[pypy-svn] r20236 - in pypy/branch/somepbc-refactoring/pypy: annotation rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Fri Nov 25 12:20:14 CET 2005


Author: arigo
Date: Fri Nov 25 12:20:13 2005
New Revision: 20236

Modified:
   pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py
   pypy/branch/somepbc-refactoring/pypy/annotation/description.py
   pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py
Log:
(mwh, pedronis, arigo)

fixed __init__ support in the annotator, and implemented the simple case
in the RTyper.  (test_rpbc: 30/51 pass)



Modified: pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py	Fri Nov 25 12:20:13 2005
@@ -197,10 +197,14 @@
                 newblocks = self.annotator.added_blocks
                 if newblocks is None:
                     newblocks = self.annotator.annotated  # all of them
+                binding = self.annotator.binding
                 for block in newblocks:
                     for op in block.operations:
                         if op.opname in ('simple_call', 'call_args'):
                             yield op
+                        # some blocks are partially annotated
+                        if binding(op.result, extquery=True) is None:
+                            break   # ignore the unannotated part
 
             for call_op in call_sites():
                 self.consider_call_site(call_op)
@@ -225,7 +229,11 @@
             descs = s_callable.descriptions.keys()
             family = descs[0].getcallfamily()
             args = self.build_args(call_op.opname, args_s)
-            s_callable.getKind().consider_call_site(self, family, descs, args)
+            s_result = binding(call_op.result, extquery=True)
+            if s_result is None:
+                s_result = s_ImpossibleValue
+            s_callable.getKind().consider_call_site(self, family, descs, args,
+                                                    s_result)
 
     def getuniqueclassdef(self, cls):
         """Get the ClassDef associated with the given user cls.

Modified: pypy/branch/somepbc-refactoring/pypy/annotation/description.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/description.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/description.py	Fri Nov 25 12:20:13 2005
@@ -211,7 +211,7 @@
         # XXX static methods
         return self.bookkeeper.getmethoddesc(self, classdef, name)
 
-    def consider_call_site(bookkeeper, family, descs, args):
+    def consider_call_site(bookkeeper, family, descs, args, s_result):
         row = FunctionDesc.row_to_consider(descs, args)
         family.calltable_add_row(args.rawshape(), row)
     consider_call_site = staticmethod(consider_call_site)
@@ -434,8 +434,36 @@
                 return self
         return None
 
-    def consider_call_site(bookkeeper, family, descs, args):
-        print "XXX not implemented"
+    def consider_call_site(bookkeeper, family, descs, args, s_result):
+        from pypy.annotation.model import SomeInstance, SomePBC, s_None
+        if len(descs) == 1:
+            # call to a single class, look at the result annotation
+            # in case it was specialized
+            if not isinstance(s_result, SomeInstance):
+                raise Exception("calling a class didn't return an instance??")
+            classdefs = [s_result.classdef]
+        else:
+            # call to multiple classes: specialization not supported
+            classdefs = [desc.getuniqueclassdef() for desc in descs]
+        # make a PBC of MethodDescs, one for the __init__ of each class
+        initdescs = []
+        for desc, classdef in zip(descs, classdefs):
+            s_init = desc.s_read_attribute('__init__')
+            if isinstance(s_init, SomePBC):
+                assert len(s_init.descriptions) == 1, (
+                    "unexpected dynamic __init__?")
+                initfuncdesc = s_init.descriptions.keys()[0]
+                if isinstance(initfuncdesc, FunctionDesc):
+                    initmethdesc = bookkeeper.getmethoddesc(initfuncdesc,
+                                                            classdef,
+                                                            '__init__')
+                    initdescs.append(initmethdesc)
+        # register a call to exactly these __init__ methods
+        if initdescs:
+            initdescs[0].mergecallfamilies(*initdescs[1:])
+            initfamily = initdescs[0].getcallfamily()
+            MethodDesc.consider_call_site(bookkeeper, initfamily, initdescs,
+                                          args, s_None)
     consider_call_site = staticmethod(consider_call_site)
 
     def rowkey(self):
@@ -465,7 +493,7 @@
         self.bookkeeper.warning("rebinding an already bound %r" % (self,))
         return self.funcdesc.bind_under(classdef, name)
     
-    def consider_call_site(bookkeeper, family, descs, args):
+    def consider_call_site(bookkeeper, family, descs, args, s_result):
         funcdescs = [methoddesc.funcdesc for methoddesc in descs]
         row = FunctionDesc.row_to_consider(descs, args)
         shape = args.rawshape()
@@ -539,7 +567,7 @@
         args = args.prepend(s_self)
         return self.funcdesc.pycall(schedule, args, s_previous_result)
     
-    def consider_call_site(bookkeeper, family, descs, args):
+    def consider_call_site(bookkeeper, family, descs, args, s_result):
         funcdescs = [mofdesc.funcdesc for mofdesc in descs]
         row = FunctionDesc.row_to_consider(descs, args)
         shape = args.rawshape()

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/lltypesystem/rpbc.py	Fri Nov 25 12:20:13 2005
@@ -265,14 +265,15 @@
             return hop2.dispatch()
 
         # instantiating a single class
-        classdef = self.s_pbc.descriptions.keys()[0].getuniqueclassdef()  # xxx specialisation
+        s_instance = hop.s_result
+        assert isinstance(s_instance, annmodel.SomeInstance)
+        classdef = hop.s_result.classdef
         v_instance = rclass.rtype_new_instance(hop.rtyper, classdef, hop.llops)
         s_init = classdef.classdesc.s_read_attribute('__init__')
         if isinstance(s_init, annmodel.SomeImpossibleValue):
             assert hop.nb_args == 1, ("arguments passed to __init__, "
                                       "but no __init__!")
         else:
-            s_instance = rclass.instance_annotation_for_cls(self.rtyper, klass)
             hop2 = hop.copy()
             hop2.r_s_popfirstarg()   # discard the class pointer argument
             if call_args:
@@ -281,9 +282,9 @@
                 adjust_shape(hop2, s_shape)
             else:
                 hop2.v_s_insertfirstarg(v_instance, s_instance)  # add 'instance'
-            c = Constant(initfunc)
+            c = Constant("init-func-dummy")   # this value not really used
             hop2.v_s_insertfirstarg(c, s_init)   # add 'initfunc'
-            hop2.s_result = annmodel.SomePBC({None: True})
+            hop2.s_result = annmodel.s_None
             hop2.r_result = self.rtyper.getrepr(hop2.s_result)
             # now hop2 looks like simple_call(initfunc, instance, args...)
             hop2.dispatch()



More information about the Pypy-commit mailing list