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:
Torsten Ruger 2018-08-07 20:48:36 +03:00
parent 554c2d3d73
commit c63e55c2bc
2 changed files with 16 additions and 1 deletions

View File

@ -116,6 +116,8 @@ module Risc
case right case right
when Parfait::Object , Symbol when Parfait::Object , Symbol
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self) 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 when RegisterValue
ins = Risc.transfer("#{right.type} to #{self.type}" , right , self) ins = Risc.transfer("#{right.type} to #{self.type}" , right , self)
when RValue when RValue
@ -137,11 +139,18 @@ module Risc
# generate a Function return instruction # generate a Function return instruction
# using the register as the parameter where the return address is passed # using the register as the parameter where the return address is passed
def function_return def function_return
ret = Risc::FunctionReturn.new("return", self) ret = Risc.function_return("return", self)
builder.add_code(ret) if builder builder.add_code(ret) if builder
ret ret
end 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) # 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

View File

@ -46,6 +46,12 @@ module Risc
assert_equal FunctionReturn , ret.class assert_equal FunctionReturn , ret.class
assert_equal @r0 , ret.register assert_equal @r0 , ret.register
end 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 def test_slot_to_reg
instr = @r0 << @r1[:next_message] instr = @r0 << @r1[:next_message]
assert_equal SlotToReg , instr.class assert_equal SlotToReg , instr.class