From 6867175bd196c94bb70e4611723ac9f0417f59a1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 21 Jun 2015 00:21:42 +0300 Subject: [PATCH] slot docs and rename --- lib/register/passes/set_implementation.rb | 2 +- lib/virtual/compiler/callsite_expression.rb | 6 ++-- lib/virtual/slots/message_slot.rb | 8 +++-- lib/virtual/slots/new_message_slot.rb | 25 -------------- lib/virtual/slots/next_message_slot.rb | 37 +++++++++++++++++++++ lib/virtual/slots/self_slot.rb | 2 +- lib/virtual/slots/slot.rb | 2 +- test/virtual/test_hello.rb | 8 ++--- test/virtual/test_methods.rb | 6 ++-- 9 files changed, 56 insertions(+), 40 deletions(-) delete mode 100644 lib/virtual/slots/new_message_slot.rb create mode 100644 lib/virtual/slots/next_message_slot.rb diff --git a/lib/register/passes/set_implementation.rb b/lib/register/passes/set_implementation.rb index af95f10c..5afb1d90 100644 --- a/lib/register/passes/set_implementation.rb +++ b/lib/register/passes/set_implementation.rb @@ -13,7 +13,7 @@ Virtual::SelfSlot.class_eval do Register::RegisterReference.self_reg end end -Virtual::NewMessageSlot.class_eval do +Virtual::NextMessageSlot.class_eval do def reg Register::RegisterReference.new_message_reg end diff --git a/lib/virtual/compiler/callsite_expression.rb b/lib/virtual/compiler/callsite_expression.rb index 023e0df0..c8720f5d 100644 --- a/lib/virtual/compiler/callsite_expression.rb +++ b/lib/virtual/compiler/callsite_expression.rb @@ -7,14 +7,14 @@ module Virtual def self.compile_callsite expession , method me = Compiler.compile( expession.receiver , method ) method.info.add_code NewMessage.new - method.info.add_code Set.new(NewSelf.new(me.type), me) - method.info.add_code Set.new(NewName.new(), expession.name.to_sym) + method.info.add_code Set.new(NextSelf.new(me.type), me) + method.info.add_code Set.new(NextMessageName.new(), expession.name.to_sym) compiled_args = [] expession.args.each_with_index do |arg , i| #compile in the running method, ie before passing control val = Compiler.compile( arg , method) # move the compiled value to it's slot in the new message - to = NewMessageSlot.new(i ,val.type , val) + to = NextMessageSlot.new(i ,val.type , val) # (doing this immediately, not after the loop, so if it's a return it won't get overwritten) method.info.add_code Set.new(to , val ) compiled_args << to diff --git a/lib/virtual/slots/message_slot.rb b/lib/virtual/slots/message_slot.rb index beba66f8..647bb26e 100644 --- a/lib/virtual/slots/message_slot.rb +++ b/lib/virtual/slots/message_slot.rb @@ -21,20 +21,24 @@ module Virtual end end + # named classes exist for slots that often accessed + + # Return is the MessageSlot(MESSAGE_RETURN_VALUE) class Return < MessageSlot def initialize type = Unknown, value = nil super( MESSAGE_RETURN_VALUE , type , value ) end end + # Self is the MessageSlot(MESSAGE_SELF) class Self < MessageSlot def initialize type = Unknown, value = nil super( MESSAGE_SELF , type , value ) end end - # Name of the current message - class Name < MessageSlot + # MessageName of the current message + class MessageName < MessageSlot def initialize type = Unknown, value = nil super( MESSAGE_NAME , type , value ) end diff --git a/lib/virtual/slots/new_message_slot.rb b/lib/virtual/slots/new_message_slot.rb deleted file mode 100644 index 55e79e6a..00000000 --- a/lib/virtual/slots/new_message_slot.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Virtual - class NewMessageSlot < Slot - def initialize index , type = Unknown, value = nil - super(index , type , value ) - end - end - - class NewReturn < NewMessageSlot - def initialize type = Unknown, value = nil - super( MESSAGE_RETURN_VALUE, type , value ) - end - end - - class NewSelf < NewMessageSlot - def initialize type = Unknown, value = nil - super( MESSAGE_SELF , type , value ) - end - end - - class NewName < NewMessageSlot - def initialize type = Unknown, value = nil - super( MESSAGE_NAME, type , value ) - end - end -end diff --git a/lib/virtual/slots/next_message_slot.rb b/lib/virtual/slots/next_message_slot.rb new file mode 100644 index 00000000..07c30f48 --- /dev/null +++ b/lib/virtual/slots/next_message_slot.rb @@ -0,0 +1,37 @@ +module Virtual + + # The next Message is one of four objects the virtual machine knows + # + # Slots represent instance variables of objects, so NextMessageSlots + # represent instance variables of NextMessage objects. + # The Message has a layout as per the constant above + + class NextMessageSlot < Slot + def initialize index , type = Unknown, value = nil + super(index , type , value ) + end + end + + # named classes exist for slots that often accessed + + # NextReturn is the NextMessageSlot(MESSAGE_RETURN_VALUE) + class NextReturn < NextMessageSlot + def initialize type = Unknown, value = nil + super( MESSAGE_RETURN_VALUE, type , value ) + end + end + + # NextSelf is the NextMessageSlot(MESSAGE_SELF) + class NextSelf < NextMessageSlot + def initialize type = Unknown, value = nil + super( MESSAGE_SELF , type , value ) + end + end + + # NextMessageName of the next message + class NextMessageName < NextMessageSlot + def initialize type = Unknown, value = nil + super( MESSAGE_NAME, type , value ) + end + end +end diff --git a/lib/virtual/slots/self_slot.rb b/lib/virtual/slots/self_slot.rb index ce2cf0d8..d0b38987 100644 --- a/lib/virtual/slots/self_slot.rb +++ b/lib/virtual/slots/self_slot.rb @@ -5,7 +5,7 @@ module Virtual # want to send a message it puts the new self into the next_message. # # The slot in the Message is represented by instances of class Self - # (and slots in the next_message by instances of NewSelf) + # (and slots in the next_message by instances of NextSelf) # # Additionally the current Self is represented as it's own top-level object. # If self is an Object one can refer to it's instance variables as Slots in SelfSlot diff --git a/lib/virtual/slots/slot.rb b/lib/virtual/slots/slot.rb index f0d1c720..3f20514c 100644 --- a/lib/virtual/slots/slot.rb +++ b/lib/virtual/slots/slot.rb @@ -8,7 +8,7 @@ module Virtual # - the message that has been received: MessageSlot # - the frame of the method that is executing (local variables): FrameSlot # - self as an object: SelfSlot - # - a message that will be sent, NewMessageSlot + # - a message that will be sent, NextMessageSlot # additionally frame, self and return are slots in Message and NewMessage diff --git a/test/virtual/test_hello.rb b/test/virtual/test_hello.rb index a04cb42a..6deccc63 100644 --- a/test/virtual/test_hello.rb +++ b/test/virtual/test_hello.rb @@ -6,11 +6,11 @@ class HelloTest < MiniTest::Test def check machine = Virtual::Machine.boot expressions = machine.compile_main @string_input - machine.run_before "Register::CallImplementation" + output_at = Virtual::Machine::FIRST_PASS + #{}"Register::CallImplementation" + machine.run_before output_at puts Sof.write(machine.space) - machine.run_after "Register::CallImplementation" - - + machine.run_after output_at writer = Elf::ObjectWriter.new(machine) writer.save "hello.o" end diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index c7798fef..e900e032 100644 --- a/test/virtual/test_methods.rb +++ b/test/virtual/test_methods.rb @@ -20,7 +20,7 @@ def foo() end foo() HERE - @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => *6)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :from &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* -Virtual::Set(:from => 'puts')*^* :to Virtual::NewName(:index => 4, :type => *6)*^* -Virtual::Set(:from => 'Hello')*^* :to &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::Set()*^* :to &18 Virtual::NewMessageSlot(:index => 0, :type => &5 Virtual::Reference, :value => *16)*^* :from &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::MessageSend(:name => :puts)*^* :me &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :args [*18]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => *6)*^*-Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)" + @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => *6)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :from &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* -Virtual::Set(:from => 'puts')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set(:from => 'Hello')*^* :to &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::Set()*^* :to &18 Virtual::NextMessageSlot(:index => 0, :type => &5 Virtual::Reference, :value => *16)*^* :from &16 Virtual::Return(:index => 5, :type => &5 Virtual::Reference, :value => 'Hello')*^* -Virtual::MessageSend(:name => :puts)*^* :me &17 Virtual::Self(:index => 3)*^* :type &15 Virtual::Reference(:of_class => *2)*^* :args [*18]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => *6)*^*-Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)" check end @@ -41,7 +41,7 @@ def foo(x) 2 + 5 end HERE - @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names [:x]*^* :locals ['abba']*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *6)*^* :from Virtual::FrameSlot(:index => 1, :type => &9 Virtual::Integer, :value => *16)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* :from &19 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &21 Virtual::NewMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *20)*^* :from &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* -Virtual::MessageSend(:name => :+)*^* :me &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :args [*21]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)" + @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names [:x]*^* :locals ['abba']*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *6)*^* :from Virtual::FrameSlot(:index => 1, :type => &9 Virtual::Integer, :value => *16)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* :from &19 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &21 Virtual::NextMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *20)*^* :from &20 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *19)*^* -Virtual::MessageSend(:name => :+)*^* :me &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :args [*21]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)" check end @@ -51,7 +51,7 @@ def foo() 2 + 5 end HERE - @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &19 Virtual::NewMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *18)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::MessageSend(:name => :+)*^* :me &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :args [*19]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)" + @output = "-&7 Parfait::Method(:name => 'foo', :code => '')*^* :memory -0*^* -&1 ['name', 'code', 'arg_names', 'locals', 'tmps']*^* :arg_names []*^* :locals []*^* :tmps []*^* :info Virtual::CompiledMethodInfo()*^* :return_type Virtual::Return(:index => 5, :type => &6 Virtual::Unknown)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter()*^* -Virtual::Set()*^* :to &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :from &15 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage()*^* -Virtual::Set()*^* :to Virtual::NextSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NextMessageName(:index => 4, :type => *6)*^* -Virtual::Set()*^* :to &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* :from &17 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &19 Virtual::NextMessageSlot(:index => 0, :type => &9 Virtual::Integer, :value => *18)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::MessageSend(:name => :+)*^* :me &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* :args [*19]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes [Virtual::MethodReturn()]*^* :receiver Virtual::Self(:index => 3, :type => &6 Virtual::Unknown)" check end