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-16 20:43:54 +02:00
|
|
|
# show_main_ticks # get output of what is
|
2019-08-19 14:23:57 +02:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, LoadConstant,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, # 10
|
2019-08-22 11:26:40 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, # 20
|
|
|
|
RegToSlot, SlotToReg, FunctionCall, LoadConstant, SlotToReg,
|
|
|
|
OperatorInstruction, IsZero, SlotToReg, SlotToReg, LoadConstant, # 30
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg, # 40
|
|
|
|
LoadConstant, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
|
|
|
DynamicJump, LoadConstant, SlotToReg, SlotToReg, SlotToReg, # 50
|
|
|
|
RegToSlot, LoadConstant, RegToSlot, Branch, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 60
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 70
|
|
|
|
RegToSlot, Branch, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 80
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, Branch, SlotToReg,
|
|
|
|
SlotToReg, Branch, RegToSlot, LoadConstant, SlotToReg, # 90
|
|
|
|
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
|
|
|
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, # 100
|
|
|
|
NilClass, ]
|
2018-07-31 17:00:42 +02:00
|
|
|
assert_equal 10 , get_return
|
|
|
|
end
|
|
|
|
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_jump
|
2019-08-22 11:26:40 +02:00
|
|
|
load_ins = main_ticks(46)
|
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 11:26:40 +02:00
|
|
|
load_ins = main_ticks(47)
|
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 11:26:40 +02:00
|
|
|
assert_slot_to_reg main_ticks(48) ,: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 11:26:40 +02:00
|
|
|
assert_slot_to_reg main_ticks(49) ,:r2 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot3
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_slot_to_reg main_ticks(50) ,:r2 , 3 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_reg
|
2019-08-22 11:26:40 +02:00
|
|
|
assert_reg_to_slot main_ticks(51) ,:r1 , :r2 , 1
|
|
|
|
end
|
|
|
|
def test_ret_load
|
|
|
|
load_ins = main_ticks(52)
|
|
|
|
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
|