add shortcut for class_name

for when type is not set
This commit is contained in:
Torsten Ruger 2018-08-08 12:02:59 +03:00
parent 71a7161200
commit 6200a35562
2 changed files with 12 additions and 2 deletions

View File

@ -30,6 +30,10 @@ module Risc
@extra = extra
end
def class_name
return :fixnum unless @type
@type.class_name
end
# using the registers type, resolve the slot to an index
# Using the index and the register, add a SlotToReg to the instruction
def resolve_and_add(slot , instruction , compiler)
@ -66,7 +70,7 @@ module Risc
end
def to_s
s = "#{symbol}:#{type&.class_name}"
s = "#{symbol}:#{class_name}"
s += ":#{extra}" unless extra.empty?
s
end
@ -171,7 +175,7 @@ module Risc
# itself (the slot) and the register given
def <<( reg )
raise "not reg #{reg}" unless reg.is_a?(RegisterValue)
reg_to_slot = Risc.reg_to_slot("#{reg.type.class_name} -> #{register.type.class_name}[#{index}]" , reg , register, index)
reg_to_slot = Risc.reg_to_slot("#{reg.class_name} -> #{register.class_name}[#{index}]" , reg , register, index)
builder.add_code(reg_to_slot) if builder
reg_to_slot
end

View File

@ -14,6 +14,12 @@ module Risc
@r0 = RegisterValue.new(:r0 , :Message)
@r1 = RegisterValue.new(:r1 , :Space)
end
def test_class_name_type
assert_equal :Message , @r0.class_name
end
def test_class_name_fix
assert_equal :fixnum , RegisterValue.new(:r0 , :fixnum).class_name
end
def test_r0
assert_equal :r0 , @r0.symbol
end