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)
|
2014-05-05 09:13:49 +02:00
|
|
|
@args = args
|
2014-05-03 14:13:44 +02:00
|
|
|
@function = nil
|
|
|
|
end
|
2014-05-05 09:13:49 +02:00
|
|
|
attr_reader :function , :args
|
2014-05-03 14:13:44 +02:00
|
|
|
|
2014-05-05 09:13:49 +02:00
|
|
|
def assign_function context
|
2014-05-03 14:13:44 +02:00
|
|
|
@function = context.program.get_function @name
|
|
|
|
if @function
|
2014-05-05 09:13:49 +02:00
|
|
|
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
|
2014-05-05 09:13:49 +02:00
|
|
|
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
|