2015-10-22 14:34:47 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2017-01-03 21:42:40 +01:00
|
|
|
class IfCalledTest < MiniTest::Test
|
|
|
|
include Ticker
|
2017-04-10 15:12:15 +02:00
|
|
|
include CleanCompile
|
2015-10-22 14:34:47 +02:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
def setup
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Space
|
|
|
|
int itest(int n)
|
|
|
|
if_zero( n - 12)
|
|
|
|
"then".putstring()
|
|
|
|
else
|
|
|
|
"else".putstring()
|
|
|
|
end
|
2015-10-22 14:34:47 +02:00
|
|
|
end
|
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
int main()
|
|
|
|
itest(20)
|
|
|
|
end
|
2015-10-22 14:34:47 +02:00
|
|
|
end
|
|
|
|
HERE
|
2017-01-16 08:34:47 +01:00
|
|
|
@input = s(:statements, s(:call, :itest , s(:arguments, s(:int, 20))))
|
2017-01-03 21:42:40 +01:00
|
|
|
super
|
|
|
|
end
|
2015-11-08 13:30:28 +01:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
# must be after boot, but before main compile, to define method
|
|
|
|
def do_clean_compile
|
|
|
|
clean_compile :Space , :itest , {:n => :Integer} ,
|
2017-01-16 08:34:47 +01:00
|
|
|
s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:arg, :n), s(:int, 12))),
|
|
|
|
s(:true_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "then")))),
|
|
|
|
s(:false_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "else"))))))
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2018-03-11 12:32:42 +01:00
|
|
|
def pest_if
|
2017-01-03 21:42:40 +01:00
|
|
|
#show_ticks # get output of what is
|
2017-01-04 20:36:46 +01:00
|
|
|
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, RegToSlot, FunctionCall, Label, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
2017-01-19 08:02:29 +01:00
|
|
|
LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label,
|
2017-01-04 20:36:46 +01:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
LoadConstant, OperatorInstruction, IsZero, SlotToReg, LoadConstant,
|
|
|
|
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg,
|
2017-01-19 08:02:29 +01:00
|
|
|
RegToSlot, LoadConstant, RegToSlot, RiscTransfer, FunctionCall,
|
2017-01-04 20:36:46 +01:00
|
|
|
Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
2017-01-19 08:02:29 +01:00
|
|
|
SlotToReg, RiscTransfer, Syscall, RiscTransfer, RiscTransfer,
|
|
|
|
RegToSlot, Label, FunctionReturn, RiscTransfer, SlotToReg,
|
2017-01-04 20:36:46 +01:00
|
|
|
SlotToReg, Branch, Label, Label, FunctionReturn,
|
2017-01-19 08:02:29 +01:00
|
|
|
RiscTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, Label, FunctionReturn, RiscTransfer, Syscall,
|
2017-01-04 20:36:46 +01:00
|
|
|
NilClass]
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2015-10-22 14:34:47 +02:00
|
|
|
end
|
|
|
|
end
|