lots more ripples from changing calling convention

This commit is contained in:
Torsten Ruger 2016-12-27 20:40:37 +02:00
parent 903fc3e4cf
commit 7462d0c486
8 changed files with 59 additions and 55 deletions

View File

@ -23,11 +23,12 @@ HERE
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", "RegToSlot","LoadConstant","SlotToReg","RegToSlot","LoadConstant",
"SlotToReg","SlotToReg","SlotToReg","RegToByte","Label", "RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg",
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label", "SlotToReg","SlotToReg","SlotToReg","SlotToReg","RegToByte",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"] "Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg",
"Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end end
def test_branch def test_branch
@ -50,12 +51,12 @@ HERE
assert_equal Register::FunctionCall , ticks(8).class assert_equal Register::FunctionCall , ticks(8).class
end end
def test_exit def test_exit
done = ticks(39) done = ticks(45)
assert_equal NilClass , done.class assert_equal NilClass , done.class
end end
def test_reg_to_byte def test_reg_to_byte
done = ticks(29) done = ticks(35)
assert_equal Register::RegToByte , done.class assert_equal Register::RegToByte , done.class
assert_equal "h".ord , @interpreter.get_register(done.register) assert_equal "h".ord , @interpreter.get_register(done.register)
end end

View File

@ -1,6 +1,6 @@
require_relative "helper" require_relative "helper"
class IfTest < MiniTest::Test class IfCalledTest < MiniTest::Test
include Ticker include Ticker
include Compiling include Compiling
@ -36,15 +36,16 @@ HERE
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "SlotToReg","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"RegisterTransfer","FunctionCall","Label","SlotToReg","LoadConstant", "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
"OperatorInstruction","IsZero","SlotToReg","LoadConstant","RegToSlot", "Label","SlotToReg","SlotToReg","LoadConstant","OperatorInstruction",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "IsZero","SlotToReg","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg", "RegToSlot","LoadConstant","SlotToReg","SlotToReg","RegToSlot",
"SlotToReg","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer", "LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label",
"RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg", "SlotToReg","SlotToReg","RegisterTransfer","Syscall","RegisterTransfer",
"SlotToReg","Branch","Label","Label","FunctionReturn", "RegisterTransfer","RegToSlot","Label","FunctionReturn","RegisterTransfer",
"RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", "SlotToReg","SlotToReg","Branch","Label","Label",
"RegisterTransfer","Syscall","NilClass"] "FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end end
end end

View File

@ -20,11 +20,11 @@ HERE
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", "SlotToReg","SlotToReg","RegToSlot","LoadConstant","RegToSlot",
"Label","SlotToReg","SlotToReg","RegisterTransfer","Syscall", "RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg",
"RegisterTransfer","RegisterTransfer","RegToSlot","Label","FunctionReturn", "RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","RegToSlot",
"RegisterTransfer","SlotToReg","SlotToReg","Label","FunctionReturn", "Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg",
"RegisterTransfer","Syscall","NilClass"] "Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"]
end end
def test_branch def test_branch
@ -48,13 +48,13 @@ HERE
end end
def test_putstring def test_putstring
done = ticks(25) done = ticks(27)
assert_equal Register::Syscall , done.class assert_equal Register::Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout assert_equal "Hello again" , @interpreter.stdout
end end
def test_return def test_return
done = ticks(30) done = ticks(32)
assert_equal Register::FunctionReturn , done.class assert_equal Register::FunctionReturn , done.class
assert Register::Label , @interpreter.instruction.class assert Register::Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}" assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"

View File

@ -23,11 +23,12 @@ HERE
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
"LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg", "LoadConstant","RegToSlot","FunctionCall","Label","SlotToReg",
"LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant", "LoadConstant","RegToSlot","LoadConstant","RegToSlot","LoadConstant",
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","RegToSlot", "SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg",
"RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg", "RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall",
"ByteToReg","RegToSlot","Label","FunctionReturn","RegisterTransfer", "Label","SlotToReg","SlotToReg","SlotToReg","ByteToReg",
"SlotToReg","SlotToReg","Label","FunctionReturn","RegisterTransfer", "RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg",
"Syscall","NilClass"] "SlotToReg","Label","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"]
end end
def test_branch def test_branch
@ -50,12 +51,12 @@ HERE
assert_equal Register::FunctionCall , ticks(8).class assert_equal Register::FunctionCall , ticks(8).class
end end
def test_exit def test_exit
done = ticks(37) done = ticks(41)
assert_equal NilClass , done.class assert_equal NilClass , done.class
end end
def test_byte_to_reg def test_byte_to_reg
done = ticks(26) done = ticks(30)
assert_equal Register::ByteToReg , done.class assert_equal Register::ByteToReg , done.class
assert_equal "H".ord , @interpreter.get_register(done.register) assert_equal "H".ord , @interpreter.get_register(done.register)
end end

View File

@ -35,8 +35,9 @@ class TestAssignStatement < MiniTest::Test
Register.machine.space.get_main.add_local(:r , :Integer) Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) @input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label ,
FunctionReturn]
check check
end end
@ -48,7 +49,7 @@ class TestAssignStatement < MiniTest::Test
was = check was = check
get = was.next(5) get = was.next(5)
assert_equal SlotToReg , get.class 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 end
def test_assign_int def test_assign_int
@ -58,28 +59,28 @@ class TestAssignStatement < MiniTest::Test
was = check was = check
set = was.next(3) set = was.next(3)
assert_equal RegToSlot , set.class 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 end
def test_assign_arg def test_assign_arg
Register.machine.space.get_main.add_argument(:blar , :Integer) Register.machine.space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5))) @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 was = check
set = was.next(2) set = was.next(3)
assert_equal RegToSlot , set.class 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 end
def test_arg_get def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic # have to define bar externally, just because redefining main. Otherwise that would be automatic
Register.machine.space.get_main.add_argument(:balr , :Integer) Register.machine.space.get_main.add_argument(:balr , :Integer)
@input = s(:statements, s(:return, s(:name, :balr))) @input = s(:statements, s(:return, s(:name, :balr)))
@expect = [Label, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check was = check
get = was.next(1) get = was.next(2)
assert_equal SlotToReg , get.class 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 end
end end

View File

@ -8,8 +8,8 @@ class TestCallStatement < MiniTest::Test
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42))) @input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
SlotToReg, SlotToReg, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end end
@ -19,8 +19,8 @@ class TestCallStatement < MiniTest::Test
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello"))) @input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
@expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
SlotToReg, SlotToReg, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end 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)))) @input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
LoadConstant, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn] FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, Label, FunctionReturn]
check check
end end
def _test_call_puts def _test_call_puts

View File

@ -20,10 +20,10 @@ module Register
s(:receiver, s(:name, :main)), s(:field, s(:name, :name))))) 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))))) @input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m)))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [ Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot ,
FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label , LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer, SlotToReg ,
FunctionReturn] SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end

View File

@ -28,8 +28,8 @@ class TestReturnStatement < MiniTest::Test
def test_return_call def test_return_call
@input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments)))) @input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
check check
end end