rubyx/lib/ast/call_site_expression.rb

40 lines
1.6 KiB
Ruby
Raw Normal View History

module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
# attr_reader :name, :args , :receiver
@@counter = 0
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
2014-06-07 22:22:32 +02:00
if receiver.is_a?(NameExpression) and (receiver.name == :self)
function = context.current_class.get_or_create_function(name)
2014-06-07 22:22:32 +02:00
value_receiver = Vm::Integer.new(Vm::Function::RECEIVER_REG)
else
2014-06-07 22:22:32 +02:00
value_receiver = receiver.compile(context , into)
function = context.current_class.get_or_create_function(name)
end
2014-06-07 22:22:32 +02: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 20:55:17 +02:00
current_function = context.function
current_function.save_locals(context , into) if current_function
call.load_args into
call.do_call into
after = into.new_block("#{into.name}_call#{@@counter+=1}")
into.insert_at after
current_function.restore_locals(context , after) if current_function
puts "compile call #{function.return_type}"
2014-05-19 20:28:18 +02:00
function.return_type
end
end
class VariableExpression < CallSiteExpression
# super( :_get_instance_variable , [StringExpression.new(name)] )
end
end