Remove MethodReturn instruction

and pass
and fix all tests
move towards removing all vm instructions
This commit is contained in:
Torsten Ruger 2015-10-18 17:32:32 +03:00
parent ae21feb6dc
commit 8bf1337043
18 changed files with 40 additions and 67 deletions

View File

@ -1,18 +0,0 @@
module Register
class ReturnImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Virtual::MethodReturn
new_codes = []
# move the current message to new_message
new_codes << RegisterTransfer.new(code, Register.message_reg , Register.new_message_reg )
# and restore the message from saved value in new_message
new_codes << Register.get_slot(code,:new_message , :caller , :message )
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
new_codes << FunctionReturn.new( code , Register.new_message_reg , Register.resolve_index(:message , :return_address) )
block.replace(code , new_codes )
end
end
end
Virtual.machine.add_pass "Register::ReturnImplementation"
end

View File

@ -1,7 +1,6 @@
require_relative "instruction" require_relative "instruction"
require_relative "register_value" require_relative "register_value"
require_relative "assembler" require_relative "assembler"
require_relative "passes/return_implementation"
require_relative "passes/call_implementation" require_relative "passes/call_implementation"
# So the memory model of the machine allows for indexed access into an "object" . # So the memory model of the machine allows for indexed access into an "object" .

View File

@ -16,4 +16,3 @@ end
require_relative "instructions/halt" require_relative "instructions/halt"
require_relative "instructions/method_call" require_relative "instructions/method_call"
require_relative "instructions/method_enter" require_relative "instructions/method_enter"
require_relative "instructions/method_return"

View File

@ -1,14 +0,0 @@
module Virtual
# also the return shuffles our objects beck before actually transferring control
class MethodReturn < Instruction
def initialize method
@method = method
end
attr_reader :method
end
end

View File

@ -60,7 +60,13 @@ module Virtual
set_return_type( return_type ) set_return_type( return_type )
@blocks = [enter] @blocks = [enter]
@current = enter @current = enter
new_block("return").add_code(MethodReturn.new(method)) ret = new_block("return")
# move the current message to new_message
ret.add_code Register::RegisterTransfer.new(self, Register.message_reg , Register.new_message_reg )
# and restore the message from saved value in new_message
ret.add_code Register.get_slot(self,:new_message , :caller , :message )
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
ret.add_code Register::FunctionReturn.new( self , Register.new_message_reg , Register.resolve_index(:message , :return_address) )
@constants = [] @constants = []
end end
attr_reader :blocks , :constants , :return_type attr_reader :blocks , :constants , :return_type

View File

@ -11,7 +11,7 @@ class Bar
end end
end end
HERE HERE
@expect = [ [Virtual::MethodEnter] ,[Virtual::MethodReturn]] @expect = [ [Virtual::MethodEnter] ,[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end

View File

@ -17,7 +17,7 @@ class Object
end end
HERE HERE
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end

View File

@ -36,7 +36,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] , @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,Virtual::MethodCall] ,
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end

View File

@ -12,7 +12,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, @expect = [[Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set,
Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn]] Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
end end

View File

@ -18,7 +18,7 @@ end
HERE HERE
@expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot, @expect = [[Virtual::MethodEnter,Virtual::Set,Virtual::Set,Register::GetSlot,
Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] , Register::GetSlot,Register::OperatorInstruction,Register::IsZeroBranch] ,
[Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[Virtual::MethodReturn] ] [Virtual::Set,Register::AlwaysBranch] ,[Virtual::Set] ,[] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
@ -30,7 +30,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,Virtual::Set] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,Virtual::Set] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -52,7 +52,7 @@ class Object
end end
HERE HERE
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
end end

View File

@ -17,7 +17,7 @@ class Object
end end
HERE HERE
@expect = [ [Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set, @expect = [ [Virtual::MethodEnter,Virtual::Set,Register::GetSlot,Virtual::Set,
Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
end end

View File

@ -28,7 +28,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, @expect = [[Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] , [Virtual::MethodReturn]] Virtual::Set,Virtual::Set,Virtual::MethodCall] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
end end

View File

@ -25,7 +25,7 @@ class Object
end end
HERE HERE
@expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set, @expect = [ [Virtual::MethodEnter,Register::GetSlot,Virtual::Set,Virtual::Set,
Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[Virtual::MethodReturn] ] Virtual::Set,Virtual::Set,Virtual::MethodCall] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end

View File

@ -17,7 +17,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -29,7 +29,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -42,7 +42,7 @@ end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
OperatorInstruction,GetSlot,SetSlot],[Virtual::MethodReturn]] OperatorInstruction,GetSlot,SetSlot],[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -55,7 +55,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -67,7 +67,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -80,7 +80,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot, @expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [Virtual::MethodReturn]] Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
end end

View File

@ -19,7 +19,7 @@ end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant, @expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -39,7 +39,7 @@ end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant, @expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] , SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -59,7 +59,7 @@ end
HERE HERE
@expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot, @expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot] ,[Virtual::MethodReturn] ] GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
@ -79,7 +79,7 @@ end
HERE HERE
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot, @expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot,
LoadConstant,SetSlot,Virtual::MethodCall, LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot] ,[Virtual::MethodReturn] ] GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
@ -96,7 +96,7 @@ end
HERE HERE
@expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant, @expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot], SetSlot,Virtual::MethodCall,GetSlot],
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end

View File

@ -19,7 +19,7 @@ HERE
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
OperatorInstruction,IsZeroBranch] , OperatorInstruction,IsZeroBranch] ,
[LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] , [LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] ,
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -37,7 +37,7 @@ HERE
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant, @expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
OperatorInstruction,IsZeroBranch] , OperatorInstruction,IsZeroBranch] ,
[AlwaysBranch] ,[LoadConstant] ,[] , [AlwaysBranch] ,[LoadConstant] ,[] ,
[Virtual::MethodReturn]] [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -56,7 +56,7 @@ end
HERE HERE
@expect = [ [Virtual::MethodEnter,GetSlot,SetSlot,LoadConstant, @expect = [ [Virtual::MethodEnter,GetSlot,SetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall, SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot] ,[Virtual::MethodReturn] ] GetSlot] ,[RegisterTransfer,GetSlot,FunctionReturn] ]
check check
end end
end end

View File

@ -13,7 +13,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -26,7 +26,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -39,7 +39,8 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] ,
[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -52,7 +53,7 @@ class Object
end end
end end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]] @expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -65,7 +66,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant, @expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot] , [Virtual::MethodReturn]] SetSlot,Virtual::MethodCall,GetSlot] , [RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
end end

View File

@ -16,7 +16,7 @@ class Object
end end
HERE HERE
@expect = [[Virtual::MethodEnter],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch], @expect = [[Virtual::MethodEnter],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch],
[],[Virtual::MethodReturn]] [],[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -33,7 +33,7 @@ end
HERE HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction, @expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch], IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
[],[Virtual::MethodReturn]] [],[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
@ -54,7 +54,7 @@ HERE
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot, [GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot, GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
GetSlot,AlwaysBranch] , GetSlot,AlwaysBranch] ,
[],[Virtual::MethodReturn]] [],[RegisterTransfer,GetSlot,FunctionReturn]]
check check
end end
end end