change block_yield to_risc to use builder

only changes the order of two instructions
This commit is contained in:
Torsten Ruger 2018-08-16 08:58:49 +03:00
parent 1dabe0fda1
commit ce157ffa94
4 changed files with 39 additions and 35 deletions

View File

@ -15,16 +15,20 @@ module Mom
end end
def to_risc(compiler) def to_risc(compiler)
block = compiler.use_reg( :Block ) return_label = Risc.label("block_yield", "continue_#{object_id}")
return_label = Risc.label(self, "continue_#{object_id}") index = arg_index
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self) compiler.build("BlockYield") do
moves = save_return.to_risc(compiler) next_message! << message[:next_message]
moves << Risc.slot_to_reg( self , Risc.message_reg ,:arguments , block) return_address! << return_label
moves << Risc.slot_to_reg( self , block ,arg_index , block) next_message[:return_address] << return_address
moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg) block_reg! << message[:arguments]
moves << Risc::DynamicJump.new(self, block ) block_reg << block_reg[index]
moves << return_label
message << message[:next_message]
add_code Risc::DynamicJump.new("block_yield", block_reg )
add_code return_label
end
end end
end end

View File

@ -155,8 +155,8 @@ module Risc
end end
# Build with builder (see there), adding the created instructions # Build with builder (see there), adding the created instructions
def build(&block) def build(source , &block)
builder.build(&block) code_builder(source).build(&block)
end end
# return a new code builder that uses this compiler # return a new code builder that uses this compiler

View File

@ -1,7 +1,7 @@
require_relative "../helper" require_relative "../helper"
module Risc module Risc
class BloclAssignOuter < MiniTest::Test class BlockAssignOuter < MiniTest::Test
include Ticker include Ticker
def setup def setup
@ -20,7 +20,7 @@ module Risc
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 40 LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 40
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 50 RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, # 50
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, # 60 SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, # 60
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant, Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,

View File

@ -12,32 +12,32 @@ module Risc
def test_chain def test_chain
#show_main_ticks # get output of what is #show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant, check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, SlotToReg, Branch, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot, # 20
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg, LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg, # 30
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
RegToSlot, RegToSlot, RegToSlot, Branch, SlotToReg, RegToSlot, RegToSlot, RegToSlot, Branch, SlotToReg, # 40
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg, LoadConstant, RegToSlot,
SlotToReg, SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg, DynamicJump, LoadConstant, # 50
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 60
SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg, SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg,
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 70
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 80
SlotToReg, Branch, SlotToReg, FunctionReturn, SlotToReg, SlotToReg, Branch, SlotToReg, FunctionReturn, SlotToReg,
SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg, SlotToReg, Branch, RegToSlot, SlotToReg, SlotToReg, # 90
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg, # 100
Branch, SlotToReg, SlotToReg, FunctionReturn, Transfer, Branch, SlotToReg, SlotToReg, FunctionReturn, Transfer,
SlotToReg, SlotToReg, Syscall, NilClass] SlotToReg, SlotToReg, Syscall, NilClass, ]
assert_equal 15 , get_return assert_equal 15 , get_return
end end
def test_load_return def test_load_return
load_ins = main_ticks(43) load_ins = main_ticks(44)
assert_equal LoadConstant , load_ins.class assert_equal LoadConstant , load_ins.class
assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class assert_equal Parfait::ReturnAddress , @interpreter.get_register(load_ins.register).class
end end