From fa4949fc80a7f5f1068d161a71455b4f6d8d0236 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 18 Oct 2015 17:39:35 +0300 Subject: [PATCH] remove MethodEnter Instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit only resolved to SaveReturn anyway also Halt instruction wasn’t used, gone passes changed to start at register --- lib/virtual.rb | 1 - lib/virtual/instruction.rb | 2 -- lib/virtual/instructions/halt.rb | 12 ------------ lib/virtual/instructions/method_enter.rb | 12 ------------ lib/virtual/machine.rb | 3 +-- lib/virtual/method_source.rb | 3 ++- lib/virtual/passes/enter_implementation.rb | 15 --------------- test/compiler/fragments/test_class.rb | 2 +- test/compiler/fragments/test_foo.rb | 2 +- test/compiler/fragments/test_functions.rb | 2 +- test/compiler/fragments/test_hello.rb | 2 +- test/compiler/fragments/test_if.rb | 6 +++--- test/compiler/fragments/test_putint.rb | 2 +- test/compiler/fragments/test_recursive_fibo.rb | 2 +- test/compiler/fragments/test_while_fibo.rb | 2 +- test/compiler/statements/test_assign.rb | 12 ++++++------ test/compiler/statements/test_call.rb | 10 +++++----- test/compiler/statements/test_if.rb | 6 +++--- test/compiler/statements/test_return.rb | 10 +++++----- test/compiler/statements/test_while.rb | 6 +++--- 20 files changed, 35 insertions(+), 77 deletions(-) delete mode 100644 lib/virtual/instructions/halt.rb delete mode 100644 lib/virtual/instructions/method_enter.rb delete mode 100644 lib/virtual/passes/enter_implementation.rb diff --git a/lib/virtual.rb b/lib/virtual.rb index 980f24bc..2f35d9c5 100644 --- a/lib/virtual.rb +++ b/lib/virtual.rb @@ -11,7 +11,6 @@ require "virtual/method_source" # the passes _are_ order dependant require "virtual/passes/minimizer" require "virtual/passes/collector" -require "virtual/passes/enter_implementation" class Fixnum diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index a5e714d2..4bab9560 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -13,6 +13,4 @@ module Virtual end -require_relative "instructions/halt" require_relative "instructions/method_call" -require_relative "instructions/method_enter" diff --git a/lib/virtual/instructions/halt.rb b/lib/virtual/instructions/halt.rb deleted file mode 100644 index 2005af46..00000000 --- a/lib/virtual/instructions/halt.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Virtual - - - # the first instruction we need is to stop. Off course in a real machine this would be a syscall, - # but that is just an implementation (in a programm it would be a function). - # But in a virtual machine, not only do we need this instruction, - # it is indeed the first instruction as just this instruction is the smallest possible programm - # for the machine. - # As such it is the next instruction for any first instruction that we generate. - class Halt < Instruction - end -end diff --git a/lib/virtual/instructions/method_enter.rb b/lib/virtual/instructions/method_enter.rb deleted file mode 100644 index 5c853da4..00000000 --- a/lib/virtual/instructions/method_enter.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Virtual - - # following classes are stubs. currently in brainstorming mode, so anything may change anytime - class MethodEnter < Instruction - def initialize method - @method = method - end - - attr_reader :method - end - -end diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index cc2f8229..8584c84b 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -36,8 +36,7 @@ module Virtual class Machine - FIRST_PASS = "Virtual::EnterImplementation" - LAST_PASS = "Virtual::SetOptimisation" + FIRST_PASS = "Register::CallImplementation" def initialize @parser = Parser::Salama.new diff --git a/lib/virtual/method_source.rb b/lib/virtual/method_source.rb index b784c216..a6abb76b 100644 --- a/lib/virtual/method_source.rb +++ b/lib/virtual/method_source.rb @@ -56,7 +56,8 @@ module Virtual def init method , return_type = nil # first block we have to create with .new , as new_block assumes a current - enter = Block.new( "enter" , method ).add_code(MethodEnter.new( method )) + enter = Block.new( "enter" , method ) + enter.add_code Register.save_return(self, :message , :return_address) set_return_type( return_type ) @blocks = [enter] @current = enter diff --git a/lib/virtual/passes/enter_implementation.rb b/lib/virtual/passes/enter_implementation.rb deleted file mode 100644 index cbec12ef..00000000 --- a/lib/virtual/passes/enter_implementation.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Virtual - - class EnterImplementation - def run block - block.codes.dup.each do |code| - next unless code.is_a? Virtual::MethodEnter - new_codes = [] - # save return register to the message at instance return_address - new_codes << Register.save_return(code, :message , :return_address) - block.replace(code , new_codes ) - end - end - end - Virtual.machine.add_pass "Virtual::EnterImplementation" -end diff --git a/test/compiler/fragments/test_class.rb b/test/compiler/fragments/test_class.rb index 4501f362..a6845a5c 100644 --- a/test/compiler/fragments/test_class.rb +++ b/test/compiler/fragments/test_class.rb @@ -11,7 +11,7 @@ class Bar end end HERE - @expect = [ [Virtual::MethodEnter] ,[RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [ [SaveReturn] ,[RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/fragments/test_foo.rb b/test/compiler/fragments/test_foo.rb index 65153b4c..362e157b 100644 --- a/test/compiler/fragments/test_foo.rb +++ b/test/compiler/fragments/test_foo.rb @@ -16,7 +16,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, + @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/fragments/test_functions.rb b/test/compiler/fragments/test_functions.rb index 30f7b30e..74ecd53e 100644 --- a/test/compiler/fragments/test_functions.rb +++ b/test/compiler/fragments/test_functions.rb @@ -35,7 +35,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] , + @expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]] check diff --git a/test/compiler/fragments/test_hello.rb b/test/compiler/fragments/test_hello.rb index 4cd38c86..ab4c2fb4 100644 --- a/test/compiler/fragments/test_hello.rb +++ b/test/compiler/fragments/test_hello.rb @@ -11,7 +11,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, + @expect = [[SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set, Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/fragments/test_if.rb b/test/compiler/fragments/test_if.rb index b64a4b83..1d8f17ee 100644 --- a/test/compiler/fragments/test_if.rb +++ b/test/compiler/fragments/test_if.rb @@ -16,7 +16,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot, + @expect = [[SaveReturn,Virtual::Set,Virtual::Set,Register::GetSlot, Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] , [Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check @@ -30,7 +30,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Virtual::Set] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,Virtual::Set] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -51,7 +51,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, + @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/fragments/test_putint.rb b/test/compiler/fragments/test_putint.rb index 53421317..b3bff4d8 100644 --- a/test/compiler/fragments/test_putint.rb +++ b/test/compiler/fragments/test_putint.rb @@ -16,7 +16,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, + @expect = [ [SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set, Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/fragments/test_recursive_fibo.rb b/test/compiler/fragments/test_recursive_fibo.rb index d24680a2..b2927aa6 100644 --- a/test/compiler/fragments/test_recursive_fibo.rb +++ b/test/compiler/fragments/test_recursive_fibo.rb @@ -27,7 +27,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, + @expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/fragments/test_while_fibo.rb b/test/compiler/fragments/test_while_fibo.rb index 92240f3f..172e99e2 100644 --- a/test/compiler/fragments/test_while_fibo.rb +++ b/test/compiler/fragments/test_while_fibo.rb @@ -24,7 +24,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, + @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/statements/test_assign.rb b/test/compiler/statements/test_assign.rb index a9dd8327..94015e4f 100644 --- a/test/compiler/statements/test_assign.rb +++ b/test/compiler/statements/test_assign.rb @@ -17,7 +17,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -29,7 +29,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -41,7 +41,7 @@ int main() end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, + @expect = [[SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,GetSlot,SetSlot],[RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -55,7 +55,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -67,7 +67,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -79,7 +79,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot, + @expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot, Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/statements/test_call.rb b/test/compiler/statements/test_call.rb index 7f4832bf..37ff9cd9 100644 --- a/test/compiler/statements/test_call.rb +++ b/test/compiler/statements/test_call.rb @@ -17,7 +17,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,LoadConstant, + @expect = [[SaveReturn,GetSlot,LoadConstant, SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check @@ -37,7 +37,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,LoadConstant, + @expect = [[SaveReturn,GetSlot,LoadConstant, SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check @@ -57,7 +57,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot, + @expect = [ [SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot, GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check @@ -77,7 +77,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot, + @expect = [ [SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,Virtual::MethodCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check @@ -94,7 +94,7 @@ int main() end end HERE - @expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant, + @expect = [ [SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant, SetSlot,Virtual::MethodCall,GetSlot], [RegisterTransfer,GetSlot,FunctionReturn]] check diff --git a/test/compiler/statements/test_if.rb b/test/compiler/statements/test_if.rb index 2d4d30e5..53ebbfbb 100644 --- a/test/compiler/statements/test_if.rb +++ b/test/compiler/statements/test_if.rb @@ -16,7 +16,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, + @expect = [[SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsZeroBranch] , [LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] , [RegisterTransfer,GetSlot,FunctionReturn]] @@ -34,7 +34,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, + @expect = [[SaveReturn,LoadConstant,LoadConstant, OperatorInstruction,IsZeroBranch] , [AlwaysBranch] ,[LoadConstant] ,[] , [RegisterTransfer,GetSlot,FunctionReturn]] @@ -54,7 +54,7 @@ class Object end end HERE - @expect = [ [Virtual::MethodEnter,GetSlot,SetSlot,LoadConstant, + @expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant, SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check diff --git a/test/compiler/statements/test_return.rb b/test/compiler/statements/test_return.rb index 26fa5d29..22dcd7fa 100644 --- a/test/compiler/statements/test_return.rb +++ b/test/compiler/statements/test_return.rb @@ -13,7 +13,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -26,7 +26,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -39,7 +39,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] , + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -53,7 +53,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + @expect = [[SaveReturn,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -65,7 +65,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant, + @expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant, SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/statements/test_while.rb b/test/compiler/statements/test_while.rb index 03bcf351..49c4f41e 100644 --- a/test/compiler/statements/test_while.rb +++ b/test/compiler/statements/test_while.rb @@ -15,7 +15,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch], + @expect = [[SaveReturn],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch], [],[RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -31,7 +31,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction, + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction, IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch], [],[RegisterTransfer,GetSlot,FunctionReturn]] check @@ -50,7 +50,7 @@ class Object end end HERE - @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot], + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot], [GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot, GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot, GetSlot,AlwaysBranch] ,