reduce_int was overwriting register

No more. But the type question is open, ie what type does the resulting register have
This commit is contained in:
Torsten 2020-03-07 19:27:10 +02:00
parent 53eb28fff4
commit bd02f69824
3 changed files with 10 additions and 6 deletions

View File

@ -65,11 +65,14 @@ module Risc
end
# reduce integer to fixnum and add instruction if compiler is used
# TODO: checck type of self, should be integer
# TODO: check type of self, should be integer, and ensure it is
# TODO: find a type for the result, maybe fixnum , or data ?
# TODO also check types on reg_to_slot
def reduce_int
reduce = Risc::SlotToReg.new( "int -> fix" , self , Parfait::Integer.integer_index , self)
def reduce_int(check = true)
raise "type not int #{type.name}" if check && type.name != "Integer_Type"
new_name = "#{@symbol}.data_1"
new_reg = RegisterValue.new( new_name.to_sym , :Integer , extra)
reduce = Risc::SlotToReg.new( "int -> fix" , self , Parfait::Integer.integer_index , new_reg)
compiler.add_code(reduce) if compiler
reduce.register
end

View File

@ -8,7 +8,7 @@ module SlotMachine
integer_reg = builder.register( :integer_reg )
integer_const = builder.register( :integer_const )
builder.build do
integer_self = message[:receiver].to_reg.reduce_int
integer_self = message[:receiver].to_reg.reduce_int(false)
transfer( integer_self , integer_1)
transfer( integer_self , integer_reg)

View File

@ -8,6 +8,7 @@ module Risc
@compiler = Risc.test_compiler
@r0 = RegisterValue.new(:message , :Message).set_compiler(@compiler)
@r1 = RegisterValue.new(:id_1234 , :Space).set_compiler(@compiler)
@int = RegisterValue.new(:id_456 , :Integer).set_compiler(@compiler)
end
def test_resolves_index_ok
@ -17,11 +18,11 @@ module Risc
assert_raises {@r0.resolve_index(:something)}
end
def test_reduce_int
ins = @r0.reduce_int
ins = @int.reduce_int
assert_equal RegisterValue , ins.class
assert_equal SlotToReg , @compiler.current.class
assert_equal Parfait::Integer.integer_index , @compiler.current.index
assert_equal :message , ins.symbol
assert_equal :"id_456.data_1" , ins.symbol
end
def test_get_new_left_0
assert_equal RegisterValue , @r0.get_new_left(:caller , @compiler).class