make positioned a helper module
This commit is contained in:
parent
b8b387d498
commit
fafcd15ce8
@ -1,30 +1,31 @@
|
||||
# Helper module that extract position attribute.
|
||||
module Positioned
|
||||
@@positions = {}
|
||||
@positions = {}
|
||||
|
||||
def self.positions
|
||||
@@positions
|
||||
@positions
|
||||
end
|
||||
|
||||
def position
|
||||
pos = Positioned.positions[self]
|
||||
def self.position(object)
|
||||
pos = self.positions[object]
|
||||
if pos == nil
|
||||
str = "position accessed but not set, "
|
||||
str += "#{self.object_id.to_s(16)}\n"
|
||||
raise str + "for #{self.class} byte_length #{self.byte_length if self.respond_to?(:byte_length)} for #{self.inspect[0...100]}"
|
||||
str += "#{object.object_id.to_s(16)}\n"
|
||||
raise str + "for #{object.class} byte_length #{object.byte_length if object.respond_to?(:byte_length)} for #{object.inspect[0...100]}"
|
||||
end
|
||||
pos
|
||||
end
|
||||
def set_position( pos )
|
||||
|
||||
def self.set_position( object , pos )
|
||||
raise "Position must be number not :#{pos}:" unless pos.is_a?(Numeric)
|
||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
||||
# in measures (of 32)
|
||||
#puts "Setting #{pos} for #{self.class}"
|
||||
old = Positioned.positions[self]
|
||||
old = Positioned.positions[object]
|
||||
if old != nil and ((old - pos).abs > 10000)
|
||||
raise "position set again #{pos}!=#{old} for #{self}"
|
||||
raise "position set again #{pos}!=#{old} for #{object}"
|
||||
end
|
||||
Positioned.positions[self] = pos
|
||||
self.positions[object] = pos
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user