add operator to builder
just minus for now, easily extended
This commit is contained in:
parent
5d4b9d4834
commit
c30e461385
@ -69,11 +69,11 @@ module Risc
|
||||
space << Parfait.object_space
|
||||
space << space[:nil_object]
|
||||
|
||||
add Risc.op(source + "if method is nil", :- , space , typed_method )
|
||||
space - typed_method
|
||||
if_zero exit_label
|
||||
|
||||
name << typed_method[:name]
|
||||
add Risc.op(source + " compare name with me", :- , name , word )
|
||||
name - word
|
||||
if_not_zero false_label
|
||||
|
||||
typed_method << typed_method[:binary]
|
||||
|
@ -77,6 +77,13 @@ module Risc
|
||||
return ins
|
||||
end
|
||||
|
||||
def -( right )
|
||||
raise "operators only on registers, not #{right.class}" unless right.is_a? RiscValue
|
||||
op = Risc.op("#{self.type} - #{right.type}", :- , self , right )
|
||||
builder.add(op) if builder
|
||||
op
|
||||
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
|
||||
|
@ -90,5 +90,11 @@ module Risc
|
||||
assert_equal Branch , ret.class
|
||||
assert_equal @label , ret.label
|
||||
end
|
||||
def test_minus
|
||||
op = @builder.build {space - typed_method}
|
||||
assert_equal OperatorInstruction , op.class
|
||||
assert_equal :- , op.operator
|
||||
assert_equal :Space , op.left.type
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user