diff --git a/test/risc/test_callable_compiler.rb b/test/risc/test_callable_compiler.rb index 00a8af00..a9d357b9 100644 --- a/test/risc/test_callable_compiler.rb +++ b/test/risc/test_callable_compiler.rb @@ -11,8 +11,7 @@ module Risc class TestCallableCompiler < MiniTest::Test def setup Parfait.boot!({}) - label = SlotMachine::Label.new("hi","ho") - @compiler = CallableCompiler.new(FakeCallable.new , label) + @compiler = Risc.test_compiler end def test_ok assert @compiler @@ -22,7 +21,7 @@ module Risc end def test_current_label assert_equal Label , @compiler.current.class - assert_equal "ho" , @compiler.current.name + assert_equal "start_label" , @compiler.current.name end def test_slot assert @compiler.risc_instructions diff --git a/test/risc/test_register_value1.rb b/test/risc/test_register_value1.rb index 18c17e9f..f9350245 100644 --- a/test/risc/test_register_value1.rb +++ b/test/risc/test_register_value1.rb @@ -7,7 +7,7 @@ module Risc Parfait.boot!(Parfait.default_test_options) @r0 = RegisterValue.new(:r0 , :Message) @r1 = RegisterValue.new(:r1 , :Space) - @compiler = FakeCompiler.new + @compiler = Risc.test_compiler end def test_resolves_index_ok diff --git a/test/slot_machine/instruction/test_slot_load.rb b/test/slot_machine/instruction/test_slot_load.rb index 215d6880..91e2cb5e 100644 --- a/test/slot_machine/instruction/test_slot_load.rb +++ b/test/slot_machine/instruction/test_slot_load.rb @@ -14,11 +14,11 @@ module SlotMachine end def pest_fail_on_right load = SlotLoad.new( "test",[:message, :caller] , [:message ,:receiver,:type] ) - assert_raises {load.to_risc(Risc::FakeCompiler.new)} + assert_raises {load.to_risc(Risc.test_compiler)} end def pest_fail_on_left_long load = SlotLoad.new("test", [:message, :caller , :type , :type] , [:message,:type] ) - assert_raises {load.to_risc(Risc::FakeCompiler.new)} + assert_raises {load.to_risc(Risc.test_compiler)} end end end diff --git a/test/slot_machine/instruction/test_slot_load1.rb b/test/slot_machine/instruction/test_slot_load1.rb index 641cc468..f600d53a 100644 --- a/test/slot_machine/instruction/test_slot_load1.rb +++ b/test/slot_machine/instruction/test_slot_load1.rb @@ -6,34 +6,34 @@ module SlotMachine def setup Parfait.boot!(Parfait.default_test_options) load = SlotLoad.new("test", [:message, :caller] , [:message,:type] ) - @compiler = Risc::FakeCompiler.new - load.to_risc(@compiler) - @instructions = @compiler.instructions + compiler = Risc.test_compiler + load.to_risc(compiler) + @instructions = compiler.risc_instructions.next end def test_ins_class - assert_equal Risc::SlotToReg , @instructions[0].class + assert_equal Risc::SlotToReg , @instructions.class end def test_ins_next_class - assert_equal Risc::RegToSlot , @instructions[1].class + assert_equal Risc::RegToSlot , @instructions.next.class end def test_ins_arr - assert_equal :r0 , @instructions[0].array.symbol + assert_equal :r0 , @instructions.array.symbol end def test_ins_reg - assert_equal :r1 , @instructions[0].register.symbol + assert_equal :r2 , @instructions.register.symbol end def test_ins_index - assert_equal 0 , @instructions[0].index + assert_equal 0 , @instructions.index end def test_ins_next_reg - assert_equal :r1 , @instructions[1].register.symbol + assert_equal :r2 , @instructions.next.register.symbol end def test_ins_next_arr - assert_equal :r0 , @instructions[1].array.symbol + assert_equal :r0 , @instructions.next.array.symbol end def test_ins_next_index - assert_equal 6 , @instructions[1].index + assert_equal 6 , @instructions.next.index end end end diff --git a/test/slot_machine/instruction/test_slot_load2.rb b/test/slot_machine/instruction/test_slot_load2.rb index 1491ee20..1a51d4eb 100644 --- a/test/slot_machine/instruction/test_slot_load2.rb +++ b/test/slot_machine/instruction/test_slot_load2.rb @@ -5,50 +5,47 @@ module SlotMachine def setup Parfait.boot!(Parfait.default_test_options) - @compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler load = SlotLoad.new( "test",[:message, :caller, :type] , [:message, :caller , :type] ) - load.to_risc(@compiler) - @instructions = @compiler.instructions + load.to_risc(compiler) + @instructions = compiler.risc_instructions.next end def test_ins_next_classes - assert_equal Risc::SlotToReg , @instructions[0].class - assert_equal Risc::SlotToReg , @instructions[1].class - assert_equal Risc::SlotToReg , @instructions[2].class + assert_equal Risc::SlotToReg , @instructions.class + assert_equal Risc::SlotToReg , @instructions.next.class + assert_equal Risc::SlotToReg , @instructions.next(2).class end def test_ins_next_next_class - assert_equal Risc::RegToSlot , @instructions[3].class - assert_equal NilClass , @instructions[4].class + assert_equal Risc::RegToSlot , @instructions.next(3).class + assert_equal NilClass , @instructions.next(4).class end - def test_ins_next_reg - assert_equal :r1 , @instructions[1].register.symbol + assert_equal :r2 , @instructions.next.register.symbol end def test_ins_next_arr - assert_equal :r1 , @instructions[1].array.symbol + assert_equal :r2 , @instructions.next.array.symbol end def test_ins_next_index - assert_equal 0 , @instructions[1].index + assert_equal 0 , @instructions.next.index end - def test_ins_next_2_reg - assert_equal :r1 , @instructions[2].register.symbol + assert_equal :r3 , @instructions.next(2).register.symbol end def test_ins_next_2_arr - assert_equal :r0 , @instructions[2].array.symbol + assert_equal :r0 , @instructions.next(2).array.symbol end def test_ins_next_2_index - assert_equal 6 , @instructions[2].index + assert_equal 6 , @instructions.next(2).index end - def test_ins_next_3_reg - assert_equal :r1 , @instructions[3].register.symbol + assert_equal :r2 , @instructions.next(3).register.symbol end def test_ins_next_3_arr - assert_equal :r1 , @instructions[3].array.symbol + assert_equal :r3 , @instructions.next(3).array.symbol end def test_ins_next_3_index - assert_equal 0 , @instructions[3].index + assert_equal 0 , @instructions.next(3).index end end end diff --git a/test/slot_machine/instruction/test_slot_load3.rb b/test/slot_machine/instruction/test_slot_load3.rb index e497748b..18c46f1e 100644 --- a/test/slot_machine/instruction/test_slot_load3.rb +++ b/test/slot_machine/instruction/test_slot_load3.rb @@ -7,44 +7,44 @@ module SlotMachine def setup Parfait.boot!(Parfait.default_test_options) method = make_method - @compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler @cache_entry = Parfait::CacheEntry.new(method.frame_type, method) load = SlotLoad.new("test", [@cache_entry , :cached_type] , [:message, :type] ) - load.to_risc(@compiler) - @instructions = @compiler.instructions + load.to_risc(compiler) + @instructions = compiler.risc_instructions.next end def test_ins_next_class - assert_equal Risc::SlotToReg , @instructions[0].class - assert_equal Risc::LoadConstant, @instructions[1].class + assert_equal Risc::SlotToReg , @instructions.class + assert_equal Risc::LoadConstant, @instructions.next.class end def test_ins_next_class - assert_equal Risc::RegToSlot , @instructions[2].class - assert_equal NilClass , @instructions[3].class + assert_equal Risc::RegToSlot , @instructions.next(2).class + assert_equal NilClass , @instructions.next(3).class end def test_ins_load - assert_equal :r1 , @instructions[1].register.symbol - assert_equal Parfait::CacheEntry , @instructions[1].constant.class + assert_equal :r3 , @instructions.next.register.symbol + assert_equal Parfait::CacheEntry , @instructions.next.constant.class end def test_ins_next_reg - assert_equal :r1 , @instructions[0].register.symbol + assert_equal :r2 , @instructions.register.symbol end def test_ins_next_arr - assert_equal :r0 , @instructions[0].array.symbol + assert_equal :r0 , @instructions.array.symbol end def test_ins_next_index - assert_equal 0 , @instructions[0].index + assert_equal 0 , @instructions.index end def test_ins_next_2_reg - assert_equal :r1 , @instructions[2].register.symbol + assert_equal :r2 , @instructions.next(2).register.symbol end def test_ins_next_2_arr - assert_equal :r1 , @instructions[2].array.symbol + assert_equal :r3 , @instructions.next(2).array.symbol end def test_ins_next_2_index - assert_equal 1 , @instructions[2].index + assert_equal 1 , @instructions.next(2).index end end diff --git a/test/slot_machine/test_slotted_constant.rb b/test/slot_machine/test_slotted_constant.rb index 2cb71e5e..529bd0f7 100644 --- a/test/slot_machine/test_slotted_constant.rb +++ b/test/slot_machine/test_slotted_constant.rb @@ -5,10 +5,10 @@ module SlotMachine class TestSlotConstant < MiniTest::Test def setup Parfait.boot!(Parfait.default_test_options) - compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler @slotted = Slotted.for(StringConstant.new("hi") , nil) register = @slotted.to_register(compiler , InstructionMock.new) - @instruction = compiler.instructions.first + @instruction = compiler.risc_instructions.next end def test_def_class assert_equal Risc::LoadConstant , @instruction.class @@ -23,10 +23,10 @@ module SlotMachine class TestSlotConstantType < MiniTest::Test def setup Parfait.boot!(Parfait.default_test_options) - @compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler @slotted = Slotted.for(StringConstant.new("hi") , [:type]) - register = @slotted.to_register(@compiler , InstructionMock.new) - @instruction = @compiler.instructions.first + register = @slotted.to_register(compiler , InstructionMock.new) + @instruction = compiler.risc_instructions.next end def test_def_class assert_equal Risc::LoadConstant , @instruction.class @@ -41,10 +41,10 @@ module SlotMachine assert_equal "StringConstant.type" , @slotted.to_s end def test_def_register2 - assert_equal :r1 , @compiler.instructions[1].register.symbol + assert_equal :r1 , @instruction.next.register.symbol end def test_def_next_index - assert_equal 0 , @compiler.instructions[1].index + assert_equal 0 , @instruction.next.index end end end diff --git a/test/slot_machine/test_slotted_message2.rb b/test/slot_machine/test_slotted_message2.rb index 8e2ed2c6..11720893 100644 --- a/test/slot_machine/test_slotted_message2.rb +++ b/test/slot_machine/test_slotted_message2.rb @@ -4,10 +4,10 @@ module SlotMachine class TestSlottedMessage2 < MiniTest::Test def setup Parfait.boot!(Parfait.default_test_options) - compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler slotted = SlottedMessage.new([:caller]) @register = slotted.to_register(compiler , "fake source") - @instruction = compiler.instructions.first + @instruction = compiler.risc_instructions.next end def test_def_class assert_equal Risc::SlotToReg , @instruction.class @@ -19,7 +19,7 @@ module SlotMachine assert_equal :r0 , @instruction.array.symbol end def test_def_register # to next free register r1 - assert_equal :r1 , @register.symbol + assert_equal :r2 , @register.symbol end def test_def_index # at caller index 6 assert_equal 6 , @instruction.index diff --git a/test/slot_machine/test_slotted_object.rb b/test/slot_machine/test_slotted_object.rb index d0c96cd0..28c8ebb0 100644 --- a/test/slot_machine/test_slotted_object.rb +++ b/test/slot_machine/test_slotted_object.rb @@ -5,10 +5,10 @@ module SlotMachine class TestSlottedObjectType < MiniTest::Test def setup Parfait.boot!(Parfait.default_test_options) - @compiler = Risc::FakeCompiler.new + compiler = Risc.test_compiler @slotted = Slotted.for(Parfait.object_space , [:type]) - register = @slotted.to_register(@compiler , InstructionMock.new) - @instruction = @compiler.instructions.first + register = @slotted.to_register(compiler , InstructionMock.new) + @instruction = compiler.risc_instructions.next end def test_def_class assert_equal Risc::LoadConstant , @instruction.class @@ -23,10 +23,10 @@ module SlotMachine assert_equal "Space.type" , @slotted.to_s end def test_def_register2 - assert_equal :r1 , @compiler.instructions[1].register.symbol + assert_equal :r1 , @instruction.next.register.symbol end def test_def_next_index - assert_equal 0 , @compiler.instructions[1].index + assert_equal 0 , @instruction.next.index end end end diff --git a/test/support/fake_compiler.rb b/test/support/fake_compiler.rb index 14c6f8cb..10ad5632 100644 --- a/test/support/fake_compiler.rb +++ b/test/support/fake_compiler.rb @@ -7,6 +7,9 @@ module Risc :fake_name end end + def self.test_compiler(label = SlotMachine::Label.new("start","start_label")) + CallableCompiler.new( FakeCallable.new , label) + end class FakeCompiler attr_reader :instructions def initialize