rubyx/lib/risc/positioned.rb

33 lines
954 B
Ruby
Raw Normal View History

2016-12-06 10:38:09 +01:00
# Helper module that extract position attribute.
module Positioned
2017-01-01 20:52:00 +01:00
@positions = {}
def self.positions
2017-01-01 20:52:00 +01:00
@positions
end
2017-01-01 20:52:00 +01:00
def self.position(object)
pos = self.positions[object]
if pos == nil
str = "position accessed but not set, "
2017-01-01 20:52:00 +01: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 11:20:39 +02:00
end
pos
end
2017-01-01 20:52:00 +01:00
def self.set_position( object , pos )
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)
#puts "Setting #{pos} for #{self.class}"
2017-01-01 20:52:00 +01:00
old = Positioned.positions[object]
if old != nil and ((old - pos).abs > 10000)
2017-01-01 20:52:00 +01:00
raise "position set again #{pos}!=#{old} for #{object}"
end
2017-01-01 20:52:00 +01:00
self.positions[object] = pos
end
end