fix interpreter tests to use classes (not strings)

and fix for the change in call sequence
This commit is contained in:
Torsten Ruger 2017-01-04 21:36:46 +02:00
parent 3f24409093
commit 49da77f996
9 changed files with 112 additions and 101 deletions

View File

@ -18,34 +18,36 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
"RegisterTransfer","Syscall","NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end end
def test_get def test_get
assert_equal Register::SlotToReg , ticks(4).class assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r2 ) assert @interpreter.get_register( :r2 )
assert Integer , @interpreter.get_register( :r2 ).class assert Integer , @interpreter.get_register( :r2 ).class
end end
def test_transfer def test_transfer
transfer = ticks 16 transfer = ticks 19
assert_equal Register::RegisterTransfer , transfer.class assert_equal RegisterTransfer , transfer.class
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from) assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end end
def test_call def test_call
ret = ticks(15) ret = ticks(18)
assert_equal Register::FunctionReturn , ret.class assert_equal FunctionReturn , ret.class
object = @interpreter.get_register( ret.register ) object = @interpreter.get_register( ret.register )
link = object.get_internal_word( ret.index ) link = object.get_internal_word( ret.index )
assert_equal Register::Label , link.class assert_equal Label , link.class
end end
def test_adding def test_adding
done_op = ticks(12) done_op = ticks(12)
assert_equal Register::OperatorInstruction , done_op.class assert_equal OperatorInstruction , done_op.class
left = @interpreter.get_register(done_op.left) left = @interpreter.get_register(done_op.left)
rr = done_op.right rr = done_op.right
right = @interpreter.get_register(rr) right = @interpreter.get_register(rr)
@ -53,8 +55,8 @@ HERE
assert_equal Fixnum , right.class assert_equal Fixnum , right.class
assert_equal 7 , right assert_equal 7 , right
assert_equal 12 , left assert_equal 12 , left
done_tr = ticks(4) done_tr = ticks(1)
assert_equal Register::RegisterTransfer , done_tr.class assert_equal RegToSlot , done_tr.class
result = @interpreter.get_register(done_op.left) result = @interpreter.get_register(done_op.left)
assert_equal result , 12 assert_equal result , 12
end end

View File

@ -21,44 +21,45 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
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,
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
"RegToSlot","LoadConstant","SlotToReg","RegToSlot","LoadConstant", LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
"RegToSlot","RegisterTransfer","FunctionCall","Label","SlotToReg", RegisterTransfer, FunctionCall, Label, LoadConstant, SlotToReg,
"SlotToReg","SlotToReg","SlotToReg","SlotToReg","RegToByte", RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
"Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg", SlotToReg, RegToByte, Label, FunctionReturn, RegisterTransfer,
"Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"] SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
Label, FunctionReturn, RegisterTransfer, Syscall, NilClass]
end end
def test_branch def test_branch
was = @interpreter.instruction was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction" assert @interpreter.instruction , "should have gone to next instruction"
end end
def test_load def test_load
assert_equal Register::LoadConstant , ticks(3).class assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::SlotToReg , ticks(4).class assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end
def test_call def test_call
assert_equal Register::FunctionCall , ticks(8).class assert_equal FunctionCall , ticks(8).class
end end
def test_exit def test_exit
done = ticks(45) done = ticks(50)
assert_equal NilClass , done.class assert_equal NilClass , done.class
end end
def test_reg_to_byte def test_reg_to_byte
done = ticks(35) done = ticks(37)
assert_equal Register::RegToByte , done.class assert_equal 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

@ -34,20 +34,22 @@ HERE
end end
def test_if def test_if
#show_ticks # get output of what is #show_ticks # get output of what is
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,
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label,
"Label","SlotToReg","SlotToReg","LoadConstant","OperatorInstruction", LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
"IsZero","SlotToReg","LoadConstant","RegToSlot","LoadConstant", LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
"RegToSlot","LoadConstant","SlotToReg","SlotToReg","RegToSlot", RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
"LoadConstant","RegToSlot","RegisterTransfer","FunctionCall","Label", RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall,
"SlotToReg","SlotToReg","RegisterTransfer","Syscall","RegisterTransfer", Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
"RegisterTransfer","RegToSlot","Label","FunctionReturn","RegisterTransfer", SlotToReg, RegisterTransfer, Syscall, RegisterTransfer, RegisterTransfer,
"SlotToReg","SlotToReg","Branch","Label","Label", RegToSlot, Label, FunctionReturn, RegisterTransfer, SlotToReg,
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Label", SlotToReg, Branch, Label, Label, FunctionReturn,
"FunctionReturn","RegisterTransfer","Syscall","NilClass"] RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end end
end end
end end

View File

@ -31,16 +31,17 @@ module Register
def test_instruction_events def test_instruction_events
@interpreter.register_event :instruction_changed , self @interpreter.register_event :instruction_changed , self
ticks 30 ticks 30
assert_equal 17 , @instruction_events.length assert_equal 20 , @instruction_events.length
@interpreter.unregister_event :instruction_changed , self @interpreter.unregister_event :instruction_changed , self
end end
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
"RegisterTransfer","Syscall","NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end end
end end

View File

@ -19,10 +19,11 @@ HERE
def test_mult def test_mult
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
"RegisterTransfer","Syscall","NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
check_return 0 check_return 0
end end
def test_overflow def test_overflow

View File

