rubyx/lib/ast/call_site_expression.rb
2014-05-22 21:55:17 +03:00

34 lines
1.0 KiB
Ruby

module Ast
# assignment, like operators are really function calls
class CallSiteExpression < Expression
attr_reader :name, :args
def initialize name, args
@name , @args = name.to_sym , args
end
def compile context , into
params = args.collect{ |a| a.compile(context, into) }
function = context.program.get_or_create_function(name)
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
call = Vm::CallSite.new( name , params , function)
current_function = context.function
current_function.save_locals(context , into) if current_function
call.load_args into
call.do_call into
current_function.restore_locals(context , into) if current_function
function.return_type
end
def inspect
self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") +"] )"
end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes
[:name , :args]
end
end
end