implement [] for RiscValue for the dsl
This commit is contained in:
parent
44d661fe56
commit
c233bd82d6
@ -60,8 +60,11 @@ module Mom
|
||||
def get_message_to( compiler , message)
|
||||
Risc.build(compiler) do
|
||||
space << Parfait.object_space
|
||||
#message << space[:first_message]
|
||||
#risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
|
||||
end
|
||||
|
||||
end
|
||||
def nnop
|
||||
space = compiler.use_reg(: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)
|
||||
|
@ -22,17 +22,14 @@ module Risc
|
||||
return built
|
||||
end
|
||||
def add_instruction(ins)
|
||||
if(built)
|
||||
built << ins
|
||||
if(@built)
|
||||
@built << ins
|
||||
else
|
||||
@built = ins
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class RValue
|
||||
end
|
||||
|
||||
def self.build(compiler, &block)
|
||||
Builder.new(compiler).build( &block )
|
||||
end
|
||||
|
@ -58,6 +58,12 @@ module Risc
|
||||
@symbol
|
||||
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 )
|
||||
puts "LOAD #{load}"
|
||||
case load
|
||||
@ -73,6 +79,22 @@ module Risc
|
||||
builder.add_instruction(ins) if builder
|
||||
return ins
|
||||
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
|
||||
|
||||
# The register we use to store the current message object is :r0
|
||||
|
@ -33,5 +33,12 @@ module Risc
|
||||
@r0 << @r1
|
||||
assert_equal Transfer , builder.built.class
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user