2019-08-12 12:16:15 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
module SlotMachine
|
2019-08-12 12:16:15 +02:00
|
|
|
module Builtin
|
|
|
|
class TestIntComp1Risc < BootTest
|
|
|
|
def setup
|
2019-09-13 09:41:13 +02:00
|
|
|
@method = get_compiler("Integer",:lt)
|
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot_length
|
2019-09-13 09:41:13 +02:00
|
|
|
assert_equal :< , @method.callable.name
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal 7 , @method.slot_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
def test_compile
|
|
|
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
|
|
|
end
|
|
|
|
def test_risc_length
|
2020-03-03 21:35:23 +01:00
|
|
|
assert_equal 25 , @method.to_risc.risc_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
class TestIntComp2Risc < BootTest
|
|
|
|
def setup
|
2020-03-06 20:26:23 +01:00
|
|
|
@method = get_compiler("Integer",:gt)
|
2019-09-13 09:41:13 +02:00
|
|
|
end
|
2019-10-03 19:55:41 +02:00
|
|
|
def test_slot_length
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_equal :> , @method.callable.name
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal 7 , @method.slot_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
def test_compile
|
|
|
|
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
|
|
|
end
|
|
|
|
def test_risc_length
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_equal 25 , @method.to_risc.risc_instructions.length
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
2020-03-06 17:09:56 +01:00
|
|
|
def test_all
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_slot_to_reg 1 , :message , 2 , "message.receiver"
|
2020-03-09 11:48:47 +01:00
|
|
|
assert_slot_to_reg 2 , "message.receiver" , 2 , "message.receiver.data_1"
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_slot_to_reg 3 ,:message , 9 , "message.arg1"
|
2020-03-09 11:48:47 +01:00
|
|
|
assert_slot_to_reg 4 , "message.arg1" , 2 , "message.arg1.data_1"
|
2020-03-14 11:47:29 +01:00
|
|
|
assert_operator 5 , :- , "message.receiver.data_1" , "message.arg1.data_1" ,"op_-_"
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_minus 6 , "false_label_"
|
2020-03-17 10:06:33 +01:00
|
|
|
assert_zero 7 , "false_label_"
|
2020-03-06 20:26:23 +01:00
|
|
|
assert_load 8 , Parfait::TrueClass , :result
|
|
|
|
assert_branch 9 , "merge_label_"
|
|
|
|
assert_label 10 , "false_label_"
|
|
|
|
assert_load 11 , Parfait::FalseClass , :result
|
|
|
|
assert_label 12 , "merge_label_"
|
|
|
|
assert_reg_to_slot 13 , :result , :message , 5
|
|
|
|
assert_slot_to_reg 14 ,:message , 5 , "message.return_value"
|
|
|
|
assert_reg_to_slot 15 , "message.return_value" , :message , 5
|
|
|
|
assert_branch 16 , "return_label"
|
2020-03-06 17:09:56 +01:00
|
|
|
end
|
|
|
|
def test_return
|
|
|
|
assert_return(17)
|
|
|
|
end
|
2019-08-12 12:16:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|