[pypy-svn] r18461 - in pypy/dist/pypy: rpython rpython/module translator translator/c translator/c/src

dialtone at codespeak.net dialtone at codespeak.net
Wed Oct 12 12:54:27 CEST 2005


Author: dialtone
Date: Wed Oct 12 12:54:23 2005
New Revision: 18461

Added:
   pypy/dist/pypy/rpython/module/ll_stack.py
Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_stackless.py
   pypy/dist/pypy/rpython/objectmodel.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/g_include.h
   pypy/dist/pypy/translator/c/src/ll_stackless.h
   pypy/dist/pypy/translator/c/src/stack.h
   pypy/dist/pypy/translator/transform.py
Log:
generalize auto_stack_unwind to stack_check so that it can be used also when
stackless mode is not enabled. It will raise a RuntimeError in that case [need
test].


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Wed Oct 12 12:54:23 2005
@@ -209,8 +209,9 @@
 # stackless
 from pypy.rpython import objectmodel
 declare(objectmodel.stack_frames_depth, int, 'll_stackless/stack_frames_depth')
-declare(objectmodel.stack_too_big, bool, 'll_stackless/stack_too_big')
-declare(objectmodel.auto_stack_unwind, noneannotation, 'll_stackless/auto_stack_unwind')
+declare(objectmodel.stack_too_big, bool, 'll_stack/too_big')
+declare(objectmodel.stack_check, noneannotation, 'll_stack/check')
+declare(objectmodel.stack_unwind, noneannotation, 'll_stack/unwind')
 
 # ___________________________________________________________
 # the exceptions that can be implicitely raised by some operations
@@ -226,4 +227,5 @@
     KeyError         : True,
     IndexError       : True,
     AssertionError   : True,
+    RuntimeError     : True,
     }

Added: pypy/dist/pypy/rpython/module/ll_stack.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/module/ll_stack.py	Wed Oct 12 12:54:23 2005
@@ -0,0 +1,14 @@
+from pypy.rpython import objectmodel
+
+def ll_stack_too_big():
+    return objectmodel.stack_too_big()
+ll_stack_too_big.suggested_primitive = True
+
+def ll_stack_unwind():
+    objectmodel.stack_unwind()
+ll_stack_unwind.suggested_primitive = True
+
+def ll_stack_check():
+    if ll_stack_too_big():
+        ll_stack_unwind()
+

Modified: pypy/dist/pypy/rpython/module/ll_stackless.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_stackless.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_stackless.py	Wed Oct 12 12:54:23 2005
@@ -1,18 +1,5 @@
 from pypy.rpython import objectmodel
 
-
-def ll_stackless_stack_unwind():
-    pass
-ll_stackless_stack_unwind.suggested_primitive = True
-
 def ll_stackless_stack_frames_depth():
     return objectmodel.stack_frames_depth()
 ll_stackless_stack_frames_depth.suggested_primitive = True
-
-def ll_stackless_stack_too_big():
-    return objectmodel.stack_too_big()
-ll_stackless_stack_too_big.suggested_primitive = True
-
-def ll_stackless_auto_stack_unwind():
-    if ll_stackless_stack_too_big():
-        ll_stackless_stack_unwind()

Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py	(original)
+++ pypy/dist/pypy/rpython/objectmodel.py	Wed Oct 12 12:54:23 2005
@@ -47,9 +47,13 @@
 def stack_too_big():
     return False
 
-def auto_stack_unwind():
+def stack_check():
     if stack_too_big():
+        # stack_unwind implementation is different depending on if stackless
+        # is enabled. If it is it unwinds the stack, otherwise it simply
+        # raises a RuntimeError.
         stack_unwind()
+
 # ____________________________________________________________
 
 

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Wed Oct 12 12:54:23 2005
@@ -4,7 +4,8 @@
 from pypy.rpython.rmodel import getfunctionptr
 from pypy.rpython.rstr import STR
 from pypy.rpython import rlist
-from pypy.rpython.module import ll_os, ll_time, ll_math, ll_strtod, ll_stackless
+from pypy.rpython.module import ll_os, ll_time, ll_math, ll_strtod
+from pypy.rpython.module import ll_stackless, ll_stack
 from pypy.module.thread.rpython import ll_thread
 
 
@@ -50,8 +51,8 @@
     ll_thread.ll_thread_start:     'LL_thread_start',
     ll_thread.ll_thread_get_ident: 'LL_thread_get_ident',
     ll_stackless.ll_stackless_stack_frames_depth: 'LL_stackless_stack_frames_depth',
-    ll_stackless.ll_stackless_stack_unwind: 'LL_stackless_stack_unwind',
-    ll_stackless.ll_stackless_stack_too_big: 'LL_stackless_stack_too_big',
+    ll_stack.ll_stack_unwind: 'LL_stack_unwind',
+    ll_stack.ll_stack_too_big: 'LL_stack_too_big',
     }
 
 #______________________________________________________

Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h	(original)
+++ pypy/dist/pypy/translator/c/src/g_include.h	Wed Oct 12 12:54:23 2005
@@ -41,6 +41,8 @@
 #  include "src/ll_stackless.h"
 #endif
 
