remove all that label stuff
left over after rewrite from blocks to linked list
This commit is contained in:
parent
1e21177b35
commit
b24b65520d
@ -50,11 +50,16 @@ module Common
|
|||||||
end
|
end
|
||||||
alias :<< :append
|
alias :<< :append
|
||||||
|
|
||||||
def length( labels = [] )
|
def length
|
||||||
ret = 1
|
ret = 0
|
||||||
ret += self.next.length( labels ) if self.next
|
self.each { ret += 1}
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def each(&block)
|
||||||
|
block.call(self)
|
||||||
|
@next.each(&block) if @next
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
return unless add_object( object , depth )
|
return unless add_object( object , depth )
|
||||||
# probably should make labels or even instructions derive from Parfait::Object, but . .
|
# probably should make labels or even instructions derive from Parfait::Object, but . .
|
||||||
if object.is_a? Risc::Label
|
if object.is_a? Risc::Label
|
||||||
object.each_label { |l| self.add_object(l ,depth)}
|
object.each { |l| self.add_object(l ,depth) if l.is_a? Risc::Label}
|
||||||
end
|
end
|
||||||
return unless object.respond_to? :has_type?
|
return unless object.respond_to? :has_type?
|
||||||
type = object.get_type
|
type = object.get_type
|
||||||
|
@ -30,10 +30,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
|
|
||||||
#TODO check if this is used. Maybe build an each for instructions
|
def to_arr
|
||||||
def to_arr labels = []
|
ret = []
|
||||||
ret = [self.class]
|
self.each {|ins| ret << ins}
|
||||||
ret += self.next.to_arr(labels) if self.next
|
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,36 +45,31 @@ module Risc
|
|||||||
translator.translate( self )
|
translator.translate( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_all( io , labels = [] )
|
def assemble_all( io )
|
||||||
self.assemble(io)
|
self.assemble(io)
|
||||||
self.next.assemble_all(io, labels) if self.next
|
self.next.assemble_all(io) if self.next
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble io
|
def assemble io
|
||||||
raise "Abstract called on #{self}"
|
raise "Abstract called on #{self}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_byte_length( labels = [])
|
def total_byte_length
|
||||||
ret = self.byte_length
|
ret = 0
|
||||||
ret += self.next.total_byte_length(labels) if self.next
|
self.each{|ins| ret += ins.byte_length}
|
||||||
#puts "#{self.class.name} return #{ret}"
|
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_position position , labels = []
|
def set_position( position )
|
||||||
Positioned.set_position(self,position)
|
Positioned.set_position(self,position)
|
||||||
position += byte_length
|
position += byte_length
|
||||||
if self.next
|
if self.next
|
||||||
self.next.set_position(position , labels)
|
self.next.set_position( position )
|
||||||
else
|
else
|
||||||
position
|
position
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_label labels =[] , &block
|
|
||||||
self.next.each_label(labels , &block) if self.next
|
|
||||||
end
|
|
||||||
|
|
||||||
def class_source( derived)
|
def class_source( derived)
|
||||||
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
|
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
|
||||||
end
|
end
|
||||||
|
@ -15,42 +15,6 @@ module Risc
|
|||||||
end
|
end
|
||||||
alias :inspect :to_s
|
alias :inspect :to_s
|
||||||
|
|
||||||
def length( labels = [])
|
|
||||||
ret = super(labels)
|
|
||||||
ret += self.label.length(labels) if self.label
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_arr( labels = [] )
|
|
||||||
ret = super(labels)
|
|
||||||
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 = [])
|
|
||||||
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
|
|
||||||
|
|
||||||
def each_label( labels =[] , &block)
|
|
||||||
super
|
|
||||||
self.label.each_label(labels , &block) if self.label
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# dynamic version of an Unconditional branch that jumps to the contents
|
# dynamic version of an Unconditional branch that jumps to the contents
|
||||||
|
@ -31,43 +31,13 @@ module Risc
|
|||||||
@name.split(".").length == 2
|
@name.split(".").length == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_arr labels = []
|
|
||||||
return [] if labels.include?(self)
|
|
||||||
labels << self
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def length labels = []
|
|
||||||
return 0 if labels.include?(self)
|
|
||||||
labels << self
|
|
||||||
ret = 1
|
|
||||||
ret += self.next.length(labels) if self.next
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def assemble io
|
def assemble io
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_all io , labels = []
|
|
||||||
return if labels.include?(self) or self.next.nil?
|
|
||||||
labels << self
|
|
||||||
self.next.assemble_all(io,labels)
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_byte_length labels = []
|
|
||||||
return 0 if labels.include?(self) or self.next.nil?
|
|
||||||
labels << self
|
|
||||||
ret = self.next.total_byte_length(labels)
|
|
||||||
#puts "#{self.class.name} return #{ret}"
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
# labels have the same position as their next
|
# labels have the same position as their next
|
||||||
def set_position position , labels = []
|
def set_position( position )
|
||||||
return position if labels.include?(self)
|
super(position)
|
||||||
labels << self
|
self.next.set_position(position) if self.next
|
||||||
super(position , labels)
|
|
||||||
self.next.set_position(position,labels) if self.next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# shame we need this, just for logging
|
# shame we need this, just for logging
|
||||||
@ -75,12 +45,6 @@ module Risc
|
|||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_label labels =[] , &block
|
|
||||||
return if labels.include?(self)
|
|
||||||
labels << self
|
|
||||||
block.yield(self)
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.label( source , name , nekst = nil)
|
def self.label( source , name , nekst = nil)
|
||||||
|
@ -61,20 +61,6 @@ module Risc
|
|||||||
assert_equal @label, @instruction.next
|
assert_equal @label, @instruction.next
|
||||||
assert_equal 2 , @instruction.length , @instruction.to_arr
|
assert_equal 2 , @instruction.length , @instruction.to_arr
|
||||||
end
|
end
|
||||||
def test_each_label1
|
|
||||||
@instruction.set_next @label
|
|
||||||
start = Label.new("test" , "test" , @instruction)
|
|
||||||
count = 0
|
|
||||||
start.each_label { |l| count += 1 }
|
|
||||||
assert_equal 2 , count
|
|
||||||
end
|
|
||||||
def test_each_label2
|
|
||||||
@instruction.set_next @branch
|
|
||||||
start = Label.new("test" , "test" , @instruction)
|
|
||||||
count = 0
|
|
||||||
start.each_label { |l| count += 1 }
|
|
||||||
assert_equal 2 , count
|
|
||||||
end
|
|
||||||
def test_label_is_method
|
def test_label_is_method
|
||||||
label = Label.new("test" , "Object.test")
|
label = Label.new("test" , "Object.test")
|
||||||
assert label.is_method
|
assert label.is_method
|
||||||
|
Loading…
Reference in New Issue
Block a user