rubyx/test/risc/test_builder1.rb
Torsten Rüger 12b29285d7 Lots of preloading for tests
so many relied (implicitly( on some builtin function
after all can't do much in ruby without calling
Now all those dependencies are explicit
Small risc changes come because the macro version has a return label and unreachable label
2019-09-13 14:07:12 +03:00

48 lines
1.7 KiB
Ruby

require_relative "../helper"
module Risc
class TestCompilerBuilder < MiniTest::Test
include Parfait::MethodHelper
def setup
Parfait.boot!(Parfait.default_test_options)
@method = Mom::MomCollection.compiler_for( :Space , :main,{},{}).callable
@compiler = Risc::MethodCompiler.new( @method , Mom::Label.new( "source_name", "return_label"))
@builder = @compiler.builder(@method)
end
def test_inserts_built
r1 = RegisterValue.new(:r1 , :Space)
@builder.build{ space! << r1 }
assert_equal Transfer , @compiler.risc_instructions.next.class
assert_equal RegisterValue , @builder.space.class
end
def test_loads
@builder.build{ space! << Parfait.object_space }
assert_equal LoadConstant , @compiler.risc_instructions.next.class
assert_equal RegisterValue , @builder.space.class
end
def test_two
@builder.build{ space! << Parfait.object_space ; integer! << 1}
assert_equal LoadConstant , @compiler.risc_instructions.next.class
assert_equal LoadData , @compiler.risc_instructions.next(2).class
end
def test_swap
test_two
@builder.swap_names( :space , :integer)
assert_equal :Integer , @builder.space.type.class_name
assert_equal :Space , @builder.integer.type.class_name
end
def test_prepare_int
int = @builder.prepare_int_return
assert_raises { @builder.integer_tmp}
end
def test_allocate_returns
int = @builder.allocate_int
assert_equal :r1 , int.symbol
end
def test_allocate_len
int = @builder.allocate_int
assert_equal 23 , @builder.compiler.risc_instructions.length
end
end
end