From 3d342f7d88e069547c9ab324c208c123ee2760b1 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 10 Oct 2015 12:04:34 +0300 Subject: [PATCH] remove new_message instruction --- lib/phisol/compiler/call_site.rb | 4 ++- lib/register/passes/message_implementation.rb | 32 ------------------- lib/register/register.rb | 1 - lib/virtual/instruction.rb | 1 - lib/virtual/instructions/new_message.rb | 5 --- test/fragments/test_foo.rb | 2 +- test/fragments/test_functions.rb | 2 +- test/fragments/test_hello.rb | 2 +- test/fragments/test_if.rb | 2 +- test/fragments/test_methods.rb | 2 +- test/fragments/test_putint.rb | 2 +- test/fragments/test_recursive_fibo.rb | 2 +- test/fragments/test_while_fibo.rb | 2 +- 13 files changed, 11 insertions(+), 48 deletions(-) delete mode 100644 lib/register/passes/message_implementation.rb delete mode 100644 lib/virtual/instructions/new_message.rb diff --git a/lib/phisol/compiler/call_site.rb b/lib/phisol/compiler/call_site.rb index 64e3b5af..d1056770 100644 --- a/lib/phisol/compiler/call_site.rb +++ b/lib/phisol/compiler/call_site.rb @@ -16,7 +16,9 @@ module Phisol end ## need two step process, compile and save to frame # then move from frame to new message - @method.source.add_code Virtual::NewMessage.new + # load the new_message from message by index, simple get_slot + new_message = Register.get_slot(@method, :message , :next_message , Register.resolve_to_register(:new_message)) + @method.source.add_code new_message @method.source.add_code Virtual::Set.new( me , Virtual::NewSelf.new(me.type)) @method.source.add_code Virtual::Set.new( name.to_sym , Virtual::NewMessageName.new(:int)) compiled_args = [] diff --git a/lib/register/passes/message_implementation.rb b/lib/register/passes/message_implementation.rb deleted file mode 100644 index f5e5255d..00000000 --- a/lib/register/passes/message_implementation.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Register - # This implements the creation of a new message object - # - # It does so by loading the next message into the new_message register. - # - # Messages are created at compile time and form a linked list which actually never changes. - # We just grab the next item of the list. - - # Just as a reminder: a message object is used for a send and holds return address/message - # and arguments + self - # while frames are used by a method and hold local and temporary variables - - # This was at first a little surprising, but it actually similar in c. When a c function pops to - # stack, it doesn't create a new stack. Just increments some index. The storage/stack is reused, - # stays constant. (until such time it runs out, which we haven't covered yet) - # - # Even stranger at first was the notion that the caller does not have to be set either. - # That is contstant (a compile time property) too. It's a bit like when calling someone, - # - - class MessageImplementation - def run block - block.codes.dup.each do |code| - next unless code.is_a?(Virtual::NewMessage) - # load the new_message from message by index, simple get_slot - new_codes = [ Register.get_slot(code, :message , :next_message , Register.resolve_to_register(:new_message))] - block.replace(code , new_codes ) - end - end - end - Virtual.machine.add_pass "Register::MessageImplementation" -end diff --git a/lib/register/register.rb b/lib/register/register.rb index 21dd6d5f..aaff27e5 100644 --- a/lib/register/register.rb +++ b/lib/register/register.rb @@ -2,7 +2,6 @@ require_relative "instruction" require_relative "register_reference" require_relative "assembler" require_relative "passes/frame_implementation" -require_relative "passes/message_implementation" require_relative "passes/set_implementation" require_relative "passes/return_implementation" require_relative "passes/call_implementation" diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index e311c7d1..475ac5fe 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -18,5 +18,4 @@ require_relative "instructions/method_call" require_relative "instructions/method_enter" require_relative "instructions/method_return" require_relative "instructions/new_frame" -require_relative "instructions/new_message" require_relative "instructions/set" diff --git a/lib/virtual/instructions/new_message.rb b/lib/virtual/instructions/new_message.rb deleted file mode 100644 index 14a671a3..00000000 --- a/lib/virtual/instructions/new_message.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Virtual - - class NewMessage < Instruction - end -end diff --git a/test/fragments/test_foo.rb b/test/fragments/test_foo.rb index de851ddb..63bc66ad 100644 --- a/test/fragments/test_foo.rb +++ b/test/fragments/test_foo.rb @@ -16,7 +16,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end diff --git a/test/fragments/test_functions.rb b/test/fragments/test_functions.rb index 01f22c0d..49fc11b5 100644 --- a/test/fragments/test_functions.rb +++ b/test/fragments/test_functions.rb @@ -35,7 +35,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set,Virtual::MethodCall] , + @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] , [Virtual::MethodReturn]] check diff --git a/test/fragments/test_hello.rb b/test/fragments/test_hello.rb index f3d0cdd2..750ef8d5 100644 --- a/test/fragments/test_hello.rb +++ b/test/fragments/test_hello.rb @@ -11,7 +11,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::NewMessage,Virtual::Set, + @expect = [[Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn]] check end diff --git a/test/fragments/test_if.rb b/test/fragments/test_if.rb index 2d9910c7..6a69d755 100644 --- a/test/fragments/test_if.rb +++ b/test/fragments/test_if.rb @@ -51,7 +51,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end diff --git a/test/fragments/test_methods.rb b/test/fragments/test_methods.rb index 9aa69ddb..ed35d3dd 100644 --- a/test/fragments/test_methods.rb +++ b/test/fragments/test_methods.rb @@ -41,7 +41,7 @@ class Object end end HERE - @expect = [[MethodEnter , NewMessage, Set, Set , Set, Set, MethodCall],[MethodReturn]] + @expect = [[MethodEnter , Register::GetSlot, Set, Set , Set, Set, MethodCall],[MethodReturn]] check end diff --git a/test/fragments/test_putint.rb b/test/fragments/test_putint.rb index 508a44a4..53dd6c69 100644 --- a/test/fragments/test_putint.rb +++ b/test/fragments/test_putint.rb @@ -11,7 +11,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Virtual::Set,Virtual::NewMessage,Virtual::Set, + @expect = [ [Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end diff --git a/test/fragments/test_recursive_fibo.rb b/test/fragments/test_recursive_fibo.rb index a478374e..7dadbd6c 100644 --- a/test/fragments/test_recursive_fibo.rb +++ b/test/fragments/test_recursive_fibo.rb @@ -27,7 +27,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] , [Virtual::MethodReturn]] check end diff --git a/test/fragments/test_while_fibo.rb b/test/fragments/test_while_fibo.rb index 6dd8e846..dd5ba2fc 100644 --- a/test/fragments/test_while_fibo.rb +++ b/test/fragments/test_while_fibo.rb @@ -24,7 +24,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Virtual::NewMessage,Virtual::Set,Virtual::Set, + @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] check end