diff --git a/lib/mom/instruction/block_yield.rb b/lib/mom/instruction/block_yield.rb index 656540ff..873ab552 100644 --- a/lib/mom/instruction/block_yield.rb +++ b/lib/mom/instruction/block_yield.rb @@ -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 diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index ca6be086..81bcc8f0 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -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 diff --git a/test/risc/interpreter/blocks/test_assign_outer.rb b/test/risc/interpreter/blocks/test_assign_outer.rb index c30cc8ed..9c6614d2 100644 --- a/test/risc/interpreter/blocks/test_assign_outer.rb +++ b/test/risc/interpreter/blocks/test_assign_outer.rb @@ -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, diff --git a/test/risc/interpreter/blocks/test_block_return.rb b/test/risc/interpreter/blocks/test_block_return.rb index c32a2a58..f0fcf80e 100644 --- a/test/risc/interpreter/blocks/test_block_return.rb +++ b/test/risc/interpreter/blocks/test_block_return.rb @@ -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