no default arg on init
also making sure the type is in the hash but also that the order of type does not matter
This commit is contained in:
parent
a82c9e8fb1
commit
db798d1a4a
@ -40,20 +40,18 @@ module Parfait
|
|||||||
attr_reader :object_class , :names , :types , :methods
|
attr_reader :object_class , :names , :types , :methods
|
||||||
|
|
||||||
def self.for_hash( object_class , hash)
|
def self.for_hash( object_class , hash)
|
||||||
|
hash[:type] = :Type unless hash[:type]
|
||||||
new_type = Type.new( object_class , hash)
|
new_type = Type.new( object_class , hash)
|
||||||
code = hash_code_for_hash( hash )
|
code = hash_code_for_hash( hash )
|
||||||
Parfait.object_space.types[code] = new_type
|
Parfait.object_space.types[code] = new_type
|
||||||
new_type
|
new_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hash_for_type(type)
|
|
||||||
self.hash_code_for_hash( type.to_hash )
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.hash_code_for_hash( dict )
|
def self.hash_code_for_hash( dict )
|
||||||
index = 1
|
index = 1
|
||||||
hash_code = 1
|
hash_code = 5467
|
||||||
dict.each do |name , type|
|
dict.each do |name , type|
|
||||||
|
next if name == :type
|
||||||
item_hash = str_hash(name) + str_hash(type)
|
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
|
||||||
@ -73,7 +71,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize( object_class , hash = {})
|
def initialize( object_class , hash )
|
||||||
super()
|
super()
|
||||||
set_object_class( object_class)
|
set_object_class( object_class)
|
||||||
init_lists( hash )
|
init_lists( hash )
|
||||||
@ -85,14 +83,15 @@ module Parfait
|
|||||||
@methods = List.new
|
@methods = List.new
|
||||||
@names = List.new
|
@names = List.new
|
||||||
@types = List.new
|
@types = List.new
|
||||||
private_add_instance_variable :type ,:Type
|
raise "No type Type in #{hash}" unless hash[:type]
|
||||||
|
private_add_instance_variable(:type , hash[:type]) #first
|
||||||
hash.each do |name , type|
|
hash.each do |name , type|
|
||||||
private_add_instance_variable(name , type) unless name == :type
|
private_add_instance_variable(name , type) unless name == :type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{@object_class.name}:#{@names.inspect}"
|
"#{@object_class.name}-#{@names.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_names
|
def method_names
|
||||||
@ -155,11 +154,8 @@ module Parfait
|
|||||||
hash[name] = type
|
hash[name] = type
|
||||||
code = Type.hash_code_for_hash( hash )
|
code = Type.hash_code_for_hash( hash )
|
||||||
existing = Parfait.object_space.types[code]
|
existing = Parfait.object_space.types[code]
|
||||||
if existing
|
return existing if existing
|
||||||
return existing
|
return Type.for_hash( @object_class , hash)
|
||||||
else
|
|
||||||
return Type.for_hash( @object_class , hash)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_object_class(oc)
|
def set_object_class(oc)
|
||||||
|
@ -40,7 +40,7 @@ module Parfait
|
|||||||
@name = name
|
@name = name
|
||||||
@binary = BinaryCode.new 0
|
@binary = BinaryCode.new 0
|
||||||
@arguments = arguments
|
@arguments = arguments
|
||||||
@locals = Type.new Parfait.object_space.get_class_by_name( :Object )
|
@locals = Parfait.object_space.get_class_by_name( :NamedList ).instance_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_instructions(inst)
|
def set_instructions(inst)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user