removed blocks and moved to labels
somewhat easier to understand the code as a linked list relatively painless change, considering
This commit is contained in:
@ -6,14 +6,22 @@ module Register
|
||||
def initialize source , to
|
||||
super(source)
|
||||
raise "No block" unless to
|
||||
@block = to
|
||||
@label = to
|
||||
end
|
||||
attr_reader :block
|
||||
attr_reader :label
|
||||
|
||||
def to_s
|
||||
"#{self.class.name}: #{block.name}"
|
||||
"#{self.class.name}: #{label.name}"
|
||||
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
|
||||
|
34
lib/register/instructions/label.rb
Normal file
34
lib/register/instructions/label.rb
Normal file
@ -0,0 +1,34 @@
|
||||
module Register
|
||||
|
||||
# A label is a placeholder for it's next Instruction
|
||||
# It's function is not to turn into code, but to be a valid brnch target
|
||||
#
|
||||
# So branches and Labels are pairs, fan out, fan in
|
||||
#
|
||||
#
|
||||
|
||||
class Label < Instruction
|
||||
def initialize source , name , nekst = nil
|
||||
super(source , nekst)
|
||||
@name = name
|
||||
end
|
||||
attr_reader :name
|
||||
|
||||
def to_s
|
||||
"Label: #{@name} (#{self.next.class})"
|
||||
end
|
||||
|
||||
def to_ac labels = []
|
||||
return [] if labels.include?(self)
|
||||
labels << self
|
||||
self.next.to_ac(labels)
|
||||
end
|
||||
|
||||
def length labels = []
|
||||
return 0 if labels.include?(self)
|
||||
labels << self
|
||||
1 + self.next.length(labels)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user