SA for slot_to_reg

This commit is contained in:
Torsten 2020-02-29 17:18:27 +02:00
parent 77003eed06
commit d22da1ab97
3 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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