2018-07-31 17:00:42 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class BloclAssignOuter < MiniTest::Test
|
|
|
|
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
|
2018-07-31 17:00:42 +02:00
|
|
|
#show_main_ticks # get output of what is
|
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
2018-08-12 14:02:23 +02:00
|
|
|
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 10
|
|
|
|
RegToSlot, RegToSlot, RegToSlot, Branch, RegToSlot,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, # 20
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, Branch, FunctionCall, LoadConstant, # 30
|
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg,
|
|
|
|
LoadConstant, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 40
|
|
|
|
RegToSlot, RegToSlot, Branch, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, # 50
|
|
|
|
SlotToReg, SlotToReg, DynamicJump, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, # 60
|
|
|
|
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, Branch, RegToSlot, RegToSlot, SlotToReg, # 70
|
|
|
|
SlotToReg, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 80
|
|
|
|
Branch, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 90
|
|
|
|
Branch, SlotToReg, FunctionReturn, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, # 100
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
Branch, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 110
|
|
|
|
SlotToReg, SlotToReg, Syscall, 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
|
2018-08-12 14:02:23 +02:00
|
|
|
load_ins = main_ticks(53)
|
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
|
2018-08-12 14:02:23 +02:00
|
|
|
load_ins = main_ticks(54)
|
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
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_slot_to_reg main_ticks(55) ,:r0 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot2
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_slot_to_reg main_ticks(56) ,:r2 , 6 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_slot3
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_slot_to_reg main_ticks(57) ,:r2 , 3 , :r2
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
2018-08-06 13:07:17 +02:00
|
|
|
def test_block_reg
|
2018-08-12 14:02:23 +02:00
|
|
|
assert_reg_to_slot main_ticks(58) ,:r1 , :r2 , 1
|
2018-07-31 17:00:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|