Fix slot access for constants

Type access is allowed for any object, including constants.
Needed for parfait
This commit is contained in:
Torsten Rüger 2019-08-18 20:35:01 +03:00
parent 5a80850975
commit ee8927b059
4 changed files with 37 additions and 4 deletions

View File

@ -63,7 +63,11 @@ module Mom
parfait = known_object.to_parfait(compiler)
const = Risc.load_constant(source, parfait , right)
compiler.add_code const
raise "Can't have slots into Constants" if slots.length > 0
if slots.length == 1
raise "only type allowed for constants, not #{slots[0]}" unless slots[0] == :type
compiler.add_code Risc::SlotToReg.new( source , right , Parfait::TYPE_INDEX, right)
end
raise "Can't have slots into Constants #{slots}" if slots.length > 1
when Parfait::Object , Risc::Label
const = const = Risc.load_constant(source, known_object , right)
compiler.add_code const

View File

@ -12,7 +12,7 @@ module Mains
def self.Qemu
@Qemu
end
DEBUG = true
DEBUG = false
# runnable_methods is called by minitest to determine which tests to run
def self.runnable_methods
@ -37,7 +37,7 @@ module Mains
def self.has_qemu
if `uname -a`.include?("torsten")
@Linker = "arm-linux-gnu-ld"
#return false
return false
end
begin
`#{@Qemu} -version`

View File

@ -28,7 +28,9 @@ module Risc
end
def to_target
assert @expect , "No output given"
RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_target(as_test_main,:interpreter)
compiler = RubyX::RubyXCompiler.new(RubyX.default_test_options)
vool = compiler.ruby_to_vool(as_test_main)
compiler.to_target(:interpreter)
end
def produce_main
produce_target(:main)

View File

@ -23,4 +23,31 @@ module Mom
assert_equal "[StringConstant]" , @definition.to_s
end
end
class TestSlotDefinitionConstantType < MiniTest::Test
def setup
Parfait.boot!(Parfait.default_test_options)
@compiler = Risc::FakeCompiler.new
@definition = SlotDefinition.new(StringConstant.new("hi") , [:type])
@register = @definition.to_register(@compiler , InstructionMock.new)
@instruction = @compiler.instructions.first
end
def test_def_class
assert_equal Risc::LoadConstant , @instruction.class
end
def test_def_register
assert_equal :r1 , @instruction.register.symbol
end
def test_def_const
assert_equal "hi" , @instruction.constant.to_string
end
def test_to_s
assert_equal "[StringConstant, type]" , @definition.to_s
end
def test_def_register2
assert_equal :r1 , @compiler.instructions[1].register.symbol
end
def test_def_next_index
assert_equal 0 , @compiler.instructions[1].index
end
end
end