remove >>, consistent use of <<
makes code easier to read, like assignments does remind of Passengers
This commit is contained in:
parent
c042dd9faa
commit
22409c93ee
@ -30,16 +30,8 @@ module Mom
|
|||||||
builder = Risc::Builder.new(compiler)
|
builder = Risc::Builder.new(compiler)
|
||||||
from = method_source
|
from = method_source
|
||||||
risc = builder.build { typed_method << from }
|
risc = builder.build { typed_method << from }
|
||||||
get_message_to(builder)
|
build_message_data(builder)
|
||||||
|
compiler.reset_regs
|
||||||
# move name args frame
|
|
||||||
# this time using Risc instructions (create helpers?)
|
|
||||||
name_move = SlotLoad.new( [:message , :next_message,:name] , [method_source , :name],self)
|
|
||||||
moves = name_move.to_risc(compiler)
|
|
||||||
args_move = SlotLoad.new( [:message , :next_message, :arguments, :type] , [method_source , :arguments_type],self)
|
|
||||||
moves << args_move.to_risc(compiler)
|
|
||||||
type_move = SlotLoad.new( [:message , :next_message, :frame, :type] , [method_source , :frame_type],self)
|
|
||||||
moves << type_move.to_risc(compiler)
|
|
||||||
return risc
|
return risc
|
||||||
end
|
end
|
||||||
private
|
private
|
||||||
@ -49,24 +41,28 @@ module Mom
|
|||||||
|
|
||||||
# get the next message from space and unlink it there
|
# get the next message from space and unlink it there
|
||||||
# also put it into next_message of current message
|
# also put it into next_message of current message
|
||||||
# use given message register
|
def build_message_data( builder )
|
||||||
# return instructions to do this
|
|
||||||
def get_message_to( builder )
|
|
||||||
builder.build do
|
builder.build do
|
||||||
space << Parfait.object_space
|
space << Parfait.object_space
|
||||||
next_message << space[:first_message]
|
next_message << space[:first_message]
|
||||||
|
message[:next_message] << next_message
|
||||||
|
next_message[:caller] << message
|
||||||
|
|
||||||
|
named_list << next_message[:arguments]
|
||||||
|
type << typed_method[:arguments_type]
|
||||||
|
named_list[:type] << type
|
||||||
|
|
||||||
|
named_list << next_message[:frame]
|
||||||
|
type << typed_method[:arguments_type]
|
||||||
|
named_list[:type] << type
|
||||||
|
|
||||||
|
name << typed_method[:arguments_type]
|
||||||
|
named_list[:type] << name
|
||||||
|
|
||||||
|
#store next.next back into space
|
||||||
|
next_message << next_message[:next_message]
|
||||||
|
space[:first_message] << next_message
|
||||||
end
|
end
|
||||||
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)
|
|
||||||
next_message = compiler.use_reg( :Message )
|
|
||||||
risc << Risc.slot_to_reg(source + "get next message" , message , :next_message , next_message)
|
|
||||||
risc << Risc.reg_to_slot(source + "store next message" , next_message , space , :first_message)
|
|
||||||
risc << Risc.reg_to_slot(source + "store message in current" , message , :message , :next_message)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,7 @@ module Risc
|
|||||||
reg.builder = self
|
reg.builder = self
|
||||||
reg
|
reg
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(&block)
|
def build(&block)
|
||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
return built
|
return built
|
||||||
@ -58,8 +58,8 @@ module Risc
|
|||||||
def self.resolve_type( object , compiler )
|
def self.resolve_type( object , compiler )
|
||||||
object = object.type if object.is_a?(RiscValue)
|
object = object.type if object.is_a?(RiscValue)
|
||||||
case object
|
case object
|
||||||
when :typed_method
|
when :name
|
||||||
type = Parfait.object_space.get_class_by_name( :TypedMethod ).instance_type
|
type = Parfait.object_space.get_class_by_name( :Word ).instance_type
|
||||||
when :frame
|
when :frame
|
||||||
type = compiler.method.frame_type
|
type = compiler.method.frame_type
|
||||||
when :message , :next_message , :caller
|
when :message , :next_message , :caller
|
||||||
|
@ -61,15 +61,15 @@ module Risc
|
|||||||
# right value may be
|
# right value may be
|
||||||
# - constant (Parfait object) , resulting in a LoadConstant
|
# - constant (Parfait object) , resulting in a LoadConstant
|
||||||
# - another RiscValue, resulting in a Transfer instruction
|
# - another RiscValue, resulting in a Transfer instruction
|
||||||
# - an RValue, which gets procuced by the [] below
|
# - an RValue, resulting in an SlotToReg
|
||||||
def <<( load )
|
def <<( right )
|
||||||
case load
|
case right
|
||||||
when Parfait::Object
|
when Parfait::Object
|
||||||
ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self)
|
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
|
||||||
when RiscValue
|
when RiscValue
|
||||||
ins = Risc.transfer("#{load.type} to #{self.type}" , load , self)
|
ins = Risc.transfer("#{right.type} to #{self.type}" , right , self)
|
||||||
when RValue
|
when RValue
|
||||||
load >> self
|
ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self)
|
||||||
else
|
else
|
||||||
raise "not implemented"
|
raise "not implemented"
|
||||||
end
|
end
|
||||||
@ -77,14 +77,6 @@ module Risc
|
|||||||
return ins
|
return ins
|
||||||
end
|
end
|
||||||
|
|
||||||
# create a RegToSlot instruction
|
|
||||||
# right hand must be an RValue
|
|
||||||
def >>( slot )
|
|
||||||
raise "not RValue #{slot}" unless slot.is_a?(RValue)
|
|
||||||
reg_to_slot = Risc.reg_to_slot("#{self.type} -> #{slot.register.type}[#{slot.index}]" , self, slot.register, slot.index)
|
|
||||||
builder.add_instruction(reg_to_slot) if builder
|
|
||||||
reg_to_slot
|
|
||||||
end
|
|
||||||
# just capture the values in an intermediary object (RValue)
|
# just capture the values in an intermediary object (RValue)
|
||||||
# The RValue then gets used in a RegToSlot ot SlotToReg, where
|
# 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
|
# the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg
|
||||||
@ -101,14 +93,15 @@ module Risc
|
|||||||
@register , @index , @builder = register , index , builder
|
@register , @index , @builder = register , index , builder
|
||||||
end
|
end
|
||||||
|
|
||||||
# fullfil the objects purpose by creating a SlotToReg instruction from
|
# fullfil the objects purpose by creating a RegToSlot instruction from
|
||||||
# itself (the slot) and the register given
|
# itself (the slot) and the register given
|
||||||
def >>( reg )
|
def <<( reg )
|
||||||
raise "not reg #{reg}" unless reg.is_a?(RiscValue)
|
raise "not reg #{reg}" unless reg.is_a?(RiscValue)
|
||||||
slot = Risc.slot_to_reg("#{register.type}[#{index}] -> #{reg.type}" , @register , @index , reg)
|
reg_to_slot = Risc.reg_to_slot("#{reg.type} -> #{register.type}[#{index}]" , reg , register, index)
|
||||||
builder.add_instruction(slot) if builder
|
builder.add_instruction(reg_to_slot) if builder
|
||||||
slot
|
reg_to_slot
|
||||||
end
|
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
|
||||||
|
@ -31,12 +31,14 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_returns_slot
|
def test_returns_slot
|
||||||
r2 = RiscValue.new(:r2 , :Message)
|
r2 = RiscValue.new(:r2 , :Message)
|
||||||
built = @builder.build{ space[:first_message] >> r2 }
|
r2.builder = @builder
|
||||||
|
built = @builder.build{ r2 << space[:first_message] }
|
||||||
assert_equal SlotToReg , built.class
|
assert_equal SlotToReg , built.class
|
||||||
assert_equal :r1 , built.array.symbol
|
assert_equal :r1 , built.array.symbol
|
||||||
end
|
end
|
||||||
def test_returns_slot_reverse
|
def test_returns_slot_reverse
|
||||||
r2 = RiscValue.new(:r2 , :Message)
|
r2 = RiscValue.new(:r2 , :Message)
|
||||||
|
r2.builder = @builder
|
||||||
built = @builder.build{ r2 << space[:first_message] }
|
built = @builder.build{ r2 << space[:first_message] }
|
||||||
assert_equal SlotToReg , built.class
|
assert_equal SlotToReg , built.class
|
||||||
assert_equal :r1 , built.array.symbol
|
assert_equal :r1 , built.array.symbol
|
||||||
|
@ -38,14 +38,14 @@ module Risc
|
|||||||
assert_equal @r0 , message.register
|
assert_equal @r0 , message.register
|
||||||
end
|
end
|
||||||
def test_slot_to_reg
|
def test_slot_to_reg
|
||||||
instr = @r1[:first_message] >> @r0
|
instr = @r0 << @r1[:first_message]
|
||||||
assert_equal SlotToReg , instr.class
|
assert_equal SlotToReg , instr.class
|
||||||
assert_equal @r1 , instr.array
|
assert_equal @r1 , instr.array
|
||||||
assert_equal @r0 , instr.register
|
assert_equal @r0 , instr.register
|
||||||
assert_equal 4 , instr.index
|
assert_equal 4 , instr.index
|
||||||
end
|
end
|
||||||
def test_reg_to_slot
|
def test_reg_to_slot
|
||||||
instr = @r0 >> @r1[:first_message]
|
instr = @r1[:first_message] << @r0
|
||||||
assert_equal RegToSlot , instr.class
|
assert_equal RegToSlot , instr.class
|
||||||
assert_equal @r1 , instr.array
|
assert_equal @r1 , instr.array
|
||||||
assert_equal @r0 , instr.register
|
assert_equal @r0 , instr.register
|
||||||
|
Loading…
Reference in New Issue
Block a user