[pypy-svn] r25538 - pypy/branch/stacklesscfg/pypy/translator/stackless

mwh at codespeak.net mwh at codespeak.net
Sat Apr 8 13:43:40 CEST 2006


Author: mwh
Date: Sat Apr  8 13:43:39 2006
New Revision: 25538

Modified:
   pypy/branch/stacklesscfg/pypy/translator/stackless/code.py
   pypy/branch/stacklesscfg/pypy/translator/stackless/transform.py
Log:
(hpk, mwh)
use a helper function to attach the frame state to the UnwindException.  this
makes the segfaults go away, but code that tries to unwind will crash out with
an RPythonException, as we don't run the slp_main_loop yet.


Modified: pypy/branch/stacklesscfg/pypy/translator/stackless/code.py
==============================================================================
--- pypy/branch/stacklesscfg/pypy/translator/stackless/code.py	(original)
+++ pypy/branch/stacklesscfg/pypy/translator/stackless/code.py	Sat Apr  8 13:43:39 2006
@@ -79,3 +79,10 @@
         raise global_state.exception
 
 
+def add_frame_state(u, frame_state):
+    if not u.frame_top:
+        u.frame_top = u.frame_bottom = frame_state
+    else:
+        u.frame_bottom.f_back = frame_state
+        u.frame_bottom = frame_state
+        

Modified: pypy/branch/stacklesscfg/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/branch/stacklesscfg/pypy/translator/stackless/transform.py	(original)
+++ pypy/branch/stacklesscfg/pypy/translator/stackless/transform.py	Sat Apr  8 13:43:39 2006
@@ -77,6 +77,11 @@
         self.translator = translator
 
         edata = translator.rtyper.getexceptiondata()
+        bk = translator.annotator.bookkeeper
+
+        self.unwind_exception_type = getinstancerepr(
+            self.translator.rtyper,
+            bk.getuniqueclassdef(code.UnwindException)).lowleveltype
         self.frametypes = {}
         self.curr_graph = None
                 
@@ -91,6 +96,20 @@
             graph=slp_main_loop_graph),
             SLP_MAIN_LOOP_TYPE)
 
+        annotations = [annmodel.SomeInstance(bk.getuniqueclassdef(code.UnwindException)),
+                       annmodel.SomePtr(lltype.Ptr(STATE_HEADER))]
+
+        add_frame_state_graph = mixlevelannotator.getgraph(
+            code.add_frame_state,
+            annotations, l2a(lltype.Void))
+        ADD_FRAME_STATE_TYPE = lltype.FuncType(
+            [self.unwind_exception_type, lltype.Ptr(STATE_HEADER)],
+            lltype.Void)
+        self.add_frame_state_ptr = model.Constant(lltype.functionptr(
+            ADD_FRAME_STATE_TYPE, "add_frame_state",
+            graph=add_frame_state_graph),
+            lltype.Ptr(ADD_FRAME_STATE_TYPE))
+
         mixlevelannotator.finish()
 
     def frame_type_for_vars(self, vars):
@@ -178,9 +197,6 @@
         etype = edata.lltype_of_exception_type
         evalue = edata.lltype_of_exception_value
         inputargs = [copyvar(self.translator, v) for v in varstosave]
-        unwind_exception_type = getinstancerepr(rtyper,
-            self.translator.annotator.bookkeeper.getuniqueclassdef(
-                code.UnwindException)).lowleveltype
         var_unwind_exception = copyvar(self.translator, var_unwind_exception) 
 
         fields = []
@@ -202,31 +218,18 @@
         
         saveops.extend(self.generate_saveops(frame_state_var, inputargs))
 
-        var_exc = varoftype(unwind_exception_type)
+        var_exc = varoftype(self.unwind_exception_type)
         saveops.append(model.SpaceOperation("cast_pointer", [var_unwind_exception], 
                                             var_exc))
-
-##             header = state.header
-##             header.state = XXX
-##             exc.frame_bottom.f_back = state.header
-##             exc.frame_bottom = state.header
         
         var_header = varoftype(lltype.Ptr(STATE_HEADER))
     
         # XXX should this be getsubstruct?
         saveops.append(model.SpaceOperation("cast_pointer", [frame_state_var], var_header))
-        
-        var_exc_frame_bottom = varoftype(lltype.Ptr(STATE_HEADER))
-        saveops.append(model.SpaceOperation(
-            "getfield", [var_exc, model.Constant("inst_frame_bottom", lltype.Void)],
-            var_exc_frame_bottom))
-        
-        saveops.append(model.SpaceOperation(
-            "setfield", [var_exc_frame_bottom, model.Constant("f_back", lltype.Void), 
-                         var_header],
-            varoftype(lltype.Void)))
+
         saveops.append(model.SpaceOperation(
-            "setfield", [var_exc, model.Constant("inst_frame_bottom", lltype.Void), var_header],
+            "direct_call",
+            [self.add_frame_state_ptr, var_exc, var_header],
             varoftype(lltype.Void)))
 
         type_repr = rclass.get_type_repr(rtyper)



More information about the Pypy-commit mailing list