rubyx/test/risc/interpreter/calling/test_puts.rb
Torsten ddd1f4e296 fix interpreter syscall and rename return reg
returned int for puts was same name as implicit return  int
2020-03-22 14:31:43 +02:00

65 lines
2.3 KiB
Ruby

require_relative "../helper"
module Risc
class TestPuts < MiniTest::Test
include Ticker
def setup
@preload = "Word.put"
@string_input = as_main(" return 'Hello again'.putstring ")
super
end
def test_chain
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
FunctionCall, LoadConstant, LoadConstant, SlotToReg, OperatorInstruction, #15
IsNotZero, SlotToReg, RegToSlot, RegToSlot, SlotToReg, #20
SlotToReg, Transfer, Transfer, Transfer, Syscall, #25
Transfer, Transfer, SlotToReg, Branch, RegToSlot, #30
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, #35
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #40
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #45
SlotToReg, SlotToReg, FunctionReturn, Transfer, SlotToReg, #50
SlotToReg, Transfer, Syscall, NilClass,] #55
assert_equal "Hello again" , @interpreter.stdout
assert_equal Integer , get_return.class
assert_equal 11 , get_return #bytes written
end
def test_call
cal = main_ticks(11)
assert_equal FunctionCall , cal.class
assert_equal :putstring , cal.method.name
end
def test_pre_sys
done = main_ticks(24)
assert_equal Parfait::Word , @interpreter.get_register(:r0).class
assert_equal "Hello again" , @interpreter.get_register(:r0).to_string
assert_equal 11 , @interpreter.get_register(:r1)
end
def test_sys
done = main_ticks(25)
assert_equal Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
assert_equal 11 , @interpreter.get_register(@interpreter.std_reg(:syscall_1))
end
def test_move_sys_return
assert_transfer(26, :r0 ,:r1)
assert_equal 11 , @interpreter.get_register(@interpreter.std_reg(:syscall_1))
end
def test_restore_message
assert_transfer(27, :r14 ,:r13)
assert_equal Parfait::Message , @interpreter.get_register(:r13).class
end
def test_return
done = main_ticks(48)
assert_equal FunctionReturn , done.class
end
end
end