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

arigo at codespeak.net arigo at codespeak.net
Sat May 13 00:18:59 CEST 2006


Author: arigo
Date: Sat May 13 00:18:58 2006
New Revision: 27158

Modified:
   pypy/dist/pypy/translator/stackless/frame.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
Order issues: discover new graphs and frame types for the stackless
helpers along the way during the stackless transformation.
(Apart from the few prebuilt ones, the RestartInfo instances
are now very short-lived, which makes them a bit strange).


Modified: pypy/dist/pypy/translator/stackless/frame.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/frame.py	(original)
+++ pypy/dist/pypy/translator/stackless/frame.py	Sat May 13 00:18:58 2006
@@ -125,16 +125,12 @@
 
 
 class RestartInfo(object):
-    __slots__ = ['func_or_graph',
-                 'first_index',
-                 'frame_types']
 
-    def __init__(self, func_or_graph, first_index, frame_types):
+    def __init__(self, func_or_graph, frame_types):
         self.func_or_graph = func_or_graph
-        self.first_index = first_index
         self.frame_types = frame_types
 
-    def compress(self, rtyper, masterarray):
+    def compress(self, rtyper):
         if self.frame_types:
             bk = rtyper.annotator.bookkeeper
             graph = self.func_or_graph
@@ -144,12 +140,11 @@
             rettype = lltype.typeOf(funcptr).TO.RESULT
             retval_type = STORAGE_TYPES.index(storage_type(rettype))
 
-            finfo = masterarray[self.first_index]
-            finfo.fnaddr = llmemory.cast_ptr_to_adr(funcptr)
-            finfo.info = retval_type
+            result = [{'fnaddr': llmemory.cast_ptr_to_adr(funcptr),
+                       'info':   retval_type},
+                      ]
             for i in range(1, len(self.frame_types)):
-                finfo = masterarray[self.first_index+i]
-                finfo.info = i
+                result.append({'info': i})
             for i in range(len(self.frame_types)):
                 reccopy = self.frame_types[i].reccopy
                 s_header = annmodel.SomePtr(lltype.Ptr(STATE_HEADER))
@@ -157,15 +152,18 @@
                 fnptr = mixlevelannotator.delayedfunction(reccopy, [s_header],
                                                           s_header)
                 mixlevelannotator.finish()
-                masterarray[self.first_index+i].reccopy = fnptr
+                result[i]['reccopy'] = fnptr
+        else:
+            result = []
+        return result
 
     prebuilt = []
     prebuiltindex = 0
 
     def add_prebuilt(cls, func, frame_types):
         assert func.stackless_explicit    # did you forget this flag?
+        restart = cls(func, frame_types)
         n = cls.prebuiltindex
-        restart = cls(func, n, frame_types)
         cls.prebuilt.append(restart)
         cls.prebuiltindex += len(frame_types)
         return n

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Sat May 13 00:18:58 2006
@@ -120,8 +120,7 @@
         self.translator = translator
 
         self.frametyper = FrameTyper()
-        self.restartinfos = frame.RestartInfo.prebuilt[:]
-        self.restartinfoindex = frame.RestartInfo.prebuiltindex
+        self.masterarray1 = []
         self.curr_graph = None
         
         bk = translator.annotator.bookkeeper
@@ -215,6 +214,10 @@
         self.c_null_state = model.Constant(null_state,
                                            lltype.typeOf(null_state))
 
+        # register the prebuilt restartinfos
+        for restartinfo in frame.RestartInfo.prebuilt:
+            self.register_restart_info(restartinfo)
+
     def transform_all(self):
         for graph in self.translator.graphs:
             self.transform_graph(graph)
@@ -504,7 +507,7 @@
             [self.add_frame_state_ptr, var_exc, var_header],
             varoftype(lltype.Void)))
 
-        f_restart = self.restartinfoindex + len(self.resume_points)
+        f_restart = len(self.masterarray1) + len(self.resume_points)
         saveops.append(model.SpaceOperation(
             "setfield",
             [var_header, self.c_f_restart_name,
@@ -539,19 +542,23 @@
 
     def generate_restart_infos(self, graph):
         frame_types = [rp.frame_state_type for rp in self.resume_points]
-        restartinfo = frame.RestartInfo(graph, self.restartinfoindex,
-                                        frame_types)
-        self.restartinfos.append(restartinfo)
-        self.restartinfoindex += len(self.resume_points)
+        restartinfo = frame.RestartInfo(graph, frame_types)
+        self.register_restart_info(restartinfo)
+
+    def register_restart_info(self, restartinfo):
+        rtyper = self.translator.rtyper
+        for frame_info_dict in restartinfo.compress(rtyper):
+            self.masterarray1.append(frame_info_dict)
 
     def finish(self):
-        # compute the final masterarray
+        # compute the final masterarray by copying over the masterarray1,
+        # which is a list of dicts of attributes
         masterarray = lltype.malloc(frame.FRAME_INFO_ARRAY,
-                                    self.restartinfoindex,
+                                    len(self.masterarray1),
                                     immortal=True)
-        rtyper = self.translator.rtyper
-        for restartinfo in self.restartinfos:
-            restartinfo.compress(rtyper, masterarray)
+        for dst, src in zip(masterarray, self.masterarray1):
+            for key, value in src.items():
+                setattr(dst, key, value)
         # 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