start to test if
truth check is only half done
This commit is contained in:
parent
63c1468e1e
commit
c8980595a3
@ -1,11 +1,12 @@
|
|||||||
module Risc
|
module Risc
|
||||||
|
|
||||||
|
# A branch must branch to a label.
|
||||||
# a branch must branch to a block.
|
# Different Branches (derived classes) use different registers, the base
|
||||||
|
# just stores the Label
|
||||||
class Branch < Instruction
|
class Branch < Instruction
|
||||||
def initialize source , to
|
def initialize( source , label )
|
||||||
super(source)
|
super(source)
|
||||||
@label = to
|
@label = label
|
||||||
end
|
end
|
||||||
attr_reader :label
|
attr_reader :label
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
alias :inspect :to_s
|
alias :inspect :to_s
|
||||||
|
|
||||||
def length labels = []
|
def length( labels = [])
|
||||||
ret = super(labels)
|
ret = super(labels)
|
||||||
ret += self.label.length(labels) if self.label
|
ret += self.label.length(labels) if self.label
|
||||||
ret
|
ret
|
||||||
@ -34,24 +35,31 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# labels have the same position as their next
|
# labels have the same position as their next
|
||||||
def set_position position , labels = []
|
def set_position( position , labels = [])
|
||||||
set_position self.label.set_position( position , labels ) if self.label
|
set_position self.label.set_position( position , labels ) if self.label
|
||||||
super(position,labels)
|
super(position,labels)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_all io , labels = []
|
def assemble_all( io , labels = [])
|
||||||
self.assemble(io)
|
self.assemble(io)
|
||||||
self.label.assemble_all(io,labels) if self.label
|
self.label.assemble_all(io,labels) if self.label
|
||||||
self.next.assemble_all(io, labels) if self.next
|
self.next.assemble_all(io, labels) if self.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_label labels =[] , &block
|
def each_label( labels =[] , &block)
|
||||||
super
|
super
|
||||||
self.label.each_label(labels , &block) if self.label
|
self.label.each_label(labels , &block) if self.label
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# branch if two registers contain same value
|
||||||
|
class IsSame < Branch
|
||||||
|
attr_reader :left , :right
|
||||||
|
def initialize(source , left , right , label)
|
||||||
|
super(source , label)
|
||||||
|
end
|
||||||
|
end
|
||||||
class IsZero < Branch
|
class IsZero < Branch
|
||||||
end
|
end
|
||||||
|
|
||||||
|
23
test/mom/test_if_no_else.rb
Normal file
23
test/mom/test_if_no_else.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestIfNoElse < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "if(@a) ; arg = 5 ; end"
|
||||||
|
@expect = [SlotToReg, SlotToReg, LoadConstant, IsSame, Label, LoadConstant ,
|
||||||
|
SlotToReg, RegToSlot, Label]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_if_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def ttest_if_instructions
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal 5 , produced.class , produced
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user