+#include "src/stack.h"
+
 #ifdef PYPY_STANDALONE
 #  include "src/main.h"
 #endif

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	Wed Oct 12 12:54:23 2005
@@ -5,10 +5,6 @@
 #  error "Stackless support: only for stand-alone executables"
 #endif
 
-#ifndef MAX_STACK_SIZE
-#    define MAX_STACK_SIZE (1 << 20)
-#endif
-
 #define STANDALONE_ENTRY_POINT   slp_standalone_entry_point
 
 
@@ -32,7 +28,6 @@
 extern long slp_retval_long;
 extern double slp_retval_double;
 extern void *slp_retval_voidptr;
-extern char *slp_base_stack_pointer;
 
 slp_frame_t* slp_new_frame(int size, int state);
 long LL_stackless_stack_frames_depth(void);
@@ -49,7 +44,6 @@
 long slp_retval_long;
 double slp_retval_double;
 void *slp_retval_voidptr;
-char *slp_base_stack_pointer = NULL;
 
 slp_frame_t* slp_new_frame(int size, int state)
 {
@@ -100,25 +94,8 @@
     }
 }
 
-
-char LL_stackless_stack_too_big(void)
-{
-  char local;
-  long result;
-  int simple_check = MAX_STACK_SIZE / 2;
-  /* compute the difference between local variable and
-   * and a stack origin pointer
-   */
-  result = &local - slp_base_stack_pointer;
-  if (-simple_check < result && result < simple_check){
-    return 0;
-  }
-  return 1;
-}
-
 #include "slp_state_decoding.h"
 
-
 void slp_main_loop(void)
 {
   int state, signature;
@@ -168,9 +145,7 @@
 
 int slp_standalone_entry_point(RPyListOfString *argv)
 {
-	char local;
 	int result;
-	slp_base_stack_pointer = &local;
 	result = PYPY_STANDALONE(argv);
 	if (slp_frame_stack_bottom) {
 		slp_main_loop();

Modified: pypy/dist/pypy/translator/c/src/stack.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/stack.h	(original)
+++ pypy/dist/pypy/translator/c/src/stack.h	Wed Oct 12 12:54:23 2005
@@ -2,13 +2,28 @@
 /************************************************************/
  /***  C header subsection: stack operations               ***/
 
-static stack_base_pointer = NULL;
+#ifndef MAX_STACK_SIZE
+#    define MAX_STACK_SIZE (1 << 19)
+#endif
+
+char LL_stack_too_big(void);
+
+#ifndef PYPY_NOT_MAIN_FILE
+
+void LL_stack_unwind(void)
+{
+#ifdef USE_STACKLESS
+    LL_stackless_stack_unwind();
+#else
+	RPyRaiseSimpleException(PyExc_RuntimeError, "Recursion limit exceeded");
+#endif
+}
 
 char LL_stack_too_big(void)
 {
   char local;
   long result;
-  int simple_check = MAX_STACK_SIZE / 2;
+  static char *stack_base_pointer = NULL;
 
   if( stack_base_pointer == NULL )
 	  stack_base_pointer = &local;
@@ -16,13 +31,10 @@
   /* compute the difference between local variable and
    * and a stack origin pointer
    */
-  result = &local - slp_base_stack_pointer;
-  if (-simple_check < result && result < simple_check){
+  result = &local - stack_base_pointer;
+  if (-MAX_STACK_SIZE < result && result < MAX_STACK_SIZE){
     return 0;
   }
   return 1;
 }
-
-
-
-
+#endif

Modified: pypy/dist/pypy/translator/transform.py
==============================================================================
--- pypy/dist/pypy/translator/transform.py	(original)
+++ pypy/dist/pypy/translator/transform.py	Wed Oct 12 12:54:23 2005
@@ -14,7 +14,7 @@
 from pypy.translator.annrpython import CannotSimplify
 from pypy.annotation import model as annmodel
 from pypy.annotation.specialize import MemoTable
-from pypy.rpython.objectmodel import auto_stack_unwind
+from pypy.rpython.objectmodel import stack_check
 
 def checkgraphs(self, blocks):
     seen = {}
@@ -202,13 +202,13 @@
             _, caller_block, _ = call_tag
         else:
             ann.warning("cycle detected but no information on where to insert "
-                        "auto_stack_unwind()")
+                        "stack_check()")
             continue
-        # caller block found, insert auto_stack_unwind()
+        # caller block found, insert stack_check()
         v = Variable()
         # push annotation on v
         ann.setbinding(v, annmodel.SomeImpossibleValue())
-        unwind_op = SpaceOperation('simple_call', [Constant(auto_stack_unwind)], v)
+        unwind_op = SpaceOperation('simple_call', [Constant(stack_check)], v)
         caller_block.operations.insert(0, unwind_op)
 
 default_extra_passes = [



More information about the Pypy-commit mailing list