From bd77db656a990059f8b13f4d2eb476173e158ed0 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 30 Jun 2015 09:39:45 +0300 Subject: [PATCH] remove class_eval on slots to map registers Use their class names (or for now called object names) these are the same that Register helper functions accept already anyway --- lib/register/passes/set_implementation.rb | 29 ++--------------------- lib/virtual/slots/frame_slot.rb | 4 ++++ lib/virtual/slots/message_slot.rb | 3 +++ lib/virtual/slots/next_message_slot.rb | 3 +++ lib/virtual/slots/self_slot.rb | 3 +++ lib/virtual/slots/slot.rb | 7 ++++++ 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/register/passes/set_implementation.rb b/lib/register/passes/set_implementation.rb index 46e0b0a5..f66c02ae 100644 --- a/lib/register/passes/set_implementation.rb +++ b/lib/register/passes/set_implementation.rb @@ -1,27 +1,4 @@ -#TODO: get rid of this. along the Register.* functions - -Virtual::MessageSlot.class_eval do - def reg - Register.message_reg - end -end -Virtual::FrameSlot.class_eval do - def reg - Register.frame_reg - end -end -Virtual::SelfSlot.class_eval do - def reg - Register.self_reg - end -end -Virtual::NewMessageSlot.class_eval do - def reg - 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!) @@ -30,17 +7,15 @@ module Register 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 tmp = Register.tmp_reg # for constants we have to "move" the constants value if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol)) move1 = LoadConstant.new( code.from , tmp ) else # while otherwise we "load" - move1 = GetSlot.new( code.from.reg , get_index(code.from) , tmp ) + move1 = Register.get_slot( code.from.object_name , get_index(code.from) , tmp ) end - move2 = SetSlot.new( tmp , to , get_index(code.to) ) + move2 = Register.set_slot( tmp , code.to.object_name , get_index(code.to) ) block.replace(code , [move1,move2] ) end end diff --git a/lib/virtual/slots/frame_slot.rb b/lib/virtual/slots/frame_slot.rb index d237ed17..6c01b524 100644 --- a/lib/virtual/slots/frame_slot.rb +++ b/lib/virtual/slots/frame_slot.rb @@ -7,6 +7,10 @@ module Virtual def initialize type = Unknown, value = nil super end + + def object_name + return :frame + end end end diff --git a/lib/virtual/slots/message_slot.rb b/lib/virtual/slots/message_slot.rb index 11a23ee0..0ff8c605 100644 --- a/lib/virtual/slots/message_slot.rb +++ b/lib/virtual/slots/message_slot.rb @@ -10,6 +10,9 @@ module Virtual def initialize type = Unknown , value = nil super(type , value ) end + def object_name + :message + end end # named classes exist for slots that often accessed diff --git a/lib/virtual/slots/next_message_slot.rb b/lib/virtual/slots/next_message_slot.rb index 295f8ea2..8d66fbc6 100644 --- a/lib/virtual/slots/next_message_slot.rb +++ b/lib/virtual/slots/next_message_slot.rb @@ -10,6 +10,9 @@ module Virtual def initialize type = Unknown, value = nil super( type , value ) end + def object_name + :new_message + end end # named classes exist for slots that often accessed diff --git a/lib/virtual/slots/self_slot.rb b/lib/virtual/slots/self_slot.rb index d0240c37..97d52324 100644 --- a/lib/virtual/slots/self_slot.rb +++ b/lib/virtual/slots/self_slot.rb @@ -17,5 +17,8 @@ module Virtual def initialize type = Unknown, value = nil super end + def object_name + :self + end end end diff --git a/lib/virtual/slots/slot.rb b/lib/virtual/slots/slot.rb index d536f80e..9f46e8fb 100644 --- a/lib/virtual/slots/slot.rb +++ b/lib/virtual/slots/slot.rb @@ -18,6 +18,13 @@ module Virtual class Slot < Object + # the name of the object of a slot is a symbol that represents what the class name describes + # ie it is one of :message , :self , :frame , :new_message + # one of the objects the machine works on. + def object_name + raise "abstract called #{self}" + end + attr_accessor :type , :value private #abstract base class