[pypy-svn] r23509 - in pypy/dist/pypy/translator/c: . src

ericvrp at codespeak.net ericvrp at codespeak.net
Mon Feb 20 13:03:05 CET 2006


Author: ericvrp
Date: Mon Feb 20 13:03:00 2006
New Revision: 23509

Modified:
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/src/exception.h
   pypy/dist/pypy/translator/c/src/ll_stackless.h
   pypy/dist/pypy/translator/c/stackless.py
Log:
Moved stackless unwind optimization out of src/exception.h and into
src/ll_stackless.h , which it is now an optional feature enabled
by the USE_OPTIMIZED_STACKLESS_UNWIND define in genc.py.

Basically reverted r23485 , it was indeed not neccessary.
(exception and unwind can not happen at the same time, but
and exception can (magically) appear after a stackless resume)

Still have to write a test for that!

Please bug me if it's still too much of a hack!


Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Mon Feb 20 13:03:00 2006
@@ -80,10 +80,10 @@
         else:
             if self.stackless:
                 defines['USE_STACKLESS'] = '1'
+                defines['USE_OPTIMIZED_STACKLESS_UNWIND'] = '1'
                 if self.use_stackless_transformation: #set in test_stackless.py
                     from pypy.translator.backendopt.stackless import stackless
-                    from pypy.translator.c.stackless import StacklessData
-                    stackless(translator, StacklessData(db))
+                    stackless(translator, db.stacklessdata)
             cfile, extra = gen_source_standalone(db, modulename, targetdir,
                                                  entrypointname = pfname,
                                                  defines = defines)

Modified: pypy/dist/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/exception.h	(original)
+++ pypy/dist/pypy/translator/c/src/exception.h	Mon Feb 20 13:03:00 2006
@@ -20,16 +20,6 @@
 
 #define RPyExceptionOccurred()	(rpython_exc_type != NULL)
 
-#define RPyRaisePseudoException()               do {                           \
-            if (rpython_exc_type == NULL)                                      \
-               rpython_exc_type = (RPYTHON_EXCEPTION_VTABLE)&rpython_exc_type; \
-        } while (0)
-
-#define RPyExceptionClear()                     do {                            \
-            if (rpython_exc_type == (RPYTHON_EXCEPTION_VTABLE)&rpython_exc_type) \
-                rpython_exc_type = NULL;                                            \
-        } while (0)
-
 #define RPyRaiseException(etype, evalue)	do {	\
 		assert(!RPyExceptionOccurred());	\
 		rpython_exc_type = etype;		\

Modified: pypy/dist/pypy/translator/c/src/ll_stackless.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_stackless.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_stackless.h	Mon Feb 20 13:03:00 2006
@@ -16,6 +16,40 @@
 #endif
 
 
+#ifdef USE_OPTIMIZED_STACKLESS_UNWIND
+
+/* trickers RPyExceptionOccurred(), actual value should never be used! */
+#define RPyRaisePseudoException() do { \
+            assert(rpython_exc_type == NULL); \
+            rpython_exc_type = (RPYTHON_EXCEPTION_VTABLE)&rpython_exc_type; \
+        } while (0)
+
+#define RPyExceptionClear()       rpython_exc_type = NULL
+
+#define StacklessUnwindAndRPyExceptionHandling(unwind_label, resume_label, exception_label) \
+            if (RPyExceptionOccurred()) {   \
+                if (slp_frame_stack_bottom) \
+                    goto unwind_label;      \
+            resume_label:                   \
+                if (RPyExceptionOccurred()) \
+                    FAIL(exception_label);  \
+            }
+#else
+
+#define RPyRaisePseudoException()
+
+#define RPyExceptionClear()
+
+#define StacklessUnwindAndRPyExceptionHandling(unwind_label, resume_label, exception_label) do { \
+            if (slp_frame_stack_bottom)     \
+                goto unwind_label;          \
+            resume_label:                   \
+            if (RPyExceptionOccurred())     \
+                FAIL(exception_label);      \
+            } while (0)
+#endif
+
+
 typedef struct slp_frame_s {
   struct slp_frame_s *f_back;
   int state;
@@ -77,6 +111,7 @@
 
     slp_frame_stack_top = slp_frame_stack_bottom =
         slp_new_frame(sizeof(slp_frame_t), 0);
+    RPyRaisePseudoException();
     return ;
 
  resume:
@@ -90,6 +125,7 @@
   assert(slp_frame_stack_bottom != NULL);
   slp_frame_stack_bottom->f_back = slp_new_frame(sizeof(slp_frame_t), 3);
   slp_frame_stack_top = slp_frame_stack_bottom = NULL;  /* stop unwinding */
+  RPyExceptionClear();
   return (struct RPyOpaque_frame_stack_top *) result;
 }
 
@@ -114,6 +150,7 @@
 	f = slp_new_frame(sizeof(slp_frame_1ptr_t), 2);
 	((slp_frame_1ptr_t *) f)->p0 = c;
 	slp_frame_stack_top = slp_frame_stack_bottom = f;
+        RPyRaisePseudoException();
 	return NULL;
 
    resume:
@@ -138,6 +175,7 @@
 
 	slp_frame_stack_top = slp_frame_stack_bottom =
 		slp_new_frame(sizeof(slp_frame_t), 1);
+        RPyRaisePseudoException();
 	return -1;
 
  resume:
@@ -167,6 +205,7 @@
   while (1)
     {
       slp_frame_stack_bottom = NULL;
+      RPyExceptionClear();
       pending = slp_frame_stack_top;
 
       while (1)

Modified: pypy/dist/pypy/translator/c/stackless.py
==============================================================================
--- pypy/dist/pypy/translator/c/stackless.py	(original)
+++ pypy/dist/pypy/translator/c/stackless.py	Mon Feb 20 13:03:00 2006
@@ -331,12 +331,8 @@
 
         # add the checks for the unwinding case just after the directcall
         # in the source
-        unwind_check = "if (slp_frame_stack_bottom)\n\tgoto %s;" % (savelabel,)
-        exception_check = (super(SlpFunctionCodeGenerator, self)
-                           .check_directcall_result(op, err))
-        return '%s\n  %s:\n%s' % (unwind_check,
-                                    resumelabel,
-                                    exception_check)
+        return 'StacklessUnwindAndRPyExceptionHandling(%s,%s,%s);' % (
+            savelabel, resumelabel, err)
 
     def OP_YIELD_CURRENT_FRAME_TO_CALLER(self, op, err):
         # special handling of this operation: call stack_unwind() to force the



More information about the Pypy-commit mailing list