2014-05-13 21:15:02 +03:00
|
|
|
module Ast
|
|
|
|
# assignment, like operators are really function calls
|
|
|
|
|
|
|
|
class CallSiteExpression < Expression
|
2014-06-04 22:03:45 +03:00
|
|
|
# attr_reader :name, :args , :receiver
|
2014-06-08 00:55:18 +03:00
|
|
|
@@counter = 0
|
2014-05-13 21:15:02 +03:00
|
|
|
def compile context , into
|
|
|
|
params = args.collect{ |a| a.compile(context, into) }
|
2014-06-03 14:49:02 +03:00
|
|
|
|
2014-06-07 23:22:32 +03:00
|
|
|
if receiver.is_a?(NameExpression) and (receiver.name == :self)
|
2014-06-03 22:16:57 +03:00
|
|
|
function = context.current_class.get_or_create_function(name)
|
2014-06-07 23:22:32 +03:00
|
|
|
value_receiver = Vm::Integer.new(Vm::Function::RECEIVER_REG)
|
2014-06-03 22:16:57 +03:00
|
|
|
else
|
2014-06-07 23:22:32 +03:00
|
|
|
value_receiver = receiver.compile(context , into)
|
2014-06-05 18:17:00 +03:00
|
|
|
function = context.current_class.get_or_create_function(name)
|
2014-06-03 14:49:02 +03:00
|
|
|
end
|
2014-06-07 23:22:32 +03:00
|
|
|
# this lot below should go, since the compile should handle all
|
|
|
|
if receiver.is_a? VariableExpression
|
|
|
|
raise "not implemented instance var:#{receiver}"
|
|
|
|
end
|
|
|
|
raise "No such method error #{3.to_s}:#{name}" if (function.nil?)
|
|
|
|
raise "No receiver error #{inspect}:#{value_receiver}:#{name}" if (value_receiver.nil?)
|
|
|
|
call = Vm::CallSite.new( name , value_receiver , params , function)
|
2014-05-22 21:55:17 +03:00
|
|
|
current_function = context.function
|
|
|
|
current_function.save_locals(context , into) if current_function
|
2014-05-13 21:15:02 +03:00
|
|
|
call.load_args into
|
|
|
|
call.do_call into
|
2014-06-08 00:55:18 +03:00
|
|
|
after = into.new_block("#{into.name}_call#{@@counter+=1}")
|
|
|
|
into.insert_at after
|
|
|
|
current_function.restore_locals(context , after) if current_function
|
2014-05-25 11:35:45 +03:00
|
|
|
puts "compile call #{function.return_type}"
|
2014-05-19 21:28:18 +03:00
|
|
|
function.return_type
|
2014-05-13 21:15:02 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-01 14:24:54 +03:00
|
|
|
class VariableExpression < CallSiteExpression
|
2014-06-04 22:03:45 +03:00
|
|
|
# super( :_get_instance_variable , [StringExpression.new(name)] )
|
2014-06-01 14:24:54 +03:00
|
|
|
end
|
|
|
|
|
2014-05-13 21:15:02 +03:00
|
|
|
end
|