keep positions globally, not in the object
hopefully cleaner switch after bootstrapping
This commit is contained in:
parent
9fb89e09f3
commit
4940bc41a3
@ -1,19 +1,30 @@
|
|||||||
# Helper module that extract position attribute.
|
# Helper module that extract position attribute.
|
||||||
module Positioned
|
module Positioned
|
||||||
|
@@positions = {}
|
||||||
|
|
||||||
|
def self.positions
|
||||||
|
@@positions
|
||||||
|
end
|
||||||
|
|
||||||
def position
|
def position
|
||||||
if @position.nil?
|
pos = Positioned.positions[self]
|
||||||
str = "IN machine #{Register.machine.objects.has_key?(self.object_id)}, at #{self.object_id.to_s(16)}\n"
|
if pos == nil
|
||||||
raise str + "position not set for #{self.class} byte_length #{byte_length} for #{self.inspect[0...100]}"
|
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
|
end
|
||||||
@position
|
pos
|
||||||
end
|
end
|
||||||
def position= pos
|
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.
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
||||||
# in measures (of 32)
|
# in measures (of 32)
|
||||||
if @position != nil and ((@position - pos).abs > 10000)
|
old = Positioned.positions[self]
|
||||||
raise "position set again #{pos}!=#{@position} for #{self}"
|
if old != nil and ((old - pos).abs > 10000)
|
||||||
|
raise "position set again #{pos}!=#{old} for #{self}"
|
||||||
end
|
end
|
||||||
@position = pos
|
Positioned.positions[self] = pos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -14,30 +14,5 @@ class Symbol
|
|||||||
def padded_length
|
def padded_length
|
||||||
padded to_s.length + 4
|
padded to_s.length + 4
|
||||||
end
|
end
|
||||||
# not the prettiest addition to the game, but it wasn't me who decided symbols are frozen in 2.x
|
|
||||||
def cache_positions
|
|
||||||
unless defined?(@@symbol_positions)
|
|
||||||
@@symbol_positions = {}
|
|
||||||
end
|
|
||||||
@@symbol_positions
|
|
||||||
end
|
|
||||||
def position
|
|
||||||
pos = cache_positions[self]
|
|
||||||
if pos == nil
|
|
||||||
str = "position accessed but not set, "
|
|
||||||
str += "Machine has object=#{Register.machine.objects.has_key?(self.object_id)} "
|
|
||||||
raise str + " for Symbol:#{self}"
|
|
||||||
end
|
|
||||||
pos
|
|
||||||
end
|
|
||||||
def position= pos
|
|
||||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
|
||||||
# in measures (of 32)
|
|
||||||
old = cache_positions[self]
|
|
||||||
if old != nil and ((old - pos).abs > 20000)
|
|
||||||
raise "position set again #{pos}!=#{old} for #{self}"
|
|
||||||
end
|
|
||||||
cache_positions[self] = pos
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -51,13 +51,17 @@ module Parfait
|
|||||||
|
|
||||||
def self.hash_code_for_hash( dict )
|
def self.hash_code_for_hash( dict )
|
||||||
index = 1
|
index = 1
|
||||||
hash_code = ""
|
hash_code = 1
|
||||||
dict.each do |name , type|
|
dict.each do |name , type|
|
||||||
item_hash = name.to_s + type.to_s
|
item_hash = str_hash(name) + str_hash(type)
|
||||||
hash_code += item_hash #+ (item_hash / 256 ) * index
|
hash_code += item_hash + (item_hash / 256 ) * index
|
||||||
index += 1
|
index += 1
|
||||||
end
|
end
|
||||||
hash_code.to_sym
|
hash_code
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.str_hash(str)
|
||||||
|
str = str.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize( object_class , hash = {})
|
def initialize( object_class , hash = {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user