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-08 18:39:16 +01:00
|
|
|
@input = s(:statements,
|
|
|
|
s(:class, :Space,
|
|
|
|
s(:derives, nil),
|
|
|
|
s(:statements,
|
|
|
|
s(:function, :Integer,
|
|
|
|
s(:name, :main),
|
|
|
|
s(:parameters),
|
|
|
|
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
|
|
|
|
check_chain ["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
|
|
|
"LoadConstant","SetSlot","FunctionCall","Label","LoadConstant",
|
|
|
|
"LoadConstant","OperatorInstruction","SetSlot","Label","FunctionReturn",
|
|
|
|
"RegisterTransfer","Syscall","NilClass"]
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get
|
2015-10-23 20:27:36 +02:00
|
|
|
assert_equal Register::GetSlot , 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
|