2018-03-24 16:55:01 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterDynamicCall < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = as_main("a = 15 ; return a.div10")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2018-04-04 19:05:09 +02:00
|
|
|
#show_main_ticks # get output of what is
|
|
|
|
check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, SlotToReg, LoadConstant, RegToSlot, LoadConstant,
|
2018-04-07 17:58:44 +02:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
SlotToReg, LoadConstant, FunctionCall, Label, SlotToReg,
|
2018-04-07 21:35:40 +02:00
|
|
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, Label,
|
|
|
|
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
|
|
|
OperatorInstruction, IsNotZero, Label, SlotToReg, Branch,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
SlotToReg, OperatorInstruction, IsNotZero, Label, SlotToReg,
|
|
|
|
Branch, Label, LoadConstant, SlotToReg, OperatorInstruction,
|
|
|
|
IsZero, SlotToReg, OperatorInstruction, IsNotZero, Label,
|
|
|
|
SlotToReg, Branch, Label, LoadConstant, SlotToReg,
|
|
|
|
OperatorInstruction, IsZero, SlotToReg, OperatorInstruction, IsNotZero,
|
|
|
|
Label, SlotToReg, Branch, Label, LoadConstant,
|
|
|
|
SlotToReg, OperatorInstruction, IsZero, SlotToReg, OperatorInstruction,
|
|
|
|
IsNotZero, Label, SlotToReg, Branch, Label,
|
|
|
|
LoadConstant, SlotToReg, OperatorInstruction, IsZero, SlotToReg,
|
|
|
|
OperatorInstruction, IsNotZero, Label, SlotToReg, Branch,
|
|
|
|
Label, LoadConstant, SlotToReg, OperatorInstruction, IsZero,
|
|
|
|
Label, Transfer, Syscall, NilClass]
|
2018-03-24 16:55:01 +01:00
|
|
|
#assert_equal 1 , get_return
|
|
|
|
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-03 11:55:28 +02:00
|
|
|
def test_call_resolve
|
2018-04-07 17:58:44 +02:00
|
|
|
call_ins = main_ticks(43)
|
2018-03-24 16:55:01 +01:00
|
|
|
assert_equal FunctionCall , call_ins.class
|
|
|
|
assert_equal :resolve_method , call_ins.method.name
|
|
|
|
end
|
2018-04-03 11:55:28 +02:00
|
|
|
def test_label
|
2018-04-07 17:58:44 +02:00
|
|
|
call_ins = main_ticks(44)
|
2018-03-24 16:55:01 +01:00
|
|
|
assert_equal Label , call_ins.class
|
|
|
|
assert_equal "Word_Type.resolve_method" , call_ins.name
|
|
|
|
end
|
2018-04-03 11:55:28 +02:00
|
|
|
def test_arg_15_to_resolve
|
2018-04-07 17:58:44 +02:00
|
|
|
sl = main_ticks( 47 )
|
2018-04-03 11:55:28 +02:00
|
|
|
assert_equal SlotToReg , sl.class
|
|
|
|
assert_equal :r2 , sl.array.symbol #load from message
|
|
|
|
assert_equal 2 , sl.index
|
|
|
|
assert_equal :r2 , sl.register.symbol
|
|
|
|
assert_equal Parfait::Integer, @interpreter.get_register( :r2 ).class
|
|
|
|
assert_equal 15, @interpreter.get_register( :r2 ).value
|
|
|
|
end
|
|
|
|
|
2018-04-02 15:36:43 +02:00
|
|
|
def est_dyn
|
2018-04-04 19:05:09 +02:00
|
|
|
cal = main_ticks(76)
|
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
|
|
|
|
def ttest_sys
|
|
|
|
sys = ticks(20)
|
|
|
|
assert_equal Syscall , sys.class
|
|
|
|
end
|
|
|
|
def ttest_return
|
|
|
|
ret = ticks(18)
|
|
|
|
assert_equal FunctionReturn , ret.class
|
|
|
|
link = @interpreter.get_register( ret.register )
|
|
|
|
assert_equal Label , link.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|