rubyx/lib/ast/call_site_expression.rb

45 lines
1.4 KiB
Ruby
Raw Normal View History

module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
attr_reader :name, :args , :receiver
def initialize name, args , receiver = Ast::NameExpression.new("self")
@name , @args , @receiver = name.to_sym , args , receiver
end
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
#TOOD, this needs dynamic resolution
function = context.current_class.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::CallSite.new( name , 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
2014-05-22 20:55:17 +02:00
current_function.restore_locals(context , into) if current_function
puts "compile call #{function.return_type}"
2014-05-19 20:28:18 +02:00
function.return_type
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") + "] ," + receiver.inspect + ")"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes
[:name , :args , :receiver]
end
end
class VariableExpression < CallSiteExpression
def initialize name
super( :_get_instance_variable , [StringExpression.new(name)] )
end
end
end