rubyx/lib/register/passes/set_implementation.rb

64 lines
1.8 KiB
Ruby
Raw Normal View History

2015-06-29 19:58:52 +02:00
#TODO: get rid of this. along the Register.* functions
Virtual::MessageSlot.class_eval do
def reg
2015-06-29 19:58:52 +02:00
Register.message_reg
end
end
Virtual::FrameSlot.class_eval do
def reg
2015-06-29 19:58:52 +02:00
Register.frame_reg
end
end
Virtual::SelfSlot.class_eval do
def reg
2015-06-29 19:58:52 +02:00
Register.self_reg
end
end
2015-06-29 19:58:52 +02:00
Virtual::NewMessageSlot.class_eval do
def reg
2015-06-29 19:58:52 +02:00
Register.new_message_reg
end
end
module Register
# This implements setting of the various slot variables the vm defines.
# Basic mem moves, but have to shuffle the type nibbles (TODO!)
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
# resolve the register and offset that we need to move to
to = code.to.reg
# need a temporay place because of indexed load/store
2015-06-29 19:58:52 +02:00
tmp = Register.tmp_reg
# for constants we have to "move" the constants value
2015-06-01 07:33:23 +02:00
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol))
move1 = LoadConstant.new( code.from , tmp )
else # while otherwise we "load"
2015-06-29 19:58:52 +02:00
move1 = GetSlot.new( code.from.reg , get_index(code.from) , tmp )
2014-08-23 19:25:19 +02:00
end
2015-06-29 19:58:52 +02:00
move2 = SetSlot.new( tmp , to , get_index(code.to) )
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)
when Virtual::MessageName , Virtual::NewMessageName
return Register.resolve_index( :message , :name)
when Virtual::NewArgSlot
puts "from: #{from.index}"
return Register.resolve_index( :message , :name) + 1 + from.index
else
raise "not implemented for #{from.class}"
end
end
2014-08-23 12:57:14 +02:00
end
Virtual.machine.add_pass "Register::SetImplementation"
2014-08-23 12:57:14 +02:00
end