2015-12-01 10:55:33 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
2017-01-11 18:18:04 +01:00
|
|
|
module Melon
|
|
|
|
class TestRubyHello < MiniTest::Test
|
|
|
|
include MelonTests
|
2017-01-17 20:27:20 +01:00
|
|
|
Branch = Register::Branch
|
|
|
|
Label = Register::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'
|
|
|
|
Register.machine.boot
|
|
|
|
# do_clean_compile
|
|
|
|
RubyCompiler.compile @string_input
|
|
|
|
Register::Collector.collect_space
|
|
|
|
@interpreter = Register::Interpreter.new
|
|
|
|
@interpreter.start Register.machine.init
|
|
|
|
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,
|
|
|
|
LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
RegisterTransfer, Syscall, RegisterTransfer, RegisterTransfer, RegToSlot,
|
|
|
|
Label, FunctionReturn, RegisterTransfer, SlotToReg, SlotToReg,
|
|
|
|
Label, FunctionReturn, RegisterTransfer, Syscall, NilClass]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_overflow
|
|
|
|
instruction = ticks( 24 )
|
|
|
|
assert_equal Register::FunctionCall , instruction.class
|
|
|
|
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
|