diff --git a/test/mom/instruction/test_slot_definition.rb b/test/mom/instruction/test_slot_definition.rb index d822ce87..4a61e557 100644 --- a/test/mom/instruction/test_slot_definition.rb +++ b/test/mom/instruction/test_slot_definition.rb @@ -17,38 +17,4 @@ module Mom assert_raises {slot(nil)} end end - class TestSlotDefinitionConstant < MiniTest::Test - def setup - Risc.machine.boot - @compiler = CompilerMock.new - @definition = SlotDefinition.new(StringConstant.new("hi") , []) - @instruction = @definition.to_register(@compiler , InstructionMock.new) - end - def test_def_class - assert_equal Risc::LoadConstant , @instruction.class - end - def test_def_register - assert_equal :r1 , @instruction.register.symbol - end - def test_def_const - assert_equal "hi" , @instruction.constant.to_string - end - end - class TestSlotDefinitionKnown1 < MiniTest::Test - def setup - Risc.machine.boot - @compiler = CompilerMock.new - @definition = SlotDefinition.new(:message , :caller) - @instruction = @definition.to_register(@compiler , InstructionMock.new) - end - def test_def_class - assert_equal Risc::SlotToReg , @instruction.class - end - def test_def_array - assert_equal :r0 , @instruction.array.symbol - end - def test_def_register - assert_equal :r1 , @instruction.register.symbol - end - end end diff --git a/test/mom/instruction/test_slot_definition1.rb b/test/mom/instruction/test_slot_definition1.rb new file mode 100644 index 00000000..3f92e112 --- /dev/null +++ b/test/mom/instruction/test_slot_definition1.rb @@ -0,0 +1,22 @@ +require_relative "helper" + +module Mom + + class TestSlotDefinitionConstant < MiniTest::Test + def setup + Risc.machine.boot + @compiler = CompilerMock.new + @definition = SlotDefinition.new(StringConstant.new("hi") , []) + @instruction = @definition.to_register(@compiler , InstructionMock.new) + end + def test_def_class + assert_equal Risc::LoadConstant , @instruction.class + end + def test_def_register + assert_equal :r1 , @instruction.register.symbol + end + def test_def_const + assert_equal "hi" , @instruction.constant.to_string + end + end +end diff --git a/test/mom/instruction/test_slot_definition2.rb b/test/mom/instruction/test_slot_definition2.rb new file mode 100644 index 00000000..15ab8973 --- /dev/null +++ b/test/mom/instruction/test_slot_definition2.rb @@ -0,0 +1,27 @@ +require_relative "helper" + +module Mom + class TestSlotDefinitionKnown1 < MiniTest::Test + def setup + Risc.machine.boot + @compiler = CompilerMock.new + @definition = SlotDefinition.new(:message , :caller) + @instruction = @definition.to_register(@compiler , InstructionMock.new) + end + def test_def_class + assert_equal Risc::SlotToReg , @instruction.class + end + def test_def_next_class + assert_equal NilClass , @instruction.next.class + end + def test_def_array #from message r0 + assert_equal :r0 , @instruction.array.symbol + end + def test_def_register # to next free register r1 + assert_equal :r1 , @instruction.register.symbol + end + def test_def_index # at caller index 6 + assert_equal 6 , @instruction.index + end + end +end diff --git a/test/mom/instruction/test_slot_definition3.rb b/test/mom/instruction/test_slot_definition3.rb new file mode 100644 index 00000000..eb189dae --- /dev/null +++ b/test/mom/instruction/test_slot_definition3.rb @@ -0,0 +1,27 @@ +require_relative "helper" + +module Mom + class TestSlotDefinitionKnown2 < MiniTest::Test + def setup + Risc.machine.boot + @compiler = CompilerMock.new + @definition = SlotDefinition.new(:message , [:caller , :type]) + @instruction = @definition.to_register(@compiler , InstructionMock.new) + end + def test_def_next_class + assert_equal Risc::SlotToReg , @instruction.next.class + end + def test_def_next_next_class + assert_equal NilClass , @instruction.next.next.class + end + def test_def_next_index + assert_equal 0 , @instruction.next.index + end + def test_def_next_register + assert_equal :r1 , @instruction.next.register.symbol + end + def test_def_next_array + assert_equal :r1 , @instruction.next.array.symbol + end + end +end diff --git a/test/mom/instruction/test_slot_load.rb b/test/mom/instruction/test_slot_load.rb index 349f155b..fd384fa6 100644 --- a/test/mom/instruction/test_slot_load.rb +++ b/test/mom/instruction/test_slot_load.rb @@ -18,38 +18,4 @@ module Mom assert_raises {@load.to_risc(CompilerMock.new)} end end - class TestSlotLoadFunction < MiniTest::Test - - def setup - Risc.machine.boot - @load = SlotLoad.new( [:message, :caller] , [:message,:type] ) - @compiler = CompilerMock.new - @instruction = @load.to_risc(@compiler) - end - - def test_ins_class - assert_equal Risc::SlotToReg , @instruction.class - end - def test_ins_next_class - assert_equal Risc::RegToSlot , @instruction.next.class - end - def test_ins_arr - assert_equal :r0 , @instruction.array.symbol - end - def test_ins_reg - assert_equal :r1 , @instruction.register.symbol - end - def test_ins_index - assert_equal 0 , @instruction.index - end - def test_ins_next_reg - assert_equal :r1 , @instruction.next.register.symbol - end - def test_ins_next_arr - assert_equal :r0 , @instruction.next.array.symbol - end - def test_ins_next_index - assert_equal 6 , @instruction.next.index - end - end end diff --git a/test/mom/instruction/test_slot_load1.rb b/test/mom/instruction/test_slot_load1.rb new file mode 100644 index 00000000..e2ca0ba6 --- /dev/null +++ b/test/mom/instruction/test_slot_load1.rb @@ -0,0 +1,38 @@ +require_relative "helper" + +module Mom + class TestSlotLoad1 < MiniTest::Test + + def setup + Risc.machine.boot + @load = SlotLoad.new( [:message, :caller] , [:message,:type] ) + @compiler = CompilerMock.new + @instruction = @load.to_risc(@compiler) + end + + def test_ins_class + assert_equal Risc::SlotToReg , @instruction.class + end + def test_ins_next_class + assert_equal Risc::RegToSlot , @instruction.next.class + end + def test_ins_arr + assert_equal :r0 , @instruction.array.symbol + end + def test_ins_reg + assert_equal :r1 , @instruction.register.symbol + end + def test_ins_index + assert_equal 0 , @instruction.index + end + def test_ins_next_reg + assert_equal :r1 , @instruction.next.register.symbol + end + def test_ins_next_arr + assert_equal :r0 , @instruction.next.array.symbol + end + def test_ins_next_index + assert_equal 6 , @instruction.next.index + end + end +end diff --git a/test/mom/instruction/test_slot_load2.rb b/test/mom/instruction/test_slot_load2.rb new file mode 100644 index 00000000..784bdb6b --- /dev/null +++ b/test/mom/instruction/test_slot_load2.rb @@ -0,0 +1,40 @@ +require_relative "helper" + +module Mom + class TestSlotLoad2 < MiniTest::Test + + def setup + Risc.machine.boot + @load = SlotLoad.new( [:message, :caller] , [:message, :caller , :type] ) + @compiler = CompilerMock.new + @instruction = @load.to_risc(@compiler) + end + + def test_ins_next_class + assert_equal Risc::SlotToReg , @instruction.next.class + end + def test_ins_next_next_class + assert_equal Risc::RegToSlot , @instruction.next.next.class + end + + def test_ins_next_reg + assert_equal :r1 , @instruction.next.register.symbol + end + def test_ins_next_arr + assert_equal :r1 , @instruction.next.array.symbol + end + def test_ins_next_index + assert_equal 0 , @instruction.next.index + end + + def test_ins_next_next_reg + assert_equal :r1 , @instruction.next.next.register.symbol + end + def test_ins_next_next_arr + assert_equal :r0 , @instruction.next.next.array.symbol + end + def test_ins_next_next_index + assert_equal 6 , @instruction.next.next.index + end + end +end