revert to symbols

Parfait::Words were nice, but endless problems with the fact that when
you write “String” you get a string.
Symbols take care of uniqueness at the same time
This commit is contained in:
Torsten Ruger
2015-05-31 18:34:18 +03:00
parent 5d870ef154
commit bee73801eb
18 changed files with 101 additions and 85 deletions

View File

@ -30,9 +30,17 @@ module Parfait
@instance_methods
end
def method_names
names = List.new
@instance_methods.each do |method|
names.push method.name
end
names
end
def add_instance_method method
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
raise "syserr #{method.name.class}" unless method.name.is_a? Word
raise "syserr #{method.name.class}" unless method.name.is_a? Symbol
found = get_instance_method( method.name )
if found
@instance_methods.delete(found)
@ -48,6 +56,7 @@ module Parfait
end
def create_instance_method name , arg_names
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
clazz = Space.object_space.get_class_by_name(self.name)
raise "??? #{self.name}" unless clazz
Method.new_object( clazz , name , arg_names )
@ -61,7 +70,7 @@ module Parfait
end
def get_instance_method fname
raise "uups #{fname}.#{fname.class}" unless fname.is_a?(Word) or fname.is_a?(String)
raise "uups #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
#if we had a hash this would be easier. Detect or find would help too
@instance_methods.each do |m|
return m if(m.name == fname )
@ -71,7 +80,7 @@ module Parfait
# get the method and if not found, try superclasses. raise error if not found
def resolve_method m_name
raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a?(Word) or m_name.is_a?(String)
raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a?(Symbol)
method = get_instance_method(m_name)
return method if method
if( @super_class )

View File

@ -56,14 +56,14 @@ module Parfait
end
def get_main
kernel = get_class_by_name "Object"
kernel.get_instance_method "main"
kernel = get_class_by_name :Object
kernel.get_instance_method :main
end
# this is the way to instantiate classes (not Parfait::Class.new)
# so we get and keep exactly one per name
def get_class_by_name name
raise "uups #{name}.#{name.class}" unless name.is_a?(Word) or name.is_a?(String)
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
c = @classes[name]
puts "MISS, no class #{name} #{name.class}" unless c # " #{@classes}"
c