rubyx/lib/neumann/call_site.rb

38 lines
1.2 KiB
Ruby
Raw Normal View History

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