1.1 --- a/deducer.py Mon Nov 28 23:51:45 2016 +0100
1.2 +++ b/deducer.py Tue Nov 29 00:47:19 2016 +0100
1.3 @@ -1354,7 +1354,7 @@
1.4 "Return whether 'path' refers to a method."
1.5
1.6 class_name, method_name = path.rsplit(".", 1)
1.7 - return self.importer.classes.has_key(class_name) and class_name
1.8 + return class_name != "__builtins__.core.type" and self.importer.classes.has_key(class_name) and class_name
1.9
1.10 def init_reference_details(self, location):
1.11
2.1 --- a/generator.py Mon Nov 28 23:51:45 2016 +0100
2.2 +++ b/generator.py Tue Nov 29 00:47:19 2016 +0100
2.3 @@ -51,11 +51,12 @@
2.4
2.5 "A code generator."
2.6
2.7 + # NOTE: These must be synchronised with the library.
2.8 +
2.9 function_type = "__builtins__.core.function"
2.10 type_error_type = "__builtins__.core.TypeError"
2.11 memory_error_type = "__builtins__.core.MemoryError"
2.12 -
2.13 - # NOTE: These must be synchronised with the library.
2.14 + type_type = "__builtins__.core.type"
2.15
2.16 predefined_constant_members = (
2.17 ("__builtins__.boolean", "False"),
2.18 @@ -352,12 +353,18 @@
2.19 #define __FUNCTION_INSTANCE_SIZE %s
2.20 #define __TYPE_ERROR_INSTANTIATOR %s
2.21 #define __MEMORY_ERROR_INSTANTIATOR %s
2.22 +#define __TYPE_CLASS_TYPE %s
2.23 +#define __TYPE_CLASS_POS %s
2.24 +#define __TYPE_CLASS_CODE %s
2.25
2.26 #endif /* __PROGTYPES_H__ */""" % (
2.27 encode_path(self.function_type),
2.28 encode_size("<instance>", self.function_type),
2.29 encode_instantiator_pointer(self.type_error_type),
2.30 - encode_instantiator_pointer(self.memory_error_type)
2.31 + encode_instantiator_pointer(self.memory_error_type),
2.32 + encode_path(self.type_type),
2.33 + encode_symbol("pos", encode_type_attribute(self.type_type)),
2.34 + encode_symbol("code", encode_type_attribute(self.type_type)),
2.35 )
2.36
2.37 print >>f_signatures, """\
3.1 --- a/inspector.py Mon Nov 28 23:51:45 2016 +0100
3.2 +++ b/inspector.py Tue Nov 29 00:47:19 2016 +0100
3.3 @@ -530,7 +530,8 @@
3.4 self.set_name("__fn__") # special instantiator attribute
3.5 self.set_name("__args__") # special instantiator attribute
3.6
3.7 - self.assign_general_local("__name__", self.get_constant("string", class_name))
3.8 + self.set_name("__name__", self.get_constant("string", class_name).reference())
3.9 +
3.10 self.process_structure_node(n.code)
3.11 self.exit_namespace()
3.12 self.in_class = in_class
4.1 --- a/lib/__builtins__/core.py Mon Nov 28 23:51:45 2016 +0100
4.2 +++ b/lib/__builtins__/core.py Tue Nov 29 00:47:19 2016 +0100
4.3 @@ -97,13 +97,21 @@
4.4
4.5 __repr__ = __str__
4.6
4.7 -class type(object):
4.8 +class type:
4.9
4.10 - "The class of all classes."
4.11 + """
4.12 + The class of all classes. Methods of this class do not treat contexts as
4.13 + instances, even though classes are meant to be instances of this class.
4.14 + Instead, contexts are either classes or instances.
4.15 + """
4.16
4.17 - # __str__ and __repr__ are handled by str and repr for classes.
4.18 + def __str__(self):
4.19 +
4.20 + "Return a string representation."
4.21
4.22 - pass
4.23 + return self.__name__
4.24 +
4.25 + __repr__ = __str__
4.26
4.27 class BaseException:
4.28
5.1 --- a/lib/__builtins__/identity.py Mon Nov 28 23:51:45 2016 +0100
5.2 +++ b/lib/__builtins__/identity.py Tue Nov 29 00:47:19 2016 +0100
5.3 @@ -86,14 +86,8 @@
5.4
5.5 "Return a program representation for 'obj'."
5.6
5.7 - # Classes do not provide __repr__ directly.
5.8 -
5.9 - if isclass(obj):
5.10 - return obj.__name__
5.11 -
5.12 # Class attributes of instances provide __repr__.
5.13
5.14 - else:
5.15 - return obj.__repr__()
5.16 + return obj.__repr__()
5.17
5.18 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/lib/__builtins__/str.py Mon Nov 28 23:51:45 2016 +0100
6.2 +++ b/lib/__builtins__/str.py Tue Nov 29 00:47:19 2016 +0100
6.3 @@ -114,14 +114,8 @@
6.4
6.5 "Return the string representation of 'obj'."
6.6
6.7 - # Classes do not provide __str__ directly.
6.8 -
6.9 - if isclass(obj):
6.10 - return obj.__name__
6.11 -
6.12 # Class attributes of instances provide __str__.
6.13
6.14 - else:
6.15 - return obj.__str__()
6.16 + return obj.__str__()
6.17
6.18 # vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/templates/ops.c Mon Nov 28 23:51:45 2016 +0100
7.2 +++ b/templates/ops.c Tue Nov 29 00:47:19 2016 +0100
7.3 @@ -59,6 +59,11 @@
7.4 return obj->pos == __INSTANCEPOS;
7.5 }
7.6
7.7 +int __is_type_instance(__ref obj)
7.8 +{
7.9 + return __HASATTR(__get_class(obj), __TYPE_CLASS_POS, __TYPE_CLASS_CODE);
7.10 +}
7.11 +
7.12 __ref __get_class(__ref obj)
7.13 {
7.14 return __load_via_object(obj, __pos___class__).value;
7.15 @@ -186,6 +191,11 @@
7.16 else
7.17 __raise_type_error();
7.18
7.19 + /* Test for access to a type class attribute using a type instance. */
7.20 +
7.21 + if (__test_specific_type(attr.context, &__TYPE_CLASS_TYPE) && __is_type_instance(context))
7.22 + return __replace_context(context, attr);
7.23 +
7.24 /* Otherwise, preserve the attribute as retrieved. */
7.25
7.26 return attr;
8.1 --- a/templates/ops.h Mon Nov 28 23:51:45 2016 +0100
8.2 +++ b/templates/ops.h Tue Nov 29 00:47:19 2016 +0100
8.3 @@ -24,6 +24,7 @@
8.4 /* Introspection. */
8.5
8.6 int __is_instance(__ref obj);
8.7 +int __is_type_instance(__ref obj);
8.8 __ref __get_class(__ref obj);
8.9 __attr __get_class_attr(__ref obj);
8.10