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 09:20:39 +02:00
|
|
|
check_main_chain [LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, RegToSlot, RegToSlot, RegToSlot, # 10
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 20
|
|
|
|
FunctionCall, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot, # 30
|
|
|
|
RegToSlot, RegToSlot, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, LoadConstant, RegToSlot, SlotToReg, # 40
|
|
|
|
SlotToReg, DynamicJump, LoadConstant, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg, # 50
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 60
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot, # 70
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 80
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, Branch, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 90
|
|
|
|
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal 10 , get_return
|
|
|
|
end
|
|
|
|
|
2019-08-23 09:20:39 +02:00
|
|
|
def base ; 42 ; end
|
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
|
2019-08-22 22:10:29 +02:00
|
|
|
load_ins = main_ticks(base+1)
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_load load_ins , Parfait::Integer , :r1
|
|
|
|
assert_equal 10 , @interpreter.get_register(load_ins.register).value
|
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot1
|
2019-08-22 22:10:29 +02:00
|
|
|
assert_slot_to_reg main_ticks(base+2) ,:r0 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot2
|
2019-08-22 22:10:29 +02:00
|
|
|
assert_slot_to_reg main_ticks(base+3) ,:r2 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_reg
|
2019-08-23 09:20:39 +02:00
|
|
|
assert_reg_to_slot main_ticks(base+4) ,:r1 , :r2 , 16
|
2019-08-22 11:26:40 +02:00
|
|
|
end
|
|
|
|
def test_ret_load
|
2019-08-23 09:20:39 +02:00
|
|
|
load_ins = main_ticks(base+5)
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_load load_ins , Parfait::Integer , :r1
|
|
|
|
assert_equal 15 , @interpreter.get_register(load_ins.register).value
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|