@ -18,10 +18,11 @@ HERE
def test_add def test_add
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn", LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
"RegisterTransfer","Syscall","NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
check_return 0 check_return 0
end end

View File

@ -18,51 +18,52 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
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,
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","RegToSlot", SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer,
"RegisterTransfer","FunctionCall","Label","SlotToReg","SlotToReg", FunctionCall, Label, LoadConstant, SlotToReg, RegToSlot,
"RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","RegToSlot", SlotToReg, SlotToReg, RegisterTransfer, Syscall, RegisterTransfer,
"Label","FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg", RegisterTransfer, RegToSlot, Label, FunctionReturn, RegisterTransfer,
"Label","FunctionReturn","RegisterTransfer","Syscall","NilClass"] SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot,
Label, FunctionReturn, RegisterTransfer, Syscall, NilClass]
end end
def test_branch def test_branch
was = @interpreter.instruction was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction" assert @interpreter.instruction , "should have gone to next instruction"
end end
def test_load def test_load
assert_equal Register::LoadConstant , ticks(3).class assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::SlotToReg , ticks(4).class assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end
def test_call def test_call
assert_equal Register::FunctionCall , ticks(8).class assert_equal FunctionCall , ticks(8).class
end end
def test_putstring def test_putstring
done = ticks(27) done = ticks(29)
assert_equal Register::Syscall , done.class assert_equal 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(32) done = ticks(34)
assert_equal Register::FunctionReturn , done.class assert_equal FunctionReturn , done.class
assert Register::Label , @interpreter.instruction.class assert Label , @interpreter.instruction.class
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}" assert @interpreter.instruction.is_a?(Instruction) , "not instruction #{@interpreter.instruction}"
end end
def test_exit def test_exit
done = ticks(42) done = ticks(45)
assert_equal NilClass , done.class assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout assert_equal "Hello again" , @interpreter.stdout
end end

View File

@ -21,44 +21,45 @@ HERE
def test_chain def test_chain
#show_ticks # get output of what is #show_ticks # get output of what is
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,
"SlotToReg","SlotToReg","RegToSlot","LoadConstant","SlotToReg", SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
"RegToSlot","LoadConstant","RegToSlot","RegisterTransfer","FunctionCall", LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label,
"Label","SlotToReg","SlotToReg","SlotToReg","ByteToReg", LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
"RegToSlot","Label","FunctionReturn","RegisterTransfer","SlotToReg", SlotToReg, ByteToReg, RegToSlot, Label, FunctionReturn,
"SlotToReg","Label","FunctionReturn","RegisterTransfer","Syscall", RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
"NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end end
def test_branch def test_branch
was = @interpreter.instruction was = @interpreter.instruction
assert_equal Register::Branch , ticks(1).class assert_equal Branch , ticks(1).class
assert was != @interpreter.instruction assert was != @interpreter.instruction
assert @interpreter.instruction , "should have gone to next instruction" assert @interpreter.instruction , "should have gone to next instruction"
end end
def test_load def test_load
assert_equal Register::LoadConstant , ticks(3).class assert_equal LoadConstant , ticks(3).class
assert_equal Parfait::Space , @interpreter.get_register(:r2).class assert_equal Parfait::Space , @interpreter.get_register(:r2).class
assert_equal :r2, @interpreter.instruction.array.symbol assert_equal :r2, @interpreter.instruction.array.symbol
end end
def test_get def test_get
assert_equal Register::SlotToReg , ticks(4).class assert_equal SlotToReg , ticks(4).class
assert @interpreter.get_register( :r1 ) assert @interpreter.get_register( :r1 )
assert Integer , @interpreter.get_register( :r1 ).class assert Integer , @interpreter.get_register( :r1 ).class
end end
def test_call def test_call
assert_equal Register::FunctionCall , ticks(8).class assert_equal FunctionCall , ticks(8).class
end end
def test_exit def test_exit
done = ticks(41) done = ticks(46)
assert_equal NilClass , done.class assert_equal NilClass , done.class
end end
def test_byte_to_reg def test_byte_to_reg
done = ticks(30) done = ticks(32)
assert_equal Register::ByteToReg , done.class assert_equal 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

@ -26,16 +26,17 @@ HERE
def test_if def test_if
#show_ticks # get output of what is #show_ticks # get output of what is
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot", check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant", LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
"LoadConstant","OperatorInstruction","IsZero","SlotToReg","LoadConstant", LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
"RegToSlot","LoadConstant","RegToSlot","LoadConstant","SlotToReg", RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
"SlotToReg","RegToSlot","LoadConstant","RegToSlot","RegisterTransfer", RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall,
"FunctionCall","Label","SlotToReg","SlotToReg","RegisterTransfer", Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
"Syscall","RegisterTransfer","RegisterTransfer","RegToSlot","Label", SlotToReg, RegisterTransfer, Syscall, RegisterTransfer, RegisterTransfer,
"FunctionReturn","RegisterTransfer","SlotToReg","SlotToReg","Branch", RegToSlot, Label, FunctionReturn, RegisterTransfer, SlotToReg,
"Label","Label","FunctionReturn","RegisterTransfer","Syscall", SlotToReg, Branch, Label, LoadConstant, SlotToReg,
"NilClass"] RegToSlot, Label, FunctionReturn, RegisterTransfer, Syscall,
NilClass]
end end
end end
end end