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 "register_value"
require_relative "assembler"
require_relative "passes/return_implementation"
require_relative "passes/call_implementation"
# 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/method_call"
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 )
@blocks = [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 = []
end
attr_reader :blocks , :constants , :return_type