2015-12-01 10:55:33 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2017-01-17 23:05:36 +01:00
|
|
|
module Rubyx
|
2017-08-31 15:18:59 +02:00
|
|
|
class TestRubyHello #< MiniTest::Test
|
2017-01-17 23:05:36 +01:00
|
|
|
include RubyxTests
|
2017-01-19 08:02:29 +01:00
|
|
|
Branch = Risc::Branch
|
|
|
|
Label = Risc::Label
|
2015-12-01 10:55:33 +01:00
|
|
|
|
2017-01-17 20:27:20 +01:00
|
|
|
def setup
|
|
|
|
@string_input = as_main '"Hello there".putstring'
|
2017-01-19 08:02:29 +01:00
|
|
|
Risc.machine.boot
|
2017-01-17 20:27:20 +01:00
|
|
|
# do_clean_compile
|
2017-08-31 13:18:12 +02:00
|
|
|
RubyxCompiler.compile @string_input
|
2017-01-19 08:02:29 +01:00
|
|
|
Risc::Collector.collect_space
|
|
|
|
@interpreter = Risc::Interpreter.new
|
|
|
|
@interpreter.start Risc.machine.init
|
2017-01-17 20:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
|
|
|
#show_ticks
|
|
|
|
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, LoadConstant, RegToSlot,
|
|
|
|
LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
2017-01-19 08:02:29 +01:00
|
|
|
LoadConstant, RegToSlot, RiscTransfer, FunctionCall, Label,
|
2017-01-17 20:27:20 +01:00
|
|
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2017-01-19 08:02:29 +01:00
|
|
|
RiscTransfer, Syscall, RiscTransfer, RiscTransfer, RegToSlot,
|
|
|
|
Label, FunctionReturn, RiscTransfer, SlotToReg, SlotToReg,
|
|
|
|
Label, FunctionReturn, RiscTransfer, Syscall, NilClass]
|
2017-01-17 20:27:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_overflow
|
|
|
|
instruction = ticks( 24 )
|
2017-01-19 08:02:29 +01:00
|
|
|
assert_equal Risc::FunctionCall , instruction.class
|
2017-01-17 20:27:20 +01:00
|
|
|
assert_equal :putstring , instruction.method.name
|
|
|
|
end
|
2015-12-01 10:55:33 +01:00
|
|
|
|
2017-01-11 18:18:04 +01:00
|
|
|
def test_ruby_hello
|
2017-01-17 20:27:20 +01:00
|
|
|
done = ticks(45)
|
|
|
|
assert_equal NilClass , done.class
|
2017-01-15 19:30:47 +01:00
|
|
|
assert_equal "Hello there" , @interpreter.stdout
|
2017-01-11 18:18:04 +01:00
|
|
|
end
|
|
|
|
|
2015-12-01 10:55:33 +01:00
|
|
|
end
|
|
|
|
end
|