rubyx/lib/vm/function_call.rb
2014-05-05 09:35:40 +03:00

40 lines
806 B
Ruby

module Vm
# name and args , return
class FunctionCall < Block
def initialize(name , args)
super(name)
@name = name
@values = args
@function = nil
end
attr_reader :function
def args
values
end
def compile context
@function = context.program.get_function @name
if @function
raise "error #{self}" unless @function.arity != @values.length
else
@function = context.program.get_or_create_function @name
end
args.each_with_index do |arg |
arg.compile context
end
args.each_with_index do |arg , index|
arg.load index
end
#puts "funcall #{self.inspect}"
self.do_call
end
def do_call
Machine.instance.function_call self
end
end
end