cleaner way to generate argument types
possibly more correct
This commit is contained in:
parent
83b6628f1a
commit
a7935db107
@ -11,7 +11,7 @@
|
|||||||
# PS: it turns out that both messages and named_lists are created at compile, not run-time, and
|
# PS: it turns out that both messages and named_lists are created at compile, not run-time, and
|
||||||
# just constantly reused. Each message has two named_list object ready and is also linked
|
# just constantly reused. Each message has two named_list object ready and is also linked
|
||||||
# to the next message.
|
# to the next message.
|
||||||
# The better way to say above is that a message is *used* by the caller, and a named_list
|
# The better way to say above is that a message is *used* by the caller, and a named_list
|
||||||
# by the callee.
|
# by the callee.
|
||||||
|
|
||||||
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
||||||
@ -23,5 +23,9 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class NamedList < Object
|
class NamedList < Object
|
||||||
|
|
||||||
|
def self.type_for( arguments )
|
||||||
|
my_class = Parfait.object_space.classes[:NamedList]
|
||||||
|
Parfait::Type.for_hash( my_class , arguments.merge(type: my_class.instance_type))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ 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]
|
hash = {type: object_class.name }.merge(hash) 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
|
||||||
@ -105,9 +105,9 @@ module Parfait
|
|||||||
def create_method( method_name , arguments )
|
def create_method( method_name , arguments )
|
||||||
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
|
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
|
||||||
#puts "Self: #{self.class} clazz: #{clazz.name}"
|
#puts "Self: #{self.class} clazz: #{clazz.name}"
|
||||||
type = arguments
|
arg_type = arguments
|
||||||
type = Parfait::Type.for_hash( @object_class , arguments) if arguments.is_a?(Hash)
|
arg_type = NamedList.type_for( arguments ) if arguments.is_a?(Hash)
|
||||||
add_method TypedMethod.new( self , method_name , type )
|
add_method TypedMethod.new( self , method_name , arg_type )
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_method( method )
|
def add_method( method )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user