2014-09-14 20:26:30 +02:00
|
|
|
Virtual::MessageSlot.class_eval do
|
|
|
|
def reg
|
|
|
|
Register::RegisterReference.new(Virtual::Message::MESSAGE_REG )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Virtual::FrameSlot.class_eval do
|
|
|
|
def reg
|
|
|
|
Register::RegisterReference.new(Virtual::Message::FRAME_REG )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Virtual::SelfSlot.class_eval do
|
|
|
|
def reg
|
|
|
|
Register::RegisterReference.new(Virtual::Message::SELF_REG )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Virtual::NewMessageSlot.class_eval do
|
|
|
|
def reg
|
|
|
|
Register::RegisterReference.new(Virtual::Message::NEW_MESSAGE_REG )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-23 20:49:09 +02:00
|
|
|
module Register
|
2014-08-23 22:37:33 +02:00
|
|
|
# This implements setting of the various slot variables the vm defines.
|
2014-10-03 10:07:18 +02:00
|
|
|
# Basic mem moves, but have to shuffle the type nibbles (TODO!)
|
2014-08-23 22:37:33 +02:00
|
|
|
|
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
|
|
|
# resolve the register and offset that we need to move to
|
|
|
|
to = code.to.reg
|
|
|
|
# need a temporay place because of indexed load/store
|
2014-09-11 20:26:22 +02:00
|
|
|
tmp = RegisterReference.new(Virtual::Message::TMP_REG)
|
2014-09-14 20:26:30 +02:00
|
|
|
# for constants we have to "move" the constants value
|
|
|
|
if( code.from.is_a? Virtual::Constant)
|
2014-10-03 10:07:18 +02:00
|
|
|
move1 = LoadConstant.new( tmp , code.from )
|
2014-09-14 20:26:30 +02:00
|
|
|
else # while otherwise we "load"
|
2014-10-03 10:07:18 +02:00
|
|
|
move1 = GetSlot.new( tmp , code.from.reg , code.from.index )
|
2014-08-23 19:25:19 +02:00
|
|
|
end
|
2014-10-03 10:07:18 +02:00
|
|
|
move2 = SetSlot.new( tmp , to , code.to.index )
|
2014-09-14 20:26:30 +02:00
|
|
|
block.replace(code , [move1,move2] )
|
2014-08-23 12:57:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-12 14:36:44 +02:00
|
|
|
Virtual::Machine.instance.add_pass "Register::SetImplementation"
|
2014-08-23 12:57:14 +02:00
|
|
|
end
|