start to test if

truth check is only half done
This commit is contained in:
Torsten Ruger 2018-03-19 21:20:11 +05:30
parent 63c1468e1e
commit c8980595a3
2 changed files with 39 additions and 8 deletions

View File

@ -1,11 +1,12 @@
module Risc
# a branch must branch to a block.
# A branch must branch to a label.
# Different Branches (derived classes) use different registers, the base
# just stores the Label
class Branch < Instruction
def initialize source , to
def initialize( source , label )
super(source)
@label = to
@label = label
end
attr_reader :label
@ -14,7 +15,7 @@ module Risc
end
alias :inspect :to_s
def length labels = []
def length( labels = [])
ret = super(labels)
ret += self.label.length(labels) if self.label
ret
@ -34,24 +35,31 @@ module Risc
end
# 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
super(position,labels)
end
def assemble_all io , labels = []
def assemble_all( io , labels = [])
self.assemble(io)
self.label.assemble_all(io,labels) if self.label
self.next.assemble_all(io, labels) if self.next
end
def each_label labels =[] , &block
def each_label( labels =[] , &block)
super
self.label.each_label(labels , &block) if self.label
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
end

View 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