From 11997ef3547b23e06432fd92c9c2b743f1657529 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 2 Jul 2015 09:48:41 +0300 Subject: [PATCH] had to revert name method change method is not known when message is created --- lib/parfait/message.rb | 2 +- lib/register/passes/set_implementation.rb | 8 +++++--- lib/virtual/boot.rb | 2 +- lib/virtual/compiler/callsite_expression.rb | 4 ++-- lib/virtual/passes/enter_implementation.rb | 4 ---- lib/virtual/slots/message_slot.rb | 4 ++-- lib/virtual/slots/new_message_slot.rb | 6 +++--- test/virtual/test_methods.rb | 6 +++--- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/parfait/message.rb b/lib/parfait/message.rb index d6ecb316..299ab103 100644 --- a/lib/parfait/message.rb +++ b/lib/parfait/message.rb @@ -17,7 +17,7 @@ module Parfait end attr_reader :next_message , :frame , :caller # aka prev_message - attr_reader :receiver , :return_address , :return_value , :method + attr_reader :receiver , :return_address , :return_value , :name def set_caller caller @caller = caller diff --git a/lib/register/passes/set_implementation.rb b/lib/register/passes/set_implementation.rb index c2559b9f..13da1ca9 100644 --- a/lib/register/passes/set_implementation.rb +++ b/lib/register/passes/set_implementation.rb @@ -24,11 +24,13 @@ module Register case from when Virtual::Self , Virtual::NewSelf return Register.resolve_index( :message , :receiver) - when Virtual::MessageMethod , Virtual::NewMessageMethod - return Register.resolve_index( :message , :method) + when Virtual::MessageName , Virtual::NewMessageName + return Register.resolve_index( :message , :name) + when Virtual::Return + return Register.resolve_index( :message , :return_value) when Virtual::NewArgSlot puts "from: #{from.index}" - return Register.resolve_index( :message , :method) + from.index + return Register.resolve_index( :message , :name) + from.index else raise "not implemented for #{from.class}" end diff --git a/lib/virtual/boot.rb b/lib/virtual/boot.rb index c26ac868..4a04a894 100644 --- a/lib/virtual/boot.rb +++ b/lib/virtual/boot.rb @@ -27,7 +27,7 @@ module Virtual :List => [] , # Assumtion is that name is the last of message :Message => [:next_message , :receiver , :frame , :return_address , :return_value, - :caller , :method ], + :caller , :name ], :MetaClass => [], :BinaryCode => [], :Space => [:classes , :first_message , :syscall_message], diff --git a/lib/virtual/compiler/callsite_expression.rb b/lib/virtual/compiler/callsite_expression.rb index be70ca88..442076b2 100644 --- a/lib/virtual/compiler/callsite_expression.rb +++ b/lib/virtual/compiler/callsite_expression.rb @@ -8,14 +8,14 @@ module Virtual me = Compiler.compile( expession.receiver , method ) method.info.add_code NewMessage.new method.info.add_code Set.new( me , NewSelf.new(me.type)) - method.info.add_code Set.new( expession.name.to_sym , NewMessageMethod.new()) + method.info.add_code Set.new( expession.name.to_sym , NewMessageName.new()) 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 # + 1 as this is a ruby 0-start , but 0 is the last message ivar. - # so the next free is +1 + # so the next free is +1 to = NewArgSlot.new(i + 1 ,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( val , to ) diff --git a/lib/virtual/passes/enter_implementation.rb b/lib/virtual/passes/enter_implementation.rb index ed0594be..d5529675 100644 --- a/lib/virtual/passes/enter_implementation.rb +++ b/lib/virtual/passes/enter_implementation.rb @@ -7,10 +7,6 @@ module Virtual new_codes = [] # save return register to the message at instance return_address new_codes << Register.save_return(:message , :return_address) - # set the method instance on message, have to load first - tmp = Register.tmp_reg - new_codes << Register::LoadConstant.new( code.method , tmp ) - new_codes << Register.set_slot( tmp , :message , :method) # and create a new frame if needed unless code.method.locals.empty? and code.method.tmps.empty? new_codes << Virtual::NewFrame.new diff --git a/lib/virtual/slots/message_slot.rb b/lib/virtual/slots/message_slot.rb index c72abf85..0ff8c605 100644 --- a/lib/virtual/slots/message_slot.rb +++ b/lib/virtual/slots/message_slot.rb @@ -31,8 +31,8 @@ module Virtual end end - # MessageMethod of the current message - class MessageMethod < MessageSlot + # MessageName of the current message + class MessageName < MessageSlot def initialize type = Unknown, value = nil super( type , value ) end diff --git a/lib/virtual/slots/new_message_slot.rb b/lib/virtual/slots/new_message_slot.rb index 834c73fc..8d66fbc6 100644 --- a/lib/virtual/slots/new_message_slot.rb +++ b/lib/virtual/slots/new_message_slot.rb @@ -31,14 +31,14 @@ module Virtual end end - # NewMessageMethod of the next message - class NewMessageMethod < NewMessageSlot + # NewMessageName of the next message + class NewMessageName < NewMessageSlot def initialize type = Unknown, value = nil super( type , value ) end end - # NewMessageMethod of the next message + # NewMessageName of the next message class NewArgSlot < NewMessageSlot def initialize index , type = Unknown, value = nil @index = index diff --git a/test/virtual/test_methods.rb b/test/virtual/test_methods.rb index 44971ddb..6e3a461d 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::NewMessageMethod(: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::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::NewMessageName(: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)" 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::NewMessageMethod(: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::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &18 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *17)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewMessageName(: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)" 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::NewMessageMethod(: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::NewSelf(:index => 3, :type => &9 Virtual::Integer)*^* :from &16 Virtual::Return(:index => 5, :type => &9 Virtual::Integer, :value => *15)*^* -Virtual::Set(:from => '+')*^* :to Virtual::NewMessageName(: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)" check end