2016-12-06 10:38:09 +01:00
|
|
|
# Helper module that extract position attribute.
|
2014-09-25 19:30:02 +02:00
|
|
|
module Positioned
|
2016-12-28 11:51:18 +01:00
|
|
|
@@positions = {}
|
|
|
|
|
|
|
|
def self.positions
|
|
|
|
@@positions
|
|
|
|
end
|
|
|
|
|
2014-09-25 19:30:02 +02:00
|
|
|
def position
|
2016-12-28 11:51:18 +01:00
|
|
|
pos = Positioned.positions[self]
|
|
|
|
if pos == nil
|
|
|
|
str = "position accessed but not set, "
|
|
|
|
str += "#{Register.machine.objects.has_key?(self.object_id)}, at #{self.object_id.to_s(16)}\n"
|
|
|
|
raise str + "for #{self.class} byte_length #{byte_length} for #{self.inspect[0...100]}"
|
2015-05-30 11:20:39 +02:00
|
|
|
end
|
2016-12-28 11:51:18 +01:00
|
|
|
pos
|
2014-09-25 19:30:02 +02:00
|
|
|
end
|
2015-10-24 16:12:36 +02:00
|
|
|
def position= pos
|
2016-12-28 11:51:18 +01:00
|
|
|
raise "Position must be number not :#{pos}:" unless pos.is_a?(Numeric)
|
2015-05-13 15:06:38 +02:00
|
|
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
|
|
|
# in measures (of 32)
|
2016-12-28 11:51:18 +01:00
|
|
|
old = Positioned.positions[self]
|
|
|
|
if old != nil and ((old - pos).abs > 10000)
|
|
|
|
raise "position set again #{pos}!=#{old} for #{self}"
|
2014-09-25 19:30:02 +02:00
|
|
|
end
|
2016-12-28 11:51:18 +01:00
|
|
|
Positioned.positions[self] = pos
|
2014-09-25 19:30:02 +02:00
|
|
|
end
|
2016-12-28 11:51:18 +01:00
|
|
|
|
|
|
|
|
2014-06-26 17:39:02 +02:00
|
|
|
end
|