2014-05-03 14:13:44 +02:00
|
|
|
module Vm
|
|
|
|
|
|
|
|
# name and args , return
|
|
|
|
|
2014-05-13 20:15:02 +02:00
|
|
|
class CallSite < Value
|
2014-05-03 14:13:44 +02:00
|
|
|
|
2014-06-05 17:17:00 +02:00
|
|
|
def initialize(name , value , args , function )
|
2014-05-13 15:24:19 +02:00
|
|
|
@name = name
|
2014-06-05 17:17:00 +02:00
|
|
|
@value = value
|
2014-05-05 09:13:49 +02:00
|
|
|
@args = args
|
2014-05-13 20:06:12 +02:00
|
|
|
@function = function
|
2014-06-07 16:59:44 +02:00
|
|
|
raise "oh #{name} " unless value
|
2014-05-03 14:13:44 +02:00
|
|
|
end
|
2014-06-05 17:17:00 +02:00
|
|
|
attr_reader :function , :args , :name , :value
|
|
|
|
|
2014-05-13 15:24:19 +02:00
|
|
|
def load_args into
|
2014-06-07 16:59:44 +02:00
|
|
|
if value.is_a?(IntegerConstant) or value.is_a?(ObjectConstant)
|
|
|
|
function.receiver.load into , value
|
|
|
|
else
|
2014-06-13 22:51:53 +02:00
|
|
|
raise "meta #{name} " if value.is_a? Boot::MetaClass
|
2014-06-07 16:59:44 +02:00
|
|
|
function.receiver.move( into, value ) if value.register_symbol != function.receiver.register_symbol
|
|
|
|
end
|
2014-06-24 11:25:03 +02:00
|
|
|
raise "function call '#{args.inspect}' has #{args.length} arguments, but function has #{function.args.length}" if args.length != function.args.length
|
2014-05-05 08:35:40 +02:00
|
|
|
args.each_with_index do |arg , index|
|
2014-05-18 11:30:49 +02:00
|
|
|
if arg.is_a?(IntegerConstant) or arg.is_a?(StringConstant)
|
2014-05-21 20:12:46 +02:00
|
|
|
function.args[index].load into , arg
|
2014-05-14 10:33:23 +02:00
|
|
|
else
|
2014-06-07 16:59:44 +02:00
|
|
|
function.args[index].move( into, arg ) if arg.register_symbol != function.args[index].register_symbol
|
2014-05-14 10:33:23 +02:00
|
|
|
end
|
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-13 15:24:19 +02:00
|
|
|
def do_call into
|
2014-05-21 18:43:46 +02:00
|
|
|
RegisterMachine.instance.function_call into , self
|
2014-05-03 14:13:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|