refactor on_call
This commit is contained in:
parent
23e09b7149
commit
86b0030f15
@ -3,8 +3,8 @@ module Soml
|
|||||||
|
|
||||||
def on_call statement
|
def on_call statement
|
||||||
#puts statement
|
#puts statement
|
||||||
name , arguments , receiver = *statement
|
name_s , arguments , receiver = *statement
|
||||||
name = name.to_a.first
|
name = name_s.to_a.first
|
||||||
raise "not inside method " unless @method
|
raise "not inside method " unless @method
|
||||||
reset_regs
|
reset_regs
|
||||||
#move the new message (that we need to populate to make a call) to std register
|
#move the new message (that we need to populate to make a call) to std register
|
||||||
@ -24,26 +24,8 @@ module Soml
|
|||||||
end
|
end
|
||||||
# move our receiver there
|
# move our receiver there
|
||||||
add_code Register.set_slot( statement , me , :new_message , :receiver)
|
add_code Register.set_slot( statement , me , :new_message , :receiver)
|
||||||
# load method name and set to new message (for exceptions/debug)
|
set_message_details(name_s , arguments)
|
||||||
name_tmp = use_reg(:Word)
|
set_arguments(arguments)
|
||||||
add_code Register::LoadConstant.new(statement, name , name_tmp)
|
|
||||||
add_code Register.set_slot( statement , name_tmp , :new_message , :name)
|
|
||||||
# next arguments. first length then args
|
|
||||||
len_tmp = use_reg(:Integer , arguments.to_a.length )
|
|
||||||
add_code Register::LoadConstant.new(statement, arguments.to_a.length , len_tmp)
|
|
||||||
add_code Register.set_slot( statement , len_tmp , :new_message , :indexed_length)
|
|
||||||
|
|
||||||
# reset tmp regs for each and load result into new_message
|
|
||||||
arguments.to_a.each_with_index do |arg , i|
|
|
||||||
reset_regs
|
|
||||||
# processing should return the register with the value
|
|
||||||
val = process( arg)
|
|
||||||
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
|
|
||||||
# which we load int the new_message at the argument's index (the one comes from c index)
|
|
||||||
set = Register.set_slot( arg , val , :new_message , Parfait::Message.get_indexed(i+1))
|
|
||||||
add_code set
|
|
||||||
end
|
|
||||||
|
|
||||||
#puts "clazz #{clazz.name}"
|
#puts "clazz #{clazz.name}"
|
||||||
raise "No such class #{me.type}" unless clazz
|
raise "No such class #{me.type}" unless clazz
|
||||||
method = clazz.get_instance_method(name)
|
method = clazz.get_instance_method(name)
|
||||||
@ -56,5 +38,30 @@ module Soml
|
|||||||
add_code Register.get_slot(statement, :message , :return_value , ret )
|
add_code Register.get_slot(statement, :message , :return_value , ret )
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
private
|
||||||
|
def set_message_details name_s , arguments
|
||||||
|
name = name_s.to_a.first
|
||||||
|
# load method name and set to new message (for exceptions/debug)
|
||||||
|
name_tmp = use_reg(:Word)
|
||||||
|
add_code Register::LoadConstant.new(name_s, name , name_tmp)
|
||||||
|
add_code Register.set_slot( name_s , name_tmp , :new_message , :name)
|
||||||
|
# next arguments. first length then args
|
||||||
|
len_tmp = use_reg(:Integer , arguments.to_a.length )
|
||||||
|
add_code Register::LoadConstant.new(arguments, arguments.to_a.length , len_tmp)
|
||||||
|
add_code Register.set_slot( arguments , len_tmp , :new_message , :indexed_length)
|
||||||
|
|
||||||
|
end
|
||||||
|
def set_arguments arguments
|
||||||
|
# reset tmp regs for each and load result into new_message
|
||||||
|
arguments.to_a.each_with_index do |arg , i|
|
||||||
|
reset_regs
|
||||||
|
# processing should return the register with the value
|
||||||
|
val = process( arg)
|
||||||
|
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
|
||||||
|
# which we load int the new_message at the argument's index (the one comes from c index)
|
||||||
|
set = Register.set_slot( arg , val , :new_message , Parfait::Message.get_indexed(i+1))
|
||||||
|
add_code set
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user