2014-05-13 20:15:02 +02:00
|
|
|
module Ast
|
|
|
|
# assignment, like operators are really function calls
|
|
|
|
|
|
|
|
class CallSiteExpression < Expression
|
2014-06-04 21:03:45 +02:00
|
|
|
# attr_reader :name, :args , :receiver
|
2014-05-31 16:58:26 +02:00
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
def compile context , into
|
|
|
|
params = args.collect{ |a| a.compile(context, into) }
|
2014-06-03 13:49:02 +02:00
|
|
|
|
2014-06-03 21:16:57 +02:00
|
|
|
if receiver.name == :self
|
|
|
|
function = context.current_class.get_or_create_function(name)
|
2014-06-07 16:59:44 +02:00
|
|
|
value = Vm::Integer.new(Vm::Function::RECEIVER_REG)
|
2014-06-03 21:16:57 +02:00
|
|
|
elsif receiver.is_a? ModuleName
|
|
|
|
c_name = receiver.name
|
|
|
|
clazz = context.object_space.get_or_create_class c_name
|
|
|
|
raise "uups #{clazz}.#{c_name}" unless clazz
|
|
|
|
#class qualifier, means call from metaclass
|
|
|
|
clazz = clazz.meta_class
|
2014-06-05 17:17:00 +02:00
|
|
|
value = clazz
|
|
|
|
puts "CLAZZ #{value}"
|
2014-06-03 21:16:57 +02:00
|
|
|
function = clazz.get_or_create_function(name)
|
|
|
|
elsif receiver.is_a? VariableExpression
|
|
|
|
raise "not implemented instance var:#{receiver}"
|
|
|
|
else
|
2014-06-05 17:17:00 +02:00
|
|
|
# should be case switch for basic tyes and dynamic dispatch for objects reference
|
|
|
|
value = context.locals[receiver.name]
|
2014-06-07 16:59:44 +02:00
|
|
|
raise "no value" unless value
|
2014-06-05 17:17:00 +02:00
|
|
|
function = context.current_class.get_or_create_function(name)
|
2014-06-03 13:49:02 +02:00
|
|
|
end
|
2014-06-03 21:16:57 +02:00
|
|
|
raise "No such method error #{clazz.to_s}:#{name}" if function == nil
|
2014-06-05 17:17:00 +02:00
|
|
|
call = Vm::CallSite.new( name , value , params , function)
|
2014-05-22 20:55:17 +02:00
|
|
|
current_function = context.function
|
|
|
|
current_function.save_locals(context , into) if current_function
|
2014-05-13 20:15:02 +02:00
|
|
|
call.load_args into
|
|
|
|
call.do_call into
|
2014-05-22 20:55:17 +02:00
|
|
|
current_function.restore_locals(context , into) if current_function
|
2014-05-25 10:35:45 +02:00
|
|
|
puts "compile call #{function.return_type}"
|
2014-05-19 20:28:18 +02:00
|
|
|
function.return_type
|
2014-05-13 20:15:02 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-01 13:24:54 +02:00
|
|
|
class VariableExpression < CallSiteExpression
|
2014-06-04 21:03:45 +02:00
|
|
|
# super( :_get_instance_variable , [StringExpression.new(name)] )
|
2014-06-01 13:24:54 +02:00
|
|
|
end
|
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
end
|