2018-04-06 13:21:38 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-04-06 19:55:21 +02:00
|
|
|
class TestBuilderBoot < MiniTest::Test
|
2018-04-06 13:54:24 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
Risc.machine.boot
|
|
|
|
init = Parfait.object_space.get_init
|
|
|
|
compiler = Risc::MethodCompiler.new( init )
|
|
|
|
@builder = Builder.new(compiler)
|
|
|
|
end
|
2018-04-06 21:54:54 +02:00
|
|
|
def test_alloc_space
|
2018-04-06 15:35:27 +02:00
|
|
|
reg = @builder.space
|
|
|
|
assert_equal RiscValue , reg.class
|
|
|
|
assert_equal :Space , reg.type
|
|
|
|
end
|
2018-04-06 21:54:54 +02:00
|
|
|
def test_next_message
|
|
|
|
reg = @builder.next_message
|
2018-04-06 15:35:27 +02:00
|
|
|
assert_equal :r1 , reg.symbol
|
|
|
|
assert_equal :Message , reg.type
|
|
|
|
end
|
2018-04-06 21:54:54 +02:00
|
|
|
def test_message
|
|
|
|
reg = @builder.message
|
|
|
|
assert_equal :r0 , reg.symbol
|
|
|
|
assert_equal :Message , reg.type
|
|
|
|
end
|
2018-04-06 15:35:27 +02:00
|
|
|
def test_returns_built
|
2018-04-06 13:54:24 +02:00
|
|
|
r1 = RiscValue.new(:r1 , :Space)
|
|
|
|
built = @builder.build{ space << r1 }
|
|
|
|
assert_equal Transfer , built.class
|
|
|
|
end
|
2018-04-06 15:35:27 +02:00
|
|
|
def test_returns_two
|
|
|
|
r1 = RiscValue.new(:r1 , :Space)
|
|
|
|
built = @builder.build{ space << r1 ; space << r1}
|
|
|
|
assert_equal Transfer , built.next.class
|
|
|
|
end
|
|
|
|
def test_returns_slot
|
|
|
|
r2 = RiscValue.new(:r2 , :Message)
|
2018-04-06 21:40:58 +02:00
|
|
|
r2.builder = @builder
|
|
|
|
built = @builder.build{ r2 << space[:first_message] }
|
2018-04-06 15:35:27 +02:00
|
|
|
assert_equal SlotToReg , built.class
|
|
|
|
assert_equal :r1 , built.array.symbol
|
2018-04-06 13:54:24 +02:00
|
|
|
end
|
2018-04-06 20:05:26 +02:00
|
|
|
def test_returns_slot_reverse
|
|
|
|
r2 = RiscValue.new(:r2 , :Message)
|
2018-04-06 21:40:58 +02:00
|
|
|
r2.builder = @builder
|
2018-04-06 20:05:26 +02:00
|
|
|
built = @builder.build{ r2 << space[:first_message] }
|
|
|
|
assert_equal SlotToReg , built.class
|
|
|
|
assert_equal :r1 , built.array.symbol
|
|
|
|
end
|
2018-04-06 19:55:21 +02:00
|
|
|
def test_reuses_names
|
|
|
|
r1 = RiscValue.new(:r1 , :Space)
|
|
|
|
built = @builder.build{ space << r1 ; space << r1}
|
|
|
|
assert_equal built.to.symbol , built.next.to.symbol
|
|
|
|
end
|
2018-04-06 21:54:54 +02:00
|
|
|
def test_uses_message_as_message
|
|
|
|
r1 = RiscValue.new(:r1 , :Space)
|
|
|
|
built = @builder.build{ message[:receiver] << r1}
|
|
|
|
assert_equal RegToSlot , built.class
|
|
|
|
assert_equal :r0 , built.array.symbol
|
|
|
|
end
|
2018-04-06 13:21:38 +02:00
|
|
|
end
|
2018-04-06 19:21:14 +02:00
|
|
|
|
|
|
|
class TestBuilderNoBoot < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@builder = Builder.new(nil)
|
|
|
|
end
|
|
|
|
def test_has_build
|
|
|
|
assert_nil @builder.build{ }
|
|
|
|
end
|
|
|
|
def test_has_attribute
|
|
|
|
assert_nil @builder.built
|
|
|
|
end
|
|
|
|
end
|
2018-04-06 13:21:38 +02:00
|
|
|
end
|