[pypy-svn] r20252 - in pypy/branch/somepbc-refactoring/pypy/rpython: . lltypesystem

arigo at codespeak.net arigo at codespeak.net
Fri Nov 25 19:01:03 CET 2005


Author: arigo
Date: Fri Nov 25 19:01:02 2005
New Revision: 20252

Modified:
   pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rclass.py
   pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py
   pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py
Log:
(mwh, pedronis, arigo)

* convert_const() for classes
* re-enable isinstance() support, with numeric ids on the classes



Modified: pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rclass.py	Fri Nov 25 19:01:02 2005
@@ -128,19 +128,19 @@
         self.allmethods = allmethods
         self.vtable = None
 
-    def convert_const(self, value):
-        if not isinstance(value, (type, types.ClassType)):
-            raise TyperError("not a class: %r" % (value,))
-        try:
-            subclassdef = self.rtyper.annotator.getuserclasses()[value]
-        except KeyError:
-            raise TyperError("no classdef: %r" % (value,))
-        if self.classdef is not None:
-            if self.classdef.commonbase(subclassdef) != self.classdef:
-                raise TyperError("not a subclass of %r: %r" % (
-                    self.classdef.cls, value))
-        #
-        return getclassrepr(self.rtyper, subclassdef).getvtable()
+#    def convert_const(self, value):
+#        if not isinstance(value, (type, types.ClassType)):
+#            raise TyperError("not a class: %r" % (value,))
+#        try:
+#            subclassdef = self.rtyper.annotator.getuserclasses()[value]
+#        except KeyError:
+#            raise TyperError("no classdef: %r" % (value,))
+#        if self.classdef is not None:
+#            if self.classdef.commonbase(subclassdef) != self.classdef:
+#                raise TyperError("not a subclass of %r: %r" % (
+#                    self.classdef.cls, value))
+#        #
+#        return getclassrepr(self.rtyper, subclassdef).getvtable()
 
     def getvtable(self, cast_to_typeptr=True):
         """Return a ptr to the vtable of this type."""
@@ -161,12 +161,11 @@
             # initialize the 'parenttypeptr' and 'name' fields
             if rsubcls.classdef is not None:
                 vtable.parenttypeptr = rsubcls.rbase.getvtable()
-                #vtable.subclassrange_min = rsubcls.classdef.minid
-                #vtable.subclassrange_max = rsubcls.classdef.maxid
+                vtable.subclassrange_min = rsubcls.classdef.minid
+                vtable.subclassrange_max = rsubcls.classdef.maxid
             else: #for the root class
-                #vtable.subclassrange_min = 0
-                #vtable.subclassrange_max = sys.maxint
-                pass
+                vtable.subclassrange_min = 0
+                vtable.subclassrange_max = sys.maxint
             rinstance = getinstancerepr(self.rtyper, rsubcls.classdef)
             rinstance.setup()
             if rinstance.needsgc: # only gc-case

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/normalizecalls.py	Fri Nov 25 19:01:02 2005
@@ -397,7 +397,7 @@
         classdef.maxid = nextid
         return classdef.maxid
     id_ = 0
-    for cls, classdef in annotator.getuserclasses().items():
+    for classdef in annotator.bookkeeper.classdefs:
         if classdef.basedef is None:
             id_ = assign_id(classdef, id_)
         
@@ -409,7 +409,7 @@
         #XXX later: normalize_function_signatures(rtyper.annotator)
         #XXX later: specialize_pbcs_by_memotables(rtyper.annotator) 
         #XXX later: merge_classpbc_getattr_into_classdef(rtyper)
-        #XXX later: assign_inheritance_ids(rtyper.annotator)
+        assign_inheritance_ids(rtyper.annotator)
     finally:
         rtyper.annotator.frozen -= 1
     #XXX later: create_instantiate_functions(rtyper.annotator)

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rclass.py	Fri Nov 25 19:01:02 2005
@@ -65,20 +65,21 @@
             cls = self.classdef.cls
         return 'ClassR %s.%s' % (cls.__module__, cls.__name__)
 
-    def convert_const(self, value):
-        if not isinstance(value, (type, types.ClassType)):
-            raise TyperError("not a class: %r" % (value,))
-        try:
-            subclassdef = self.rtyper.annotator.getuserclasses()[value]
-        except KeyError:
-            raise TyperError("no classdef: %r" % (value,))
+    def convert_desc(self, desc):
+        subclassdef = desc.getuniqueclassdef()
         if self.classdef is not None:
             if self.classdef.commonbase(subclassdef) != self.classdef:
                 raise TyperError("not a subclass of %r: %r" % (
-                    self.classdef.cls, value))
+                    self.classdef.name, desc))
         #
         return getclassrepr(self.rtyper, subclassdef).getruntime()
 
+    def convert_const(self, value):
+        if not isinstance(value, (type, types.ClassType)):
+            raise TyperError("not a class: %r" % (value,))
+        bk = self.rtyper.annotator.bookkeeper
+        return self.convert_desc(bk.getdesc(value))
+
     def prepare_method(self, s_value):
         # special-casing for methods:
         #  if s_value is SomePBC([MethodDescs...])



More information about the Pypy-commit mailing list