2019-08-13 18:32:17 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestBlockSetup < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
2019-09-12 21:27:10 +02:00
|
|
|
|
2019-08-13 18:32:17 +02:00
|
|
|
@input = as_block("return 5")
|
2019-08-23 18:24:18 +02:00
|
|
|
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15
|
|
|
|
FunctionCall, Label,] #20
|
2019-08-13 18:32:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_send_instructions
|
2019-08-14 10:11:26 +02:00
|
|
|
assert_nil msg = check_nil(:main) , msg
|
2019-08-13 18:32:17 +02:00
|
|
|
end
|
2019-08-19 14:23:57 +02:00
|
|
|
def test_load_5_block
|
2019-08-14 10:11:26 +02:00
|
|
|
produced = produce_block.next
|
|
|
|
assert_load( produced , Parfait::Integer)
|
|
|
|
assert_equal 5 , produced.constant.value
|
|
|
|
end
|
2019-08-13 18:32:17 +02:00
|
|
|
def test_load_5
|
|
|
|
produced = produce_body
|
|
|
|
assert_load( produced , Parfait::Integer)
|
|
|
|
assert_equal 5 , produced.constant.value
|
|
|
|
end
|
2019-08-19 14:23:57 +02:00
|
|
|
def test_load_block
|
2019-08-23 18:24:18 +02:00
|
|
|
produced = produce_body.next(8)
|
2019-08-19 14:23:57 +02:00
|
|
|
assert_load( produced , Parfait::Block)
|
|
|
|
assert_equal :main_block , produced.constant.name
|
|
|
|
end
|
2019-08-23 14:31:04 +02:00
|
|
|
def test_load_return
|
2019-08-23 18:24:18 +02:00
|
|
|
produced = produce_body.next(11)
|
2019-08-13 18:32:17 +02:00
|
|
|
assert_load( produced , Label)
|
|
|
|
assert produced.constant.name.start_with?("continue_")
|
|
|
|
end
|
|
|
|
def test_function_call
|
2019-08-23 18:24:18 +02:00
|
|
|
produced = produce_body.next(15)
|
2019-08-13 18:32:17 +02:00
|
|
|
assert_equal FunctionCall , produced.class
|
|
|
|
assert_equal :main , produced.method.name
|
|
|
|
end
|
|
|
|
def test_check_continue
|
2019-08-23 18:24:18 +02:00
|
|
|
produced = produce_body.next(16)
|
2019-08-13 18:32:17 +02:00
|
|
|
assert_equal Label , produced.class
|
2019-08-23 14:31:04 +02:00
|
|
|
assert produced.name.start_with?("continue_") , produced.name
|
2019-08-13 18:32:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|