keep positions globally, not in the object

hopefully cleaner switch after bootstrapping
This commit is contained in:
Torsten Ruger
2016-12-28 12:51:18 +02:00
parent 9fb89e09f3
commit 4940bc41a3
3 changed files with 27 additions and 37 deletions

View File

@ -14,30 +14,5 @@ class Symbol
def padded_length
padded to_s.length + 4
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

View File

@ -51,15 +51,19 @@ module Parfait
def self.hash_code_for_hash( dict )
index = 1
hash_code = ""
hash_code = 1
dict.each do |name , type|
item_hash = name.to_s + type.to_s
hash_code += item_hash #+ (item_hash / 256 ) * index
item_hash = str_hash(name) + str_hash(type)
hash_code += item_hash + (item_hash / 256 ) * index
index += 1
end
hash_code.to_sym
hash_code
end
def self.str_hash(str)
str = str.hash
end
def initialize( object_class , hash = {})
super()
private_add_instance_variable :type ,:Type