rubyx/lib/vm/function_call.rb

33 lines
673 B
Ruby
Raw Normal View History

2014-05-03 14:13:44 +02:00
module Vm
# name and args , return
2014-05-05 08:35:40 +02:00
class FunctionCall < Block
2014-05-03 14:13:44 +02:00
def initialize(name , args)
2014-05-05 08:35:40 +02:00
super(name)
@args = args
2014-05-03 14:13:44 +02:00
@function = nil
end
attr_reader :function , :args
2014-05-03 14:13:44 +02:00
def assign_function context
2014-05-03 14:13:44 +02:00
@function = context.program.get_function @name
if @function
raise "error #{self}" unless @function.arity != args.length
2014-05-03 14:13:44 +02:00
else
@function = context.program.get_or_create_function @name
end
end
def load_args
2014-05-05 08:35:40 +02:00
args.each_with_index do |arg , index|
2014-05-06 20:36:28 +02:00
add_code arg.load(index)
2014-05-05 08:35:40 +02:00
end
2014-05-03 14:13:44 +02:00
end
2014-05-06 20:36:28 +02:00
2014-05-05 08:35:40 +02:00
def do_call
2014-05-06 20:36:28 +02:00
add_code Machine.instance.function_call self
2014-05-03 14:13:44 +02:00
end
end
end