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",
"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

View File

@ -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

View File

@ -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}"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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