diff --git a/lib/risc/instructions/slot_to_reg.rb b/lib/risc/instructions/slot_to_reg.rb index 0ea8185b..2cb9decf 100644 --- a/lib/risc/instructions/slot_to_reg.rb +++ b/lib/risc/instructions/slot_to_reg.rb @@ -16,9 +16,12 @@ module Risc # Produce a SlotToReg instruction. # Array and to are registers # index may be a Symbol in which case is resolves with resolve_index. - def self.slot_to_reg( source , array , index , to) - raise "Not register #{array}" unless RegisterValue.look_like_reg(array) + def self.slot_to_reg( source , array , index ) + raise "Register #{array}" if RegisterValue.look_like_reg(array.symbol) index = array.resolve_index(index) if index.is_a?(Symbol) + type = array.type_at(index) + #puts "Slot for #{array.symbol}@ index #{index} is #{type}" + to = RegisterValue.new( "#{array.symbol}.#{type.to_s.downcase}".to_sym , type ) SlotToReg.new( source , array , index , to) end end diff --git a/test/risc/instructions/test_slot_to_reg.rb b/test/risc/instructions/test_slot_to_reg.rb new file mode 100644 index 00000000..3057a3f7 --- /dev/null +++ b/test/risc/instructions/test_slot_to_reg.rb @@ -0,0 +1,18 @@ +require_relative "../helper" + +module Risc + class TestSlotToReg < MiniTest::Test + def setup + Parfait.boot!({}) + end + def slot + Risc.slot_to_reg("source" , Risc.message_named_reg , :type) + end + def test_slot + assert_equal SlotToReg , slot.class + end + def test_slot_reg + assert_equal :"message.type" , slot.register.symbol + end + end +end diff --git a/test/risc/test_callable_compiler.rb b/test/risc/test_callable_compiler.rb index a9d357b9..02b7cbc8 100644 --- a/test/risc/test_callable_compiler.rb +++ b/test/risc/test_callable_compiler.rb @@ -29,9 +29,6 @@ module Risc def test_const assert_equal Array , @compiler.constants.class end - def test_use_reg - @compiler.use_reg(:Type) - end end class TestFakeCallableCompiler < MiniTest::Test def setup