diff --git a/test/register/interpreter/test_byte_to_reg.rb b/test/register/interpreter/test_byte_to_reg.rb index 9c85bf3e..ffb09f3f 100644 --- a/test/register/interpreter/test_byte_to_reg.rb +++ b/test/register/interpreter/test_byte_to_reg.rb @@ -23,11 +23,12 @@ HERE check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", - "LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", - "SlotToReg","SlotToReg","SlotToReg","RegToByte","Label", - "FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label", - "FunctionReturn","RegisterTransfer","Syscall","NilClass"] + "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", + "RegToSlot","LoadConstant","SlotToReg","RegToSlot","LoadConstant", + "RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg", + "SlotToReg","SlotToReg","SlotToReg","SlotToReg","RegToByte", + "Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg", + "Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"] end def test_branch @@ -50,12 +51,12 @@ HERE assert_equal Register::FunctionCall , ticks(8).class end def test_exit - done = ticks(39) + done = ticks(45) assert_equal NilClass , done.class end def test_reg_to_byte - done = ticks(29) + done = ticks(35) assert_equal Register::RegToByte , done.class assert_equal "h".ord , @interpreter.get_register(done.register) end diff --git a/test/register/interpreter/test_called_if.rb b/test/register/interpreter/test_called_if.rb index a2a57780..5d432c37 100644 --- a/test/register/interpreter/test_called_if.rb +++ b/test/register/interpreter/test_called_if.rb @@ -1,6 +1,6 @@ require_relative "helper" -class IfTest < MiniTest::Test +class IfCalledTest < MiniTest::Test include Ticker include Compiling @@ -36,15 +36,16 @@ HERE check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", - "RegisterTransfer","FunctionCall","Label","SlotToReg","LoadConstant", - "OperatorInstruction","IsZero","SlotToReg","LoadConstant","RegToSlot", - "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg", - "SlotToReg","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", - "RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg", - "SlotToReg","Branch","Label","Label","FunctionReturn", - "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", - "RegisterTransfer","Syscall","NilClass"] + "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", + "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", + "Label","SlotToReg","SlotToReg","LoadConstant","OperatorInstruction", + "IsZero","SlotToReg","LoadConstant","RegToSlot","LoadConstant", + "RegToSlot","LoadConstant","SlotToReg","SlotToReg","RegToSlot", + "LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", + "SlotToReg","SlotToReg","RegisterTransfer","Syscall","RegisterTransfer", + "RegisterTransfer","RegToSlot","Label","FunctionReturn","RegisterTransfer", + "SlotToReg","SlotToReg","Branch","Label","Label", + "FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label", + "FunctionReturn","RegisterTransfer","Syscall","NilClass"] end end diff --git a/test/register/interpreter/test_puts.rb b/test/register/interpreter/test_puts.rb index ba5c52f8..3e805536 100644 --- a/test/register/interpreter/test_puts.rb +++ b/test/register/interpreter/test_puts.rb @@ -20,11 +20,11 @@ HERE check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", - "Label","SlotToReg","SlotToReg","RegisterTransfer","Syscall", - "RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn", - "RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", - "RegisterTransfer","Syscall","NilClass"] + "SlotToReg","SlotToReg","RegToSlot","LoadConstant","RegToSlot", + "RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg", + "RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","RegToSlot", + "Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg", + "Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"] end def test_branch @@ -48,13 +48,13 @@ HERE end def test_putstring - done = ticks(25) + done = ticks(27) assert_equal Register::Syscall , done.class assert_equal "Hello again" , @interpreter.stdout end def test_return - done = ticks(30) + done = ticks(32) assert_equal Register::FunctionReturn , done.class assert Register::Label , @interpreter.instruction.class assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}" diff --git a/test/register/interpreter/test_reg_to_byte.rb b/test/register/interpreter/test_reg_to_byte.rb index 261f2033..3b3ad5da 100644 --- a/test/register/interpreter/test_reg_to_byte.rb +++ b/test/register/interpreter/test_reg_to_byte.rb @@ -23,11 +23,12 @@ HERE check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", - "RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", - "RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg", - "ByteToReg","RegToSlot","Label","FunctionReturn","RegisterTransfer", - "SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer", - "Syscall","NilClass"] + "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", + "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", + "Label","SlotToReg","SlotToReg","SlotToReg","ByteToReg", + "RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg", + "SlotToReg","Label","FunctionReturn","RegisterTransfer","Syscall", + "NilClass"] end def test_branch @@ -50,12 +51,12 @@ HERE assert_equal Register::FunctionCall , ticks(8).class end def test_exit - done = ticks(37) + done = ticks(41) assert_equal NilClass , done.class end def test_byte_to_reg - done = ticks(26) + done = ticks(30) assert_equal Register::ByteToReg , done.class assert_equal "H".ord , @interpreter.get_register(done.register) end diff --git a/test/typed/statements/test_assign.rb b/test/typed/statements/test_assign.rb index 422532a6..0864c7f8 100644 --- a/test/typed/statements/test_assign.rb +++ b/test/typed/statements/test_assign.rb @@ -35,8 +35,9 @@ class TestAssignStatement < MiniTest::Test Register.machine.space.get_main.add_local(:r , :Integer) @input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , - SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , + Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label , + FunctionReturn] check end @@ -48,7 +49,7 @@ class TestAssignStatement < MiniTest::Test was = check get = was.next(5) assert_equal SlotToReg , get.class - assert_equal 1, get.index , "Get to named_list index must be offset, not #{get.index}" + assert_equal 1 + 1, get.index , "Get to named_list index must be offset, not #{get.index}" end def test_assign_int @@ -58,28 +59,28 @@ class TestAssignStatement < MiniTest::Test was = check set = was.next(3) assert_equal RegToSlot , set.class - assert_equal 1, set.index , "Set to named_list index must be offset, not #{set.index}" + assert_equal 1 + 1, set.index , "Set to named_list index must be offset, not #{set.index}" end def test_assign_arg Register.machine.space.get_main.add_argument(:blar , :Integer) @input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5))) - @expect = [Label, LoadConstant, RegToSlot, Label, FunctionReturn] + @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] was = check - set = was.next(2) + set = was.next(3) assert_equal RegToSlot , set.class - assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}" + assert_equal 1 + 1, set.index , "Set to args index must be offset, not #{set.index}" end def test_arg_get # have to define bar externally, just because redefining main. Otherwise that would be automatic Register.machine.space.get_main.add_argument(:balr , :Integer) @input = s(:statements, s(:return, s(:name, :balr))) - @expect = [Label, SlotToReg, RegToSlot, Label, FunctionReturn] + @expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] was = check - get = was.next(1) + get = was.next(2) assert_equal SlotToReg , get.class - assert_equal 1, get.index , "Get to args index must be offset, not #{get.index}" + assert_equal 1 + 1, get.index , "Get to args index must be offset, not #{get.index}" end end end diff --git a/test/typed/statements/test_call.rb b/test/typed/statements/test_call.rb index 3acf0c0e..6e79b6c4 100644 --- a/test/typed/statements/test_call.rb +++ b/test/typed/statements/test_call.rb @@ -8,8 +8,8 @@ class TestCallStatement < MiniTest::Test clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) @input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42))) @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , - SlotToReg, SlotToReg, Label, FunctionReturn] + SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , + Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] check end @@ -19,8 +19,8 @@ class TestCallStatement < MiniTest::Test @input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello"))) @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , - SlotToReg, SlotToReg, Label, FunctionReturn] + SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , + Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] check end @@ -42,9 +42,9 @@ class TestCallStatement < MiniTest::Test @input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l)))) @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , - LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , - RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] - check + LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , + FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] + check end def _test_call_puts diff --git a/test/typed/statements/test_fields.rb b/test/typed/statements/test_fields.rb index 71054e09..1088631d 100644 --- a/test/typed/statements/test_fields.rb +++ b/test/typed/statements/test_fields.rb @@ -20,10 +20,10 @@ module Register s(:receiver, s(:name, :main)), s(:field, s(:name, :name))))) @input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m))))) - @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , - FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label , - FunctionReturn] + @expect = [ Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , + SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot , + LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg , + SlotToReg, RegToSlot, Label, FunctionReturn] check end diff --git a/test/typed/statements/test_return.rb b/test/typed/statements/test_return.rb index a729c269..4c8f0235 100644 --- a/test/typed/statements/test_return.rb +++ b/test/typed/statements/test_return.rb @@ -28,8 +28,8 @@ class TestReturnStatement < MiniTest::Test def test_return_call @input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments)))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , - SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] + SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , + Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] check end