removed blocks and moved to labels

somewhat easier to understand the code as a linked list
relatively painless change, considering
This commit is contained in:
Torsten Ruger
2015-10-23 21:27:36 +03:00
parent f1f56f0d4e
commit 57f37ec023
22 changed files with 281 additions and 370 deletions

View File

@ -24,32 +24,22 @@ class AddTest < MiniTest::Test
@interpreter.start Register.machine.init
end
def test_branch
was = @interpreter.block
assert_equal Register::Branch , ticks(1).class
assert was != @interpreter.block
end
def test_load
assert_equal Register::LoadConstant , ticks(2).class
assert_equal Parfait::Space , Register.machine.objects[ @interpreter.get_register(:r2)].class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::GetSlot , ticks(3).class
assert_equal Register::GetSlot , ticks(4).class
assert @interpreter.get_register( :r2 )
assert @interpreter.get_register( :r2 ).is_a? Integer
end
def test_transfer
transfer = ticks 5
transfer = ticks 6
assert_equal Register::RegisterTransfer , transfer.class
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
assert_equal Register::FunctionCall , ticks(6).class
assert_equal Register::FunctionCall , ticks(7).class
assert @interpreter.link
end
def test_adding
done_op = ticks(10)
done_op = ticks(12)
assert_equal Register::OperatorInstruction , done_op.class
left = @interpreter.get_register(done_op.left)
rr = done_op.right
@ -58,7 +48,7 @@ class AddTest < MiniTest::Test
assert_equal Fixnum , right.class
assert_equal 7 , right
assert_equal 12 , left
done_tr = ticks(1)
done_tr = ticks(2)
assert_equal Register::RegisterTransfer , done_tr.class
result = @interpreter.get_register(done_op.left)
assert_equal result , 12
@ -66,10 +56,10 @@ class AddTest < MiniTest::Test
def test_chain
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"FunctionCall","SaveReturn","LoadConstant","LoadConstant","OperatorInstruction",
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"].each_with_index do |name , index|
["Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","LoadConstant",
"LoadConstant","OperatorInstruction","Label","RegisterTransfer","GetSlot",
"FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end

View File

@ -31,16 +31,18 @@ HERE
@interpreter = Interpreter::Interpreter.new
@interpreter.start Register.machine.init
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"FunctionCall","SaveReturn","GetSlot","GetSlot","SetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
"FunctionCall","SaveReturn","GetSlot","LoadConstant","OperatorInstruction",
"IsZero","GetSlot","LoadConstant","SetSlot","LoadConstant",
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","SetSlot",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Branch",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","RegisterTransfer",
"GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
["Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
"GetSlot","SetSlot","LoadConstant","SetSlot","LoadConstant",
"SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn",
"GetSlot","LoadConstant","OperatorInstruction","IsZero","GetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
"FunctionCall","Label","SaveReturn","GetSlot","RegisterTransfer",
"Syscall","RegisterTransfer","RegisterTransfer","SetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Branch",
"Label","Label","RegisterTransfer","GetSlot","FunctionReturn",
"GetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn",
"RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end

View File

@ -59,26 +59,30 @@ HERE
@interpreter = Interpreter::Interpreter.new
@interpreter.start Register.machine.init
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
"LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot",
["Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
"FunctionCall","Label","SaveReturn","LoadConstant","GetSlot",
"SetSlot","GetSlot","GetSlot","SetSlot","LoadConstant",
"SetSlot","GetSlot","GetSlot","SetSlot","RegisterTransfer",
"FunctionCall","Label","SaveReturn","GetSlot","LoadConstant",
"OperatorInstruction","GetSlot","SetSlot","GetSlot","GetSlot",
"GetSlot","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"GetSlot","IsNotzero","Label","GetSlot","GetSlot",
"SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot",
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","GetSlot","IsNotzero","GetSlot","GetSlot",
"SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot",
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"LoadConstant","OperatorInstruction","IsZero","Branch","GetSlot",
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","GetSlot",
"LoadConstant","OperatorInstruction","IsZero","LoadConstant","RegisterTransfer",
"GetSlot","FunctionReturn","GetSlot","GetSlot","SetSlot",
"GetSlot","GetSlot","GetSlot","OperatorInstruction","SetSlot",
"GetSlot","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","RegisterTransfer",
"SetSlot","RegisterTransfer","FunctionCall","Label","SaveReturn",
"GetSlot","LoadConstant","OperatorInstruction","IsZero","Branch",
"Label","GetSlot","LoadConstant","OperatorInstruction","IsZero",
"Label","LoadConstant","Label","GetSlot","LoadConstant",
"OperatorInstruction","IsZero","Label","LoadConstant","Label",
"GetSlot","LoadConstant","OperatorInstruction","IsZero","Label",
"LoadConstant","Label","GetSlot","LoadConstant","OperatorInstruction",
"IsZero","Label","LoadConstant","Label","Label",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","GetSlot",
"SetSlot","GetSlot","GetSlot","GetSlot","OperatorInstruction",
"SetSlot","Label","GetSlot","Label","RegisterTransfer",
"GetSlot","FunctionReturn","GetSlot","Label","RegisterTransfer",
"GetSlot","FunctionReturn","GetSlot","Label","RegisterTransfer",
"GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"

View File

@ -25,42 +25,44 @@ class TestPuts < MiniTest::Test
end
def test_branch
was = @interpreter.block
was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class
assert was != @interpreter.block
assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction"
end
def test_load
assert_equal Register::LoadConstant , ticks(2).class
assert_equal Register::LoadConstant , ticks(3).class
assert_equal Parfait::Space , Register.machine.objects[ @interpreter.get_register(:r2)].class
assert_equal :r2, @interpreter.instruction.array.symbol
end
def test_get
assert_equal Register::GetSlot , ticks(3).class
assert_equal Register::GetSlot , ticks(4).class
assert @interpreter.get_register( :r1 )
assert @interpreter.get_register( :r1 ).is_a? Integer
end
def test_transfer
transfer = ticks 5
transfer = ticks 6
assert_equal Register::RegisterTransfer , transfer.class
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
assert_equal Register::FunctionCall , ticks(6).class
assert_equal Register::FunctionCall , ticks(7).class
assert @interpreter.link
end
def test_save
done = ticks(7)
done = ticks(9)
assert_equal Register::SaveReturn , done.class
assert @interpreter.get_register done.register.symbol
end
def test_chain
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
"SetSlot","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
[ "Branch","Label","LoadConstant","GetSlot","SetSlot",
"RegisterTransfer","FunctionCall","Label","SaveReturn","GetSlot",
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
"FunctionCall","Label","SaveReturn","GetSlot","RegisterTransfer",
"Syscall","RegisterTransfer","RegisterTransfer","SetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Label",
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"].each_with_index do |name , index|
got = ticks(1)
@ -70,20 +72,20 @@ class TestPuts < MiniTest::Test
end
def test_putstring
done = ticks(18)
done = ticks(21)
assert_equal Register::Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
end
def test_return
done = ticks(24)
done = ticks(28)
assert_equal Register::FunctionReturn , done.class
assert @interpreter.block.is_a?(Register::Block)
assert Register::Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"
end
def test_exit
done = ticks(31)
done = ticks(36)
assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout
end