2016-12-06 11:38:09 +02:00
|
|
|
# Helper module that extract position attribute.
|
2014-09-25 20:30:02 +03:00
|
|
|
module Positioned
|
2017-01-01 21:52:00 +02:00
|
|
|
@positions = {}
|
2016-12-28 12:51:18 +02:00
|
|
|
|
|
|
|
def self.positions
|
2017-01-01 21:52:00 +02:00
|
|
|
@positions
|
2016-12-28 12:51:18 +02:00
|
|
|
end
|
|
|
|
|
2017-01-01 21:52:00 +02:00
|
|
|
def self.position(object)
|
|
|
|
pos = self.positions[object]
|
2016-12-28 12:51:18 +02:00
|
|
|
if pos == nil
|
|
|
|
str = "position accessed but not set, "
|
2017-01-01 21:52:00 +02:00
|
|
|
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]}"
|
2015-05-30 12:20:39 +03:00
|
|
|
end
|
2016-12-28 12:51:18 +02:00
|
|
|
pos
|
2014-09-25 20:30:02 +03:00
|
|
|
end
|
2017-01-01 21:52:00 +02:00
|
|
|
|
|
|
|
def self.set_position( object , pos )
|
2016-12-28 12:51:18 +02:00
|
|
|
raise "Position must be number not :#{pos}:" unless pos.is_a?(Numeric)
|
2015-05-13 16:06:38 +03:00
|
|
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
|
|
|
# in measures (of 32)
|
2016-12-29 21:24:11 +02:00
|
|
|
#puts "Setting #{pos} for #{self.class}"
|
2017-01-01 21:52:00 +02:00
|
|
|
old = Positioned.positions[object]
|
2016-12-28 12:51:18 +02:00
|
|
|
if old != nil and ((old - pos).abs > 10000)
|
2017-01-01 21:52:00 +02:00
|
|
|
raise "position set again #{pos}!=#{old} for #{object}"
|
2014-09-25 20:30:02 +03:00
|
|
|
end
|
2017-01-01 21:52:00 +02:00
|
|
|
self.positions[object] = pos
|
2014-09-25 20:30:02 +03:00
|
|
|
end
|
2016-12-28 12:51:18 +02:00
|
|
|
|
|
|
|
|
2014-06-26 18:39:02 +03:00
|
|
|
end
|