2018-03-24 17:55:01 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterDynamicCall < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2018-04-19 10:00:55 +03:00
|
|
|
@string_input = as_main("a = 5 ; return a.div4")
|
2018-03-24 17:55:01 +02:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2018-04-04 20:05:09 +03:00
|
|
|
#show_main_ticks # get output of what is
|
2018-05-24 21:20:56 +03:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
2018-08-13 18:02:34 +03:00
|
|
|
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero, # 10
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, Branch, LoadConstant,
|
|
|
|
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg, # 20
|
2018-09-01 11:20:59 +03:00
|
|
|
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
|
|
|
|
IsZero, SlotToReg, Branch, Branch, LoadConstant, # 30
|
|
|
|
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, Branch, Branch, LoadConstant, OperatorInstruction, # 40
|
|
|
|
IsZero, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
|
|
|
Branch, Branch, LoadConstant, OperatorInstruction, IsZero, # 50
|
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
|
|
|
|
Branch, LoadConstant, OperatorInstruction, IsZero, SlotToReg, # 60
|
|
|
|
OperatorInstruction, IsZero, SlotToReg, Branch, Branch,
|
|
|
|
LoadConstant, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, # 70
|
2018-11-24 22:40:22 +02:00
|
|
|
IsZero, RegToSlot, LoadConstant, SlotToReg, LoadConstant,
|
|
|
|
Branch, SlotToReg, SlotToReg, RegToSlot, RegToSlot, # 80
|
2018-09-01 11:20:59 +03:00
|
|
|
RegToSlot, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
2018-11-24 22:40:22 +02:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Branch, # 90
|
|
|
|
SlotToReg, LoadConstant, SlotToReg, DynamicJump, LoadConstant,
|
|
|
|
SlotToReg, LoadConstant, OperatorInstruction, IsNotZero, SlotToReg, # 100
|
|
|
|
RegToSlot, SlotToReg, Branch, SlotToReg, LoadData,
|
|
|
|
OperatorInstruction, RegToSlot, RegToSlot, SlotToReg, SlotToReg, # 110
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
|
|
|
SlotToReg, Branch, SlotToReg, SlotToReg, FunctionReturn, # 120
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, Branch, # 130
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, # 140
|
2018-09-01 11:20:59 +03:00
|
|
|
SlotToReg, SlotToReg, Syscall, NilClass, ]
|
2019-02-07 18:24:35 +02:00
|
|
|
assert_equal ::Integer , get_return.class
|
2018-06-19 18:55:47 +03:00
|
|
|
assert_equal 1 , get_return
|
2018-03-24 17:55:01 +02:00
|
|
|
end
|
|
|
|
|
2018-04-03 12:55:28 +03:00
|
|
|
def test_call_main
|
2018-08-12 15:02:23 +03:00
|
|
|
call_ins = ticks(main_at)
|
2018-03-24 17:55:01 +02:00
|
|
|
assert_equal FunctionCall , call_ins.class
|
|
|
|
assert_equal :main , call_ins.method.name
|
|
|
|
end
|
2018-04-08 22:30:18 +03:00
|
|
|
def test_load_entry
|
2018-05-24 21:20:56 +03:00
|
|
|
call_ins = main_ticks(4)
|
2018-04-08 22:30:18 +03:00
|
|
|
assert_equal LoadConstant , call_ins.class
|
|
|
|
assert_equal Parfait::CacheEntry , call_ins.constant.class
|
2018-04-03 12:55:28 +03:00
|
|
|
end
|
|
|
|
|
2018-04-09 15:06:46 +03:00
|
|
|
def test_dyn
|
2018-09-01 11:20:59 +03:00
|
|
|
cal = main_ticks(94)
|
2018-04-02 16:36:43 +03:00
|
|
|
assert_equal DynamicJump , cal.class
|
|
|
|
end
|
2018-04-09 15:06:46 +03:00
|
|
|
def test_return
|
2018-11-24 22:40:22 +02:00
|
|
|
ret = main_ticks(139)
|
2018-03-24 17:55:01 +02:00
|
|
|
assert_equal FunctionReturn , ret.class
|
|
|
|
link = @interpreter.get_register( ret.register )
|
2019-02-07 18:24:35 +02:00
|
|
|
assert_equal ::Integer , link.class
|
2018-03-24 17:55:01 +02:00
|
|
|
end
|
2018-04-24 20:16:50 +03:00
|
|
|
def test_sys
|
2018-11-24 22:40:22 +02:00
|
|
|
sys = main_ticks(143)
|
2018-04-24 20:16:50 +03:00
|
|
|
assert_equal Syscall , sys.class
|
|
|
|
end
|
2018-03-24 17:55:01 +02:00
|
|
|
end
|
|
|
|
end
|