2018-04-05 11:19:29 +02:00
|
|
|
require_relative "../helper"
|
2018-03-30 17:05:38 +02:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestCallSimpleArgs < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@input = "5.get_internal_word(1)"
|
2018-08-12 14:02:23 +02:00
|
|
|
@expect = [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall,
|
|
|
|
Label]
|
2018-03-30 17:05:38 +02:00
|
|
|
end
|
|
|
|
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_send_instructions
|
2018-03-30 17:05:38 +02:00
|
|
|
assert_nil msg = check_nil , msg
|
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_5
|
2018-03-30 17:05:38 +02:00
|
|
|
produced = produce_body
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_equal LoadConstant , produced.next(8).class
|
|
|
|
assert_equal 5 , produced.next(8).constant.value
|
2018-04-06 22:37:41 +02:00
|
|
|
end
|
|
|
|
def base
|
2018-08-12 14:02:23 +02:00
|
|
|
11
|
2018-03-30 17:05:38 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_arg_const
|
2018-03-30 19:01:31 +02:00
|
|
|
produced = produce_body
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_load( produced.next(base) , Parfait::Integer )
|
2018-07-22 21:29:32 +02:00
|
|
|
assert_equal 1 , produced.next(base).constant.value
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_next_m
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+1)
|
|
|
|
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_args
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+2)
|
|
|
|
assert_slot_to_reg( produced ,:r2 ,8 , :r2 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_store_arg_at
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+3)
|
|
|
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 1 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_label
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+4)
|
|
|
|
assert_load( produced , Label )
|
2018-03-30 17:05:38 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_load_some
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+5)
|
|
|
|
assert_slot_to_reg( produced ,:r0 ,1 , :r2 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_store_
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+6)
|
|
|
|
assert_reg_to_slot( produced ,:r1 ,:r2 , 4 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
|
|
|
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_swap_messages
|
2018-08-12 14:02:23 +02:00
|
|
|
produced = produce_body.next(base+7)
|
|
|
|
assert_slot_to_reg( produced ,:r0 ,1 , :r0 )
|
2018-03-30 19:01:31 +02:00
|
|
|
end
|
|
|
|
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_function_call
|
2018-03-30 17:05:38 +02:00
|
|
|
produced = produce_body
|
2018-05-24 18:38:48 +02:00
|
|
|
assert_equal FunctionCall , produced.next(base+8).class
|
|
|
|
assert_equal :get_internal_word , produced.next(base+8).method.name
|
2018-03-30 17:05:38 +02:00
|
|
|
end
|
2019-08-10 20:59:31 +02:00
|
|
|
def pest_check_continue
|
2018-03-30 17:05:38 +02:00
|
|
|
produced = produce_body
|
2018-05-24 18:38:48 +02:00
|
|
|
assert produced.next(base+9).name.start_with?("continue_")
|
2018-03-30 17:05:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|