[pypy-svn] r29722 - pypy/dist/pypy/translator/stackless

mwh at codespeak.net mwh at codespeak.net
Fri Jul 7 11:13:04 CEST 2006


Author: mwh
Date: Fri Jul  7 11:13:02 2006
New Revision: 29722

Modified:
   pypy/dist/pypy/translator/stackless/frame.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(misto, mwh)
de-generalize some of the RestartInfo code.


Modified: pypy/dist/pypy/translator/stackless/frame.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/frame.py	(original)
+++ pypy/dist/pypy/translator/stackless/frame.py	Fri Jul  7 11:13:02 2006
@@ -97,12 +97,23 @@
 
 class RestartInfo(object):
 
-    def __init__(self, func_or_graph, frame_types):
+    """A RestartInfo is created (briefly) for each graph that contains
+    a resume point.
+
+    In addition, a RestartInfo is created for each function that needs
+    to do explicit stackless manipulations
+    (e.g. code.yield_current_frame_to_caller)."""
+
+    def __init__(self, func_or_graph, resume_point_count):
         self.func_or_graph = func_or_graph
-        self.frame_types = frame_types
+        self.resume_point_count = resume_point_count
+        self.frame_types = ()
 
     def compress(self, rtyper):
-        if self.frame_types:
+        """This returns sufficient information to be able to build the
+        entries that will go in the global array of restart
+        information."""
+        if self.resume_point_count > 0:
             bk = rtyper.annotator.bookkeeper
             graph = self.func_or_graph
             if not isinstance(graph, FunctionGraph):
@@ -111,11 +122,9 @@
             rettype = lltype.typeOf(funcptr).TO.RESULT
             retval_type = STORAGE_TYPES.index(storage_type(rettype))
 
-            result = [{'fnaddr': llmemory.cast_ptr_to_adr(funcptr),
-                       'info':   retval_type},
-                      ]
-            for i in range(1, len(self.frame_types)):
-                result.append({'info': i})
+            result = [(llmemory.cast_ptr_to_adr(funcptr), retval_type)]
+            for i in range(1, self.resume_point_count):
+                result.append((llmemory.NULL, i))
         else:
             result = []
         return result
@@ -125,7 +134,8 @@
 
     def add_prebuilt(cls, func, frame_types):
         assert func.stackless_explicit    # did you forget this flag?
-        restart = cls(func, frame_types)
+        restart = cls(func, len(frame_types))
+        restart.frame_types = frame_types
         n = cls.prebuiltindex
         cls.prebuilt.append(restart)
         cls.prebuiltindex += len(frame_types)

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Fri Jul  7 11:13:02 2006
@@ -845,15 +845,14 @@
         return llops
 
     def generate_restart_infos(self, graph):
-        frame_types = [rp.frame_state_type for rp in self.resume_points]
-        restartinfo = frame.RestartInfo(graph, frame_types)
+        restartinfo = frame.RestartInfo(graph, len(self.resume_points))
         self.register_restart_info(restartinfo)
 
     def register_restart_info(self, restartinfo):
         assert not self.is_finished
         rtyper = self.translator.rtyper
-        for frame_info_dict in restartinfo.compress(rtyper):
-            self.masterarray1.append(frame_info_dict)
+        for frame_info in restartinfo.compress(rtyper):
+            self.masterarray1.append(frame_info)
 
     def finish(self):
         # compute the final masterarray by copying over the masterarray1,
@@ -863,8 +862,7 @@
                                     len(self.masterarray1),
                                     immortal=True)
         for dst, src in zip(masterarray, self.masterarray1):
-            for key, value in src.items():
-                setattr(dst, key, value)
+            dst.fnaddr, dst.info = src
         # horrors in the same spirit as in rpython.memory.gctransform
         # (shorter, though)
         ll_global_state = self.ll_global_state.value



More information about the Pypy-commit mailing list