keep positions globally, not in the object
hopefully cleaner switch after bootstrapping
This commit is contained in:
@ -1,19 +1,30 @@
|
||||
# Helper module that extract position attribute.
|
||||
module Positioned
|
||||
@@positions = {}
|
||||
|
||||
def self.positions
|
||||
@@positions
|
||||
end
|
||||
|
||||
def position
|
||||
if @position.nil?
|
||||
str = "IN machine #{Register.machine.objects.has_key?(self.object_id)}, at #{self.object_id.to_s(16)}\n"
|
||||
raise str + "position not set for #{self.class} byte_length #{byte_length} for #{self.inspect[0...100]}"
|
||||
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]}"
|
||||
end
|
||||
@position
|
||||
pos
|
||||
end
|
||||
def position= pos
|
||||
raise "Setting of nil not allowed" if pos.nil?
|
||||
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)
|
||||
if @position != nil and ((@position - pos).abs > 10000)
|
||||
raise "position set again #{pos}!=#{@position} for #{self}"
|
||||
old = Positioned.positions[self]
|
||||
if old != nil and ((old - pos).abs > 10000)
|
||||
raise "position set again #{pos}!=#{old} for #{self}"
|
||||
end
|
||||
@position = pos
|
||||
Positioned.positions[self] = pos
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user