[pypy-svn] r23523 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Mon Feb 20 20:52:07 CET 2006


Author: arigo
Date: Mon Feb 20 20:52:06 2006
New Revision: 23523

Modified:
   pypy/dist/pypy/rpython/annlowlevel.py
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/rpython/rtyper.py
Log:
(arigo, pedronis)

support for delaying setup through the MixLevelHelperAnnotator for some reprs.




Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py	(original)
+++ pypy/dist/pypy/rpython/annlowlevel.py	Mon Feb 20 20:52:06 2006
@@ -118,6 +118,7 @@
         self.rtyper = rtyper
         self.policy = MixLevelAnnotatorPolicy(rtyper)
         self.pending = []     # list of (graph, args_s, s_result)
+        self.delayedreprs = []
 
     def getgraph(self, ll_function, args_s, s_result):
         # get the graph of the mix-level helper ll_function and prepare it for
@@ -132,6 +133,15 @@
         self.pending.append((graph, args_s, s_result))
         return graph
 
+    def getdelayedrepr(self, s_value):
+        """Like rtyper.getrepr(), but the resulting repr will not be setup() at
+        all before finish() is called.
+        """
+        r = self.rtyper.getrepr(s_value)
+        r.set_setup_delayed(True)
+        self.delayedreprs.append(r)
+        return r
+
     def finish(self):
         # push all the graphs into the annotator's pending blocks dict at once
         rtyper = self.rtyper
@@ -152,5 +162,8 @@
                                 " found by annotating: %r" %
                                 (graph, s_result, s_real_result))
         rtyper.type_system.perform_normalizations(rtyper)
+        for r in self.delayedreprs:
+            r.set_setup_delayed(False)
         rtyper.specialize_more_blocks()
         del self.pending[:]
+        del self.delayedreprs[:]

Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Mon Feb 20 20:52:06 2006
@@ -14,7 +14,8 @@
     NOTINITIALIZED = 0 
     INPROGRESS = 1
     BROKEN = 2 
-    FINISHED = 3 
+    FINISHED = 3
+    DELAYED = 4
 
 class Repr:
     """ An instance of Repr is associated with each instance of SomeXxx.
@@ -46,6 +47,9 @@
         elif self._initialized == setupstate.INPROGRESS: 
             raise AssertionError(
                 "recursive invocation of Repr setup(): %r" %(self,))
+        elif self._initialized == setupstate.DELAYED:
+            raise AssertionError(
+                "Repr setup() is delayed and cannot be called yet: %r" %(self,))
         assert self._initialized == setupstate.NOTINITIALIZED 
         self._initialized = setupstate.INPROGRESS 
         try: 
@@ -72,7 +76,18 @@
         self._setup_repr_final() 
 
     def _setup_repr_final(self): 
-        pass 
+        pass
+
+    def is_setup_delayed(self):
+        return self._initialized == setupstate.DELAYED
+
+    def set_setup_delayed(self, flag):
+        assert self._initialized in (setupstate.NOTINITIALIZED,
+                                     setupstate.DELAYED)
+        if flag:
+            self._initialized = setupstate.DELAYED
+        else:
+            self._initialized = setupstate.NOTINITIALIZED
 
     def __getattr__(self, name):
         # Assume that when an attribute is missing, it's because setup() needs

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Mon Feb 20 20:52:06 2006
@@ -228,12 +228,17 @@
     def call_all_setups(self):
         # make sure all reprs so far have had their setup() called
         must_setup_more = []
+        delayed = []
         while self._reprs_must_call_setup:
             r = self._reprs_must_call_setup.pop()
-            r.setup()
-            must_setup_more.append(r)
+            if r.is_setup_delayed():
+                delayed.append(r)
+            else:
+                r.setup()
+                must_setup_more.append(r)
         for r in must_setup_more:
             r.setup_final()
+        self._reprs_must_call_setup.extend(delayed)
 
     def setconcretetype(self, v):
         assert isinstance(v, Variable)



More information about the Pypy-commit mailing list