2018-07-31 17:00:42 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-08-16 07:58:49 +02:00
|
|
|
class BlockAssignOuter < MiniTest::Test
|
2018-07-31 17:00:42 +02:00
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = block_main("a = 15 ;yielder {a = 10 ; return 15} ; return a")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_chain
|
2019-08-22 22:10:29 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2019-08-23 18:25:02 +02:00
|
|
|
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15
|
|
|
|
FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero, #20
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #25
|
2020-03-22 10:29:56 +01:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #30
|
2019-08-23 18:25:02 +02:00
|
|
|
SlotToReg, DynamicJump, LoadConstant, SlotToReg, SlotToReg, #35
|
|
|
|
RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg, #40
|
2020-03-22 10:29:56 +01:00
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #45
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #50
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #55
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #60
|
|
|
|
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #65
|
|
|
|
SlotToReg, Transfer, Syscall, NilClass,] #70
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal 10 , get_return
|
|
|
|
end
|
2019-08-23 18:25:02 +02:00
|
|
|
def base ; 32 ; end
|
2018-07-31 17:00:42 +02:00
|
|
|
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_jump
|
2019-08-22 22:10:29 +02:00
|
|
|
load_ins = main_ticks(base)
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal DynamicJump , load_ins.class
|
|
|
|
assert_equal Parfait::Block , @interpreter.get_register(load_ins.register).class
|
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_load
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_load base+1 , Parfait::Integer , :r0
|
|
|
|
assert_equal 10 , @interpreter.get_register(risc(base+1).register).value
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot1
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_slot_to_reg base+2 ,:r13 , 6 , :r1
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot2
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_slot_to_reg base+3 ,:r1 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_reg
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_reg_to_slot base+4 ,:r0 , :r2 , 16
|
2019-08-22 11:26:40 +02:00
|
|
|
end
|
|
|
|
def test_ret_load
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_load base+5 , Parfait::Integer , :r0
|
|
|
|
assert_equal 15 , @interpreter.get_register(risc(base+5).register).value
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|