remove all that label stuff

left over after rewrite from blocks to linked list
This commit is contained in:
Torsten Ruger 2018-03-26 14:54:41 +03:00
parent 1e21177b35
commit b24b65520d
6 changed files with 22 additions and 109 deletions

View File

@ -50,11 +50,16 @@ module Common
end
alias :<< :append
def length( labels = [] )
ret = 1
ret += self.next.length( labels ) if self.next
def length
ret = 0
self.each { ret += 1}
ret
end
def each(&block)
block.call(self)
@next.each(&block) if @next
end
end
end

View File

@ -14,7 +14,7 @@ module Risc
return unless add_object( object , depth )
# probably should make labels or even instructions derive from Parfait::Object, but . .
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
return unless object.respond_to? :has_type?
type = object.get_type

View File

@ -30,10 +30,9 @@ module Risc
end
attr_reader :source
#TODO check if this is used. Maybe build an each for instructions
def to_arr labels = []
ret = [self.class]
ret += self.next.to_arr(labels) if self.next
def to_arr
ret = []
self.each {|ins| ret << ins}
ret
end
@ -46,36 +45,31 @@ module Risc
translator.translate( self )
end
def assemble_all( io , labels = [] )
def assemble_all( io )
self.assemble(io)
self.next.assemble_all(io, labels) if self.next
self.next.assemble_all(io) if self.next
end
def assemble io
raise "Abstract called on #{self}"
end
def total_byte_length( labels = [])
ret = self.byte_length
ret += self.next.total_byte_length(labels) if self.next
#puts "#{self.class.name} return #{ret}"
def total_byte_length
ret = 0
self.each{|ins| ret += ins.byte_length}
ret
end
def set_position position , labels = []
def set_position( position )
Positioned.set_position(self,position)
position += byte_length
if self.next
self.next.set_position(position , labels)
self.next.set_position( position )
else
position
end
end
def each_label labels =[] , &block
self.next.each_label(labels , &block) if self.next
end
def class_source( derived)
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
end

View File

@ -15,42 +15,6 @@ module Risc
end
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
# dynamic version of an Unconditional branch that jumps to the contents

View File

@ -31,43 +31,13 @@ module Risc
@name.split(".").length == 2
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
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
def set_position position , labels = []
return position if labels.include?(self)
labels << self
super(position , labels)
self.next.set_position(position,labels) if self.next
def set_position( position )
super(position)
self.next.set_position(position) if self.next
end
# shame we need this, just for logging
@ -75,12 +45,6 @@ module Risc
0
end
def each_label labels =[] , &block
return if labels.include?(self)
labels << self
block.yield(self)
super
end
end
def self.label( source , name , nekst = nil)

View File

@ -61,20 +61,6 @@ module Risc
assert_equal @label, @instruction.next
assert_equal 2 , @instruction.length , @instruction.to_arr
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
label = Label.new("test" , "Object.test")
assert label.is_method