2015-06-29 19:58:52 +02:00
|
|
|
|
2014-08-23 20:49:09 +02:00
|
|
|
module Register
|
2015-05-24 14:31:30 +02:00
|
|
|
# This implements setting of the various slot variables the vm defines.
|
|
|
|
|
2014-08-23 12:57:14 +02:00
|
|
|
class SetImplementation
|
|
|
|
def run block
|
|
|
|
block.codes.dup.each do |code|
|
|
|
|
next unless code.is_a? Virtual::Set
|
2014-09-14 20:26:30 +02:00
|
|
|
# need a temporay place because of indexed load/store
|
2015-10-10 18:14:27 +02:00
|
|
|
tmp = Register.tmp_reg :int
|
2014-09-14 20:26:30 +02:00
|
|
|
# for constants we have to "move" the constants value
|
2015-08-06 17:28:09 +02:00
|
|
|
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol) or code.from.is_a?(Fixnum) )
|
2015-07-27 11:13:39 +02:00
|
|
|
move1 = LoadConstant.new(code, code.from , tmp )
|
2014-09-14 20:26:30 +02:00
|
|
|
else # while otherwise we "load"
|
2015-10-06 14:26:57 +02:00
|
|
|
puts "from #{code.from}"
|
2015-07-27 11:13:39 +02:00
|
|
|
move1 = Register.get_slot(code, code.from.object_name , get_index(code.from) , tmp )
|
2014-08-23 19:25:19 +02:00
|
|
|
end
|
2015-08-06 17:28:09 +02:00
|
|
|
#puts "to #{code.to}"
|
2015-07-27 11:13:39 +02:00
|
|
|
move2 = Register.set_slot( code , tmp , code.to.object_name , get_index(code.to) )
|
2014-09-14 20:26:30 +02:00
|
|
|
block.replace(code , [move1,move2] )
|
2014-08-23 12:57:14 +02:00
|
|
|
end
|
|
|
|
end
|
2015-06-29 19:58:52 +02:00
|
|
|
|
|
|
|
def get_index from
|
|
|
|
case from
|
|
|
|
when Virtual::Self , Virtual::NewSelf
|
|
|
|
return Register.resolve_index( :message , :receiver)
|
2015-07-02 08:48:41 +02:00
|
|
|
when Virtual::MessageName , Virtual::NewMessageName
|
|
|
|
return Register.resolve_index( :message , :name)
|
|
|
|
when Virtual::Return
|
|
|
|
return Register.resolve_index( :message , :return_value)
|
2015-10-06 14:26:57 +02:00
|
|
|
when Virtual::ArgSlot , Virtual::NewArgSlot
|
2015-08-06 17:28:09 +02:00
|
|
|
#puts "from: #{from.index}"
|
2015-07-02 08:48:41 +02:00
|
|
|
return Register.resolve_index( :message , :name) + from.index
|
2015-10-06 14:26:57 +02:00
|
|
|
when Virtual::FrameSlot
|
|
|
|
#puts "from: #{from.index}"
|
|
|
|
return Register.resolve_index( :frame , :next_frame) + from.index
|
2015-06-29 19:58:52 +02:00
|
|
|
else
|
|
|
|
raise "not implemented for #{from.class}"
|
|
|
|
end
|
|
|
|
end
|
2014-08-23 12:57:14 +02:00
|
|
|
end
|
2015-06-01 07:40:17 +02:00
|
|
|
Virtual.machine.add_pass "Register::SetImplementation"
|
2014-08-23 12:57:14 +02:00
|
|
|
end
|