rubyx/test/risc/test_register_value1.rb
Torsten 0ce14bdfd1 moving to SA register names (wip)
starting to implement register allocation by first creating SA
Single Assignment means a register is only every assigned a value once. Hence for any operation involving another register, a new register is created.
We do this with a naming scheme for the registers in dot notation (as it would be in c) which means 2 registers with the same name, should have the same contents. This does not apply to temporaries, but that is another day.
Starting WIP now, and will create many red commits before merging when green.
2020-03-22 14:31:43 +02:00

46 lines
1.5 KiB
Ruby

require_relative "../helper"
module Risc
class TestRegisterValue1 < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
@r0 = RegisterValue.new(:message , :Message)
@r1 = RegisterValue.new(:id_1234 , :Space)
@compiler = Risc.test_compiler
end
def test_resolves_index_ok
assert_equal 6 , @r0.resolve_index(:caller)
end
def test_resolves_index_fail
assert_raises {@r0.resolve_index(:something)}
end
def test_reduce_int
ins = @r0.reduce_int
assert_equal SlotToReg , ins.class
assert_equal Parfait::Integer.integer_index , ins.index
end
def test_get_new_left_0
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
end
def test_get_new_left_no_extra
assert @r0.get_new_left(:caller , @compiler).extra.empty?
end
def test_get_new_left_0_reg
assert_equal :"message.caller" , @r0.get_new_left(:caller , @compiler).symbol
end
def test_get_new_left_1
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class
end
def test_get_new_left_1_reg
assert_equal :"id_1234.classes" , @r1.get_new_left(:classes , @compiler).symbol
end
def test_get_left_uses_extra
@r1 = RegisterValue.new(:message , :Space , type_arguments: @r0.type)
# works with nil as compiler, because extra is used
assert_equal :Message , @r1.get_new_left(:arguments , nil).type.class_name
end
end
end