2014-09-16 15:06:56 +02:00
|
|
|
require_relative "type"
|
|
|
|
|
2014-09-25 19:30:02 +02:00
|
|
|
module Positioned
|
|
|
|
def position
|
2014-10-07 11:01:33 +02:00
|
|
|
raise "position accessed but not set at #{length} for #{self.inspect[0...500]}" if @position == nil
|
2014-09-25 19:30:02 +02:00
|
|
|
@position
|
|
|
|
end
|
|
|
|
def set_position pos
|
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)
|
2014-09-28 10:18:24 +02:00
|
|
|
if @position != nil and ((@position - pos).abs > 32)
|
2015-05-04 10:10:40 +02:00
|
|
|
raise "position set again #{pos}!=#{@position} for #{self}"
|
2014-09-25 19:30:02 +02:00
|
|
|
end
|
|
|
|
@position = pos
|
|
|
|
end
|
2015-05-24 17:05:20 +02:00
|
|
|
# objects only come in lengths of multiple of 8 words
|
|
|
|
# but there is a constant overhead of 2 words, one for type, one for layout
|
|
|
|
# and as we would have to subtract 1 to make it work without overhead, we now have to add 7
|
|
|
|
def padded len
|
|
|
|
a = 32 * (1 + (len + 7)/32 )
|
|
|
|
#puts "#{a} for #{len}"
|
|
|
|
a
|
2014-09-16 15:06:56 +02:00
|
|
|
end
|
2015-05-24 17:05:20 +02:00
|
|
|
|
|
|
|
def padded_words words
|
|
|
|
padded(words*4) # 4 == word length, a constant waiting for a home
|
2014-09-16 16:16:56 +02:00
|
|
|
end
|
2014-06-26 17:39:02 +02:00
|
|
|
end
|