2018-04-06 13:21:38 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
2018-04-06 13:54:24 +02:00
|
|
|
class FakeBuilder
|
|
|
|
attr_reader :built
|
2018-04-08 17:51:20 +02:00
|
|
|
def add_code(ins)
|
2018-04-06 13:54:24 +02:00
|
|
|
@built = ins
|
|
|
|
end
|
|
|
|
end
|
2018-04-06 13:21:38 +02:00
|
|
|
module Risc
|
|
|
|
class TestRegisterValue < MiniTest::Test
|
2018-04-06 13:54:24 +02:00
|
|
|
|
|
|
|
def setup
|
2018-06-30 18:20:17 +02:00
|
|
|
Parfait.boot!
|
2018-06-29 10:39:07 +02:00
|
|
|
@r0 = RegisterValue.new(:r0 , :Message)
|
|
|
|
@r1 = RegisterValue.new(:r1 , :Space)
|
2018-04-06 13:54:24 +02:00
|
|
|
end
|
|
|
|
def test_r0
|
|
|
|
assert_equal :r0 , @r0.symbol
|
|
|
|
end
|
|
|
|
def test_load_space
|
|
|
|
move = @r0 << Parfait.object_space
|
|
|
|
assert_equal LoadConstant , move.class
|
|
|
|
end
|
2018-04-08 21:30:18 +02:00
|
|
|
def test_load_symbol
|
|
|
|
move = @r1 << :puts
|
|
|
|
assert_equal LoadConstant , move.class
|
|
|
|
end
|
2018-04-06 13:54:24 +02:00
|
|
|
def test_transfer
|
|
|
|
transfer = @r0 << @r1
|
|
|
|
assert_equal Transfer , transfer.class
|
|
|
|
end
|
|
|
|
def test_calls_builder
|
|
|
|
builder = FakeBuilder.new
|
|
|
|
@r0.builder = builder
|
|
|
|
@r0 << @r1
|
|
|
|
assert_equal Transfer , builder.built.class
|
|
|
|
end
|
2018-04-06 15:08:35 +02:00
|
|
|
def test_index_op
|
2018-07-02 14:49:51 +02:00
|
|
|
message = @r0[:next_message]
|
2018-04-06 15:08:35 +02:00
|
|
|
assert_equal RValue , message.class
|
2018-07-02 14:49:51 +02:00
|
|
|
assert_equal :next_message , message.index
|
2018-04-06 15:08:35 +02:00
|
|
|
assert_equal @r0 , message.register
|
|
|
|
end
|
2018-04-06 15:35:27 +02:00
|
|
|
def test_slot_to_reg
|
2018-07-02 14:49:51 +02:00
|
|
|
instr = @r0 << @r1[:next_message]
|
2018-04-06 15:35:27 +02:00
|
|
|
assert_equal SlotToReg , instr.class
|
|
|
|
assert_equal @r1 , instr.array
|
|
|
|
assert_equal @r0 , instr.register
|
2018-05-14 14:17:04 +02:00
|
|
|
assert_equal 3 , instr.index
|
2018-04-06 15:35:27 +02:00
|
|
|
end
|
2018-04-06 19:21:14 +02:00
|
|
|
def test_reg_to_slot
|
2018-07-02 14:49:51 +02:00
|
|
|
instr = @r1[:next_message] << @r0
|
2018-04-06 19:21:14 +02:00
|
|
|
assert_equal RegToSlot , instr.class
|
|
|
|
assert_equal @r1 , instr.array
|
|
|
|
assert_equal @r0 , instr.register
|
2018-05-14 14:17:04 +02:00
|
|
|
assert_equal 3 , instr.index
|
2018-04-06 19:21:14 +02:00
|
|
|
end
|
2018-04-06 13:21:38 +02:00
|
|
|
end
|
|
|
|
end
|