hello world in ruby works
doesnt do much dynamic things though
This commit is contained in:
parent
10d75e136f
commit
48d32a2b8e
@ -3,11 +3,41 @@ require_relative 'helper'
|
|||||||
module Melon
|
module Melon
|
||||||
class TestRubyHello < MiniTest::Test
|
class TestRubyHello < MiniTest::Test
|
||||||
include MelonTests
|
include MelonTests
|
||||||
|
Branch = Register::Branch
|
||||||
|
Label = Register::Label
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def test_ruby_hello
|
def test_ruby_hello
|
||||||
@string_input = in_Space 'def puts(str) ; str.putstring; end ; def main; putstring "Hello there"; end'
|
done = ticks(45)
|
||||||
assert !check
|
assert_equal NilClass , done.class
|
||||||
assert_equal "Hello there" , @interpreter.stdout
|
assert_equal "Hello there" , @interpreter.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,11 @@ require_relative '../helper'
|
|||||||
|
|
||||||
module Melon
|
module Melon
|
||||||
module CompilerHelper
|
module CompilerHelper
|
||||||
|
|
||||||
|
def in_Test(statements)
|
||||||
|
"class Test ; #{statements} ; end"
|
||||||
|
end
|
||||||
|
|
||||||
def in_Space(statements)
|
def in_Space(statements)
|
||||||
"class Space ; #{statements} ; end"
|
"class Space ; #{statements} ; end"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user