rubyx/lib/register/instructions/branch.rb

68 lines
1.4 KiB
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)
@label = to
end
attr_reader :label
2015-07-18 10:21:49 +02:00
def to_s
2016-12-28 20:10:14 +01:00
"#{self.class.name.split("::").last}: #{label ? label.name : ''}"
2015-07-18 10:21:49 +02:00
end
alias :inspect :to_s
def length labels = []
ret = super(labels)
ret += self.label.length(labels) if self.label
ret
end
2017-01-04 20:32:09 +01:00
def to_arr( labels = [] )
ret = super(labels)
2017-01-04 20:32:09 +01:00
ret += self.label.to_arr(labels) if self.label
ret
end
def total_byte_length labels = []
ret = super(labels)
ret += self.label.total_byte_length(labels) if self.label
#puts "#{self.class.name} return #{ret}"
ret
end
# labels have the same position as their next
def set_position position , labels = []
2016-12-28 20:40:06 +01:00
set_position self.label.set_position( position , labels ) if self.label
super(position,labels)
end
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
2015-10-25 11:03:31 +01:00
def each_label labels =[] , &block
super
self.label.each_label(labels , &block) if self.label
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