2015-08-04 21:01:20 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
class AddTest < MiniTest::Test
|
2015-09-27 21:39:10 +02:00
|
|
|
include Ticker
|
2015-10-05 23:27:13 +02:00
|
|
|
|
2015-08-04 21:01:20 +02:00
|
|
|
def setup
|
2015-11-08 13:30:28 +01:00
|
|
|
@string_input = <<HERE
|
2015-11-30 15:20:39 +01:00
|
|
|
class Space
|
2015-11-08 13:30:28 +01:00
|
|
|
int main()
|
|
|
|
return 5 + 7
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2016-12-16 23:19:23 +01:00
|
|
|
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))
|
2015-11-08 13:30:28 +01:00
|
|
|
super
|
|
|
|
end
|
2015-10-16 16:13:08 +02:00
|
|
|
|
2015-11-08 13:30:28 +01:00
|
|
|
def test_chain
|
|
|
|
#show_ticks # get output of what is
|
2016-12-25 17:05:39 +01:00
|
|
|
check_chain ["Branch","Label","LoadConstant","SlotToReg","RegToSlot",
|
2016-12-25 17:02:39 +01:00
|
|
|
"LoadConstant","RegToSlot","FunctionCall","Label","LoadConstant",
|
|
|
|
"LoadConstant","OperatorInstruction","RegToSlot","Label","FunctionReturn",
|
2015-11-08 13:30:28 +01:00
|
|
|
"RegisterTransfer","Syscall","NilClass"]
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get
|
2016-12-25 17:05:39 +01:00
|
|
|
assert_equal Register::SlotToReg , ticks(4).class
|
2015-10-18 16:20:19 +02:00
|
|
|
assert @interpreter.get_register( :r2 )
|
2015-11-04 19:27:48 +01:00
|
|
|
assert Integer , @interpreter.get_register( :r2 ).class
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
|
|
|
def test_transfer
|
2015-11-07 21:20:21 +01:00
|
|
|
transfer = ticks 16
|
2015-08-04 21:01:20 +02:00
|
|
|
assert_equal Register::RegisterTransfer , transfer.class
|
|
|
|
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
|
|
|
end
|
|
|
|
def test_call
|
2015-11-07 21:20:21 +01:00
|
|
|
ret = ticks(15)
|
2015-11-03 10:25:02 +01:00
|
|
|
assert_equal Register::FunctionReturn , ret.class
|
|
|
|
|
2015-11-07 19:10:55 +01:00
|
|
|
object = @interpreter.get_register( ret.register )
|
2015-11-18 14:36:43 +01:00
|
|
|
link = object.get_internal_word( ret.index )
|
2015-11-03 10:25:02 +01:00
|
|
|
|
|
|
|
assert_equal Register::Label , link.class
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
2015-10-16 20:42:11 +02:00
|
|
|
def test_adding
|
2015-11-07 21:20:21 +01:00
|
|
|
done_op = ticks(12)
|
2015-10-16 20:42:11 +02:00
|
|
|
assert_equal Register::OperatorInstruction , done_op.class
|
|
|
|
left = @interpreter.get_register(done_op.left)
|
|
|
|
rr = done_op.right
|
2015-08-08 23:53:04 +02:00
|
|
|
right = @interpreter.get_register(rr)
|
|
|
|
assert_equal Fixnum , left.class
|
|
|
|
assert_equal Fixnum , right.class
|
2015-10-16 20:42:11 +02:00
|
|
|
assert_equal 7 , right
|
|
|
|
assert_equal 12 , left
|
2015-11-07 21:20:21 +01:00
|
|
|
done_tr = ticks(4)
|
2015-10-16 20:42:11 +02:00
|
|
|
assert_equal Register::RegisterTransfer , done_tr.class
|
|
|
|
result = @interpreter.get_register(done_op.left)
|
|
|
|
assert_equal result , 12
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
|
|
|
end
|