2018-03-24 16:55:01 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterDynamicCall < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2018-04-19 09:00:55 +02:00
|
|
|
@string_input = as_main("a = 5 ; return a.div4")
|
2018-03-24 16:55:01 +01:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2018-04-04 19:05:09 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2018-04-19 21:57:31 +02:00
|
|
|
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
2018-04-08 22:45:23 +02:00
|
|
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
|
|
|
|
IsZero, SlotToReg, SlotToReg, SlotToReg, LoadConstant,
|
|
|
|
RegToSlot, LoadConstant, LoadConstant, SlotToReg, SlotToReg,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
2018-04-19 21:57:31 +02:00
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
2018-04-08 22:45:23 +02:00
|
|
|
SlotToReg, OperatorInstruction, IsZero, Label, RegToSlot,
|
|
|
|
Label, LoadConstant, SlotToReg, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
2018-04-09 14:06:46 +02:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
LoadConstant, SlotToReg, DynamicJump, Label, SlotToReg,
|
|
|
|
SlotToReg, LoadData, OperatorInstruction, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2018-04-08 22:45:23 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, FunctionReturn, Transfer, Syscall, NilClass]
|
|
|
|
assert_equal Parfait::Integer , get_return.class
|
2018-04-09 14:06:46 +02:00
|
|
|
assert_equal 1 , get_return.value
|
2018-03-24 16:55:01 +01:00
|
|
|
end
|
|
|
|
|
2018-04-03 11:55:28 +02:00
|
|
|
def test_call_main
|
|
|
|
call_ins = ticks(26)
|
2018-03-24 16:55:01 +01:00
|
|
|
assert_equal FunctionCall , call_ins.class
|
|
|
|
assert_equal :main , call_ins.method.name
|
|
|
|
end
|
2018-04-08 21:30:18 +02:00
|
|
|
def test_load_entry
|
|
|
|
call_ins = main_ticks(5)
|
|
|
|
assert_equal LoadConstant , call_ins.class
|
|
|
|
assert_equal Parfait::CacheEntry , call_ins.constant.class
|
2018-04-03 11:55:28 +02:00
|
|
|
end
|
|
|
|
|
2018-04-09 14:06:46 +02:00
|
|
|
def test_dyn
|
2018-04-19 21:57:31 +02:00
|
|
|
cal = main_ticks(88)
|
2018-04-02 15:36:43 +02:00
|
|
|
assert_equal DynamicJump , cal.class
|
|
|
|
end
|
2018-03-24 16:55:01 +01:00
|
|
|
#should end in exit, but doesn't, becasue resolve never returns
|
2018-04-09 14:06:46 +02:00
|
|
|
def test_sys
|
2018-04-19 21:57:31 +02:00
|
|
|
sys = main_ticks(119)
|
2018-03-24 16:55:01 +01:00
|
|
|
assert_equal Syscall , sys.class
|
|
|
|
end
|
2018-04-09 14:06:46 +02:00
|
|
|
def test_return
|
2018-04-19 21:57:31 +02:00
|
|
|
ret = main_ticks(117)
|
2018-03-24 16:55:01 +01:00
|
|
|
assert_equal FunctionReturn , ret.class
|
|
|
|
link = @interpreter.get_register( ret.register )
|
|
|
|
assert_equal Label , link.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|