2015-07-17 12:21:57 +02:00
|
|
|
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)
|
2015-07-17 12:21:57 +02:00
|
|
|
raise "No block" unless to
|
2015-10-23 20:27:36 +02:00
|
|
|
@label = to
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|
2015-10-23 20:27:36 +02:00
|
|
|
attr_reader :label
|
2015-07-18 10:21:49 +02:00
|
|
|
|
|
|
|
def to_s
|
2015-10-23 20:27:36 +02:00
|
|
|
"#{self.class.name}: #{label.name}"
|
2015-07-18 10:21:49 +02:00
|
|
|
end
|
2015-10-19 13:46:12 +02:00
|
|
|
alias :inspect :to_s
|
2015-10-23 20:27:36 +02:00
|
|
|
|
|
|
|
def length labels = []
|
|
|
|
super(labels) + self.label.length(labels)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_ac labels = []
|
|
|
|
super(labels) + self.label.to_ac(labels)
|
|
|
|
end
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsZero < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsNotzero < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsMinus < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
2015-07-18 10:21:49 +02:00
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsPlus < Branch
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|
2015-07-18 10:21:49 +02:00
|
|
|
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|