implement [] for RiscValue for the dsl

This commit is contained in:
Torsten Ruger 2018-04-06 16:08:35 +03:00
parent 44d661fe56
commit c233bd82d6
4 changed files with 35 additions and 6 deletions

View File

@ -60,8 +60,11 @@ module Mom
def get_message_to( compiler , message) def get_message_to( compiler , message)
Risc.build(compiler) do Risc.build(compiler) do
space << Parfait.object_space space << Parfait.object_space
#message << space[:first_message]
#risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
end end
end
def nnop
space = compiler.use_reg(:Space) space = compiler.use_reg(:Space)
risc = Risc.load_constant("message setup move method" , Parfait.object_space ,space) risc = Risc.load_constant("message setup move method" , Parfait.object_space ,space)
risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message) risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)

View File

@ -22,17 +22,14 @@ module Risc
return built return built
end end
def add_instruction(ins) def add_instruction(ins)
if(built) if(@built)
built << ins @built << ins
else else
@built = ins @built = ins
end end
end end
end end
class RValue
end
def self.build(compiler, &block) def self.build(compiler, &block)
Builder.new(compiler).build( &block ) Builder.new(compiler).build( &block )
end end

View File

@ -58,6 +58,12 @@ module Risc
@symbol @symbol
end end
# can't overload "=" , so use shift for it.
# move the right side to the left. Left (this) is a RiscValue
# right value may be
# - constant (Parfait object) , resulting in a LoadConstant
# - another RiscValue, resulting in a Transfer instruction
# - an RValue, which gets procuced by the [] below
def <<( load ) def <<( load )
puts "LOAD #{load}" puts "LOAD #{load}"
case load case load
@ -73,6 +79,22 @@ module Risc
builder.add_instruction(ins) if builder builder.add_instruction(ins) if builder
return ins return ins
end end
# just capture the values in an intermediary object (RValue)
# The RValue then gets used in a RegToSlot ot SlotToReg, where
# the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg
def []( index )
RValue.new( self , index)
end
end
# Just a struct, see comment for [] of RiscValue
#
class RValue
attr_reader :register , :index
def initialize(register, index)
@register , @index = register , index
end
end end
# The register we use to store the current message object is :r0 # The register we use to store the current message object is :r0

View File

@ -33,5 +33,12 @@ module Risc
@r0 << @r1 @r0 << @r1
assert_equal Transfer , builder.built.class assert_equal Transfer , builder.built.class
end end
def test_index_op
message = @r0[:first_message]
assert_equal RValue , message.class
assert_equal :first_message , message.index
assert_equal @r0 , message.register
end
#message << space[:first_message]
end end
end end