fix unconditional jump
and affected tests
This commit is contained in:
parent
c12830ee6d
commit
77084dc894
@ -21,7 +21,7 @@ module Mom
|
||||
# The argument that is passed is a MethodCompiler, which has the method and some
|
||||
# state about registers used. (also provides helpers to generate risc instructions)
|
||||
def to_risc(compiler)
|
||||
raise Risc::Label.new(self.class.name, self.class.name + "_todo")
|
||||
raise self.class.name + "_todo"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
module Mom
|
||||
|
||||
# unconditional jump to the instruction given as target
|
||||
# Unconditional jump to the Label given as target
|
||||
# Eg used at the end of while or end of if_true branch
|
||||
#
|
||||
# Risc equivalent is the same really, called Unconditional there.
|
||||
#
|
||||
class Jump < Instruction
|
||||
attr_reader :target
|
||||
@ -8,8 +11,8 @@ module Mom
|
||||
def initialize(target)
|
||||
@target = target
|
||||
end
|
||||
def to_risc(context)
|
||||
Risc::Label.new(self,"Jump")
|
||||
def to_risc(compiler)
|
||||
Risc::Unconditional.new(self , @target.to_risc(compiler))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,6 +60,11 @@ module Risc
|
||||
super(source , label)
|
||||
end
|
||||
end
|
||||
|
||||
class Unconditional < Branch
|
||||
|
||||
end
|
||||
|
||||
class IsZero < Branch
|
||||
end
|
||||
|
||||
|
@ -8,7 +8,7 @@ module Risc
|
||||
super
|
||||
@input = "if(@a) ; arg = 5 ; else; arg = 6; end"
|
||||
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, LoadConstant, IsSame ,
|
||||
Label, LoadConstant, SlotToReg, RegToSlot, Label, Label ,
|
||||
Label, LoadConstant, SlotToReg, RegToSlot, Unconditional, Label ,
|
||||
LoadConstant, SlotToReg, RegToSlot, Label]
|
||||
end
|
||||
|
||||
@ -45,7 +45,7 @@ module Risc
|
||||
|
||||
def test_true_jump # should jumpp to merge label
|
||||
produced = produce_body
|
||||
assert_equal "Jump" , produced.next(10).name
|
||||
assert produced.next(10).label.name.start_with?("merge_label")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ module Risc
|
||||
super
|
||||
@input = "while(@a) ; arg = 5 end"
|
||||
@expect = [Label, SlotToReg, SlotToReg, LoadConstant, IsSame, LoadConstant ,
|
||||
IsSame, LoadConstant, SlotToReg, RegToSlot, Label, Label]
|
||||
IsSame, LoadConstant, SlotToReg, RegToSlot, Unconditional, Label]
|
||||
end
|
||||
|
||||
def test_while_instructions
|
||||
@ -37,9 +37,9 @@ module Risc
|
||||
assert produced.next(11).name.start_with?("merge_label")
|
||||
end
|
||||
|
||||
def test_true_jump # should jumpp to merge label
|
||||
def test_back_jump # should jump back to condition label
|
||||
produced = produce_body
|
||||
assert_equal "Jump" , produced.next(10).name
|
||||
assert_equal produced , produced.next(10).label
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user