add an operator function
to be able to use the builder more also add ability to load fixnums (for the int functions)
This commit is contained in:
parent
554c2d3d73
commit
c63e55c2bc
@ -116,6 +116,8 @@ module Risc
|
||||
case right
|
||||
when Parfait::Object , Symbol
|
||||
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
|
||||
when Fixnum
|
||||
ins = Risc.load_data("#{right.class} to #{self.type}" , right , self)
|
||||
when RegisterValue
|
||||
ins = Risc.transfer("#{right.type} to #{self.type}" , right , self)
|
||||
when RValue
|
||||
@ -137,11 +139,18 @@ module Risc
|
||||
# generate a Function return instruction
|
||||
# using the register as the parameter where the return address is passed
|
||||
def function_return
|
||||
ret = Risc::FunctionReturn.new("return", self)
|
||||
ret = Risc.function_return("return", self)
|
||||
builder.add_code(ret) if builder
|
||||
ret
|
||||
end
|
||||
|
||||
# create operator instruction for self and add
|
||||
# doesn't read quite as smoothly as one would like, but better than the compiler version
|
||||
def op( operator , right)
|
||||
ret = Risc.op( "operator #{operator}" , :>> , self , right)
|
||||
builder.add_code(ret) if builder
|
||||
ret
|
||||
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
|
||||
|
@ -46,6 +46,12 @@ module Risc
|
||||
assert_equal FunctionReturn , ret.class
|
||||
assert_equal @r0 , ret.register
|
||||
end
|
||||
def test_operator
|
||||
ret = @r0.op :<< , @r1
|
||||
assert_equal OperatorInstruction , ret.class
|
||||
assert_equal @r0 , ret.left
|
||||
assert_equal @r1 , ret.right
|
||||
end
|
||||
def test_slot_to_reg
|
||||
instr = @r0 << @r1[:next_message]
|
||||
assert_equal SlotToReg , instr.class
|
||||
|
Loading…
Reference in New Issue
Block a user