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
|
||||
# just constantly reused. Each message has two named_list object ready and is also linked
|
||||
# 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.
|
||||
|
||||
# Also at runtime Messages and NamedLists remain completely "normal" objects.
|
||||
@ -23,5 +23,9 @@
|
||||
module Parfait
|
||||
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
|
||||
|
@ -40,7 +40,7 @@ module Parfait
|
||||
attr_reader :object_class , :names , :types , :methods
|
||||
|
||||
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)
|
||||
code = hash_code_for_hash( hash )
|
||||
Parfait.object_space.types[code] = new_type
|
||||
@ -105,9 +105,9 @@ module Parfait
|
||||
def create_method( method_name , arguments )
|
||||
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
|
||||
#puts "Self: #{self.class} clazz: #{clazz.name}"
|
||||
type = arguments
|
||||
type = Parfait::Type.for_hash( @object_class , arguments) if arguments.is_a?(Hash)
|
||||
add_method TypedMethod.new( self , method_name , type )
|
||||
arg_type = arguments
|
||||
arg_type = NamedList.type_for( arguments ) if arguments.is_a?(Hash)
|
||||
add_method TypedMethod.new( self , method_name , arg_type )
|
||||
end
|
||||
|
||||
def add_method( method )
|
||||
|
Loading…
Reference in New Issue
Block a user