From d767caf4799ff36d8e7124961d9c360c01c082f5 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 18 Oct 2015 19:27:46 +0300 Subject: [PATCH] remove MethodCall and thus all virtual instructions --- lib/phisol/compiler/call_site.rb | 2 +- lib/phisol/compiler/function_definition.rb | 1 - lib/register/builtin/kernel.rb | 2 +- lib/register/instructions/function_call.rb | 6 +++++ lib/register/passes/call_implementation.rb | 24 ------------------- lib/register/register.rb | 1 - lib/virtual/instruction.rb | 16 ------------- lib/virtual/instructions/method_call.rb | 12 ---------- lib/virtual/method_source.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 | 2 +- test/compiler/fragments/test_putint.rb | 2 +- .../compiler/fragments/test_recursive_fibo.rb | 2 +- test/compiler/fragments/test_while_fibo.rb | 2 +- test/compiler/statements/test_assign.rb | 2 +- test/compiler/statements/test_call.rb | 10 ++++---- test/compiler/statements/test_if.rb | 2 +- test/compiler/statements/test_return.rb | 2 +- 20 files changed, 24 insertions(+), 72 deletions(-) delete mode 100644 lib/register/passes/call_implementation.rb delete mode 100644 lib/virtual/instruction.rb delete mode 100644 lib/virtual/instructions/method_call.rb diff --git a/lib/phisol/compiler/call_site.rb b/lib/phisol/compiler/call_site.rb index 4b0d14c0..c11d8ef7 100644 --- a/lib/phisol/compiler/call_site.rb +++ b/lib/phisol/compiler/call_site.rb @@ -38,7 +38,7 @@ module Phisol method = clazz.get_instance_method(name) #puts Virtual.machine.space.get_class_by_name(:Integer).method_names.to_a raise "Method not implemented #{me.type}.#{name}" unless method - @method.source.add_code Virtual::MethodCall.new( method ) + Register.issue_call( @method , method ) ret = use_reg( method.source.return_type ) # the effect of the method is that the NewMessage Return slot will be filled, return it # but move it into a register too diff --git a/lib/phisol/compiler/function_definition.rb b/lib/phisol/compiler/function_definition.rb index 82093dce..7360a62c 100644 --- a/lib/phisol/compiler/function_definition.rb +++ b/lib/phisol/compiler/function_definition.rb @@ -42,7 +42,6 @@ module Phisol kids.to_a.each do |ex| ret = process(ex) - raise ret.inspect if ret.is_a? Virtual::Instruction end @method = nil # function definition is a statement, does not return any value diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index 65c0c1a7..8e74fd1b 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -21,7 +21,7 @@ module Register # And store the space as the new self (so the call can move it back as self) function.source.add_code Register.set_slot( function, space_reg , :new_message , :receiver) # now we are set up to issue a call to the main - function.source.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main) + Register.issue_call( function , Virtual.machine.space.get_main) emit_syscall( function , :exit ) return function end diff --git a/lib/register/instructions/function_call.rb b/lib/register/instructions/function_call.rb index 88c8a69f..f0b2651e 100644 --- a/lib/register/instructions/function_call.rb +++ b/lib/register/instructions/function_call.rb @@ -13,6 +13,12 @@ module Register def to_s "FunctionCall: #{method.name}" end + end + def self.issue_call caller , callee + # move the current new_message to message + caller.source.add_code RegisterTransfer.new(caller, Register.new_message_reg , Register.message_reg ) + # do the register call + caller.source.add_code FunctionCall.new( caller , callee ) end end diff --git a/lib/register/passes/call_implementation.rb b/lib/register/passes/call_implementation.rb deleted file mode 100644 index cbf259ca..00000000 --- a/lib/register/passes/call_implementation.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Register - - # Defines the method call, ie - # - move the new_message to message - # - unroll self and - # - register call - - # all in all, quite the reverse of a return - - class CallImplementation - def run block - block.codes.dup.each do |code| - next unless code.is_a? Virtual::MethodCall - new_codes = [] - # move the current new_message to message - new_codes << RegisterTransfer.new(code, Register.new_message_reg , Register.message_reg ) - # do the register call - new_codes << FunctionCall.new( code , code.method ) - block.replace(code , new_codes ) - end - end - end - Virtual.machine.add_pass "Register::CallImplementation" -end diff --git a/lib/register/register.rb b/lib/register/register.rb index 12ca21eb..b6cb805f 100644 --- a/lib/register/register.rb +++ b/lib/register/register.rb @@ -1,7 +1,6 @@ require_relative "instruction" require_relative "register_value" require_relative "assembler" -require_relative "passes/call_implementation" # So the memory model of the machine allows for indexed access into an "object" . # A fixed number of objects exist (ie garbage collection is reclaming, not destroying and diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb deleted file mode 100644 index 4bab9560..00000000 --- a/lib/virtual/instruction.rb +++ /dev/null @@ -1,16 +0,0 @@ - -module Virtual - - # Instruction is an abstract for all the code of the object-machine. - # Derived classes make up the actual functionality of the machine. - # All functions on the machine are captured as instances of instructions - # - # It is actually the point of the virtual machine layer to express oo functionality in the set of - # instructions, thus defining a minimal set of instructions needed to implement oo. - - class Instruction - end - -end - -require_relative "instructions/method_call" diff --git a/lib/virtual/instructions/method_call.rb b/lib/virtual/instructions/method_call.rb deleted file mode 100644 index b78ad4a6..00000000 --- a/lib/virtual/instructions/method_call.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Virtual - - - # MethodCall involves shuffling some registers about and doing a machine call - class MethodCall < Instruction - def initialize method - @method = method - end - attr_reader :method - end - -end diff --git a/lib/virtual/method_source.rb b/lib/virtual/method_source.rb index a6abb76b..83f3a012 100644 --- a/lib/virtual/method_source.rb +++ b/lib/virtual/method_source.rb @@ -81,7 +81,7 @@ module Virtual # add an instruction after the current (insertion point) # the added instruction will become the new insertion point def add_code instruction - unless (instruction.is_a?(Instruction) or instruction.is_a?(Register::Instruction)) + unless instruction.is_a?(Register::Instruction) raise instruction.to_s end @current.add_code(instruction) #insert after current diff --git a/test/compiler/fragments/test_foo.rb b/test/compiler/fragments/test_foo.rb index 362e157b..4dc53f43 100644 --- a/test/compiler/fragments/test_foo.rb +++ b/test/compiler/fragments/test_foo.rb @@ -17,7 +17,7 @@ class Object end HERE @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, - Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] + Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/fragments/test_functions.rb b/test/compiler/fragments/test_functions.rb index 74ecd53e..b2bd96bb 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 = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] , + @expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] , [RegisterTransfer,GetSlot,FunctionReturn]] check diff --git a/test/compiler/fragments/test_hello.rb b/test/compiler/fragments/test_hello.rb index ab4c2fb4..bf501841 100644 --- a/test/compiler/fragments/test_hello.rb +++ b/test/compiler/fragments/test_hello.rb @@ -12,7 +12,7 @@ class Object end HERE @expect = [[SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set, - Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn]] + Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn]] check end end diff --git a/test/compiler/fragments/test_if.rb b/test/compiler/fragments/test_if.rb index 1d8f17ee..05471613 100644 --- a/test/compiler/fragments/test_if.rb +++ b/test/compiler/fragments/test_if.rb @@ -52,7 +52,7 @@ class Object end HERE @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, - Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] + Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end end diff --git a/test/compiler/fragments/test_putint.rb b/test/compiler/fragments/test_putint.rb index b3bff4d8..73880846 100644 --- a/test/compiler/fragments/test_putint.rb +++ b/test/compiler/fragments/test_putint.rb @@ -17,7 +17,7 @@ class Object end HERE @expect = [ [SaveReturn,Virtual::Set,Register::GetSlot,Virtual::Set, - Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] + Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end end diff --git a/test/compiler/fragments/test_recursive_fibo.rb b/test/compiler/fragments/test_recursive_fibo.rb index b2927aa6..3bd1bf9f 100644 --- a/test/compiler/fragments/test_recursive_fibo.rb +++ b/test/compiler/fragments/test_recursive_fibo.rb @@ -28,7 +28,7 @@ class Object end HERE @expect = [[SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, - Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]] + Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] , [RegisterTransfer,GetSlot,FunctionReturn]] check end end diff --git a/test/compiler/fragments/test_while_fibo.rb b/test/compiler/fragments/test_while_fibo.rb index 172e99e2..0c0c8de4 100644 --- a/test/compiler/fragments/test_while_fibo.rb +++ b/test/compiler/fragments/test_while_fibo.rb @@ -25,7 +25,7 @@ class Object end HERE @expect = [ [SaveReturn,Register::GetSlot,Virtual::Set,Virtual::Set, - Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] + Virtual::Set,Virtual::Set,RegisterTransfer,FunctionCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/statements/test_assign.rb b/test/compiler/statements/test_assign.rb index 94015e4f..3eaa1023 100644 --- a/test/compiler/statements/test_assign.rb +++ b/test/compiler/statements/test_assign.rb @@ -80,7 +80,7 @@ class Object end HERE @expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot, - Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + RegisterTransfer,FunctionCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end end diff --git a/test/compiler/statements/test_call.rb b/test/compiler/statements/test_call.rb index 37ff9cd9..33d3a090 100644 --- a/test/compiler/statements/test_call.rb +++ b/test/compiler/statements/test_call.rb @@ -18,7 +18,7 @@ class Object end HERE @expect = [[SaveReturn,GetSlot,LoadConstant, - SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , + SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -38,7 +38,7 @@ class Object end HERE @expect = [[SaveReturn,GetSlot,LoadConstant, - SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , + SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -58,7 +58,7 @@ class Object end HERE @expect = [ [SaveReturn,LoadConstant,GetSlot,SetSlot,GetSlot, - GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, + GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end @@ -78,7 +78,7 @@ class Object end HERE @expect = [ [SaveReturn,GetSlot,GetSlot,GetSlot,SetSlot, - LoadConstant,SetSlot,Virtual::MethodCall, + LoadConstant,SetSlot,RegisterTransfer,FunctionCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end @@ -95,7 +95,7 @@ end end HERE @expect = [ [SaveReturn , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant, - SetSlot,Virtual::MethodCall,GetSlot], + SetSlot,RegisterTransfer,FunctionCall,GetSlot], [RegisterTransfer,GetSlot,FunctionReturn]] check end diff --git a/test/compiler/statements/test_if.rb b/test/compiler/statements/test_if.rb index 53ebbfbb..5773890a 100644 --- a/test/compiler/statements/test_if.rb +++ b/test/compiler/statements/test_if.rb @@ -55,7 +55,7 @@ class Object end HERE @expect = [ [SaveReturn,GetSlot,SetSlot,LoadConstant, - SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, + SetSlot,LoadConstant,SetSlot,RegisterTransfer,FunctionCall, GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ] check end diff --git a/test/compiler/statements/test_return.rb b/test/compiler/statements/test_return.rb index 22dcd7fa..bebff832 100644 --- a/test/compiler/statements/test_return.rb +++ b/test/compiler/statements/test_return.rb @@ -66,7 +66,7 @@ class Object end HERE @expect = [[SaveReturn,GetSlot,GetSlot,SetSlot, LoadConstant, - SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] + SetSlot,RegisterTransfer,FunctionCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]] check end end