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
def to_risc(compiler)
block = compiler.use_reg( :Block )
return_label = Risc.label(self, "continue_#{object_id}")
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
moves = save_return.to_risc(compiler)
moves << Risc.slot_to_reg( self , Risc.message_reg ,:arguments , block)
moves << Risc.slot_to_reg( self , block ,arg_index , block)
return_label = Risc.label("block_yield", "continue_#{object_id}")
index = arg_index
compiler.build("BlockYield") do
next_message! << message[:next_message]
return_address! << return_label
next_message[:return_address] << return_address
moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg)
moves << Risc::DynamicJump.new(self, block )
moves << return_label
block_reg! << message[:arguments]
block_reg << block_reg[index]
message << message[:next_message]
add_code Risc::DynamicJump.new("block_yield", block_reg )
add_code return_label
end
end
end

View File

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

View File

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

View File

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