rubyx/lib/register/instructions/branch.rb

40 lines
611 B
Ruby
Raw Normal View History

module Register
# a branch must branch to a block.
class Branch < Instruction
2015-07-18 10:21:49 +02:00
def initialize source , to
super(source)
raise "No block" unless to
@label = to
end
attr_reader :label
2015-07-18 10:21:49 +02:00
def to_s
"#{self.class.name}: #{label.name}"
2015-07-18 10:21:49 +02:00
end
alias :inspect :to_s
def length labels = []
super(labels) + self.label.length(labels)
end
def to_ac labels = []
super(labels) + self.label.to_ac(labels)
end
end
class IsZero < Branch
end
class IsNotzero < Branch
end
class IsMinus < Branch
end
2015-07-18 10:21:49 +02:00
class IsPlus < Branch
end
2015-07-18 10:21:49 +02:00
end