[pypy-svn] r25607 - in pypy/dist/pypy/translator/stackless: . test

mwh at codespeak.net mwh at codespeak.net
Sun Apr 9 10:54:14 CEST 2006


Author: mwh
Date: Sun Apr  9 10:54:12 2006
New Revision: 25607

Modified:
   pypy/dist/pypy/translator/stackless/code.py
   pypy/dist/pypy/translator/stackless/test/test_transform.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(hpk, mwh, pedronis consulting)
run the stackless main loop after the entry point has unwound.
cope with a small annotator boggle, see comments in test_transform.


Modified: pypy/dist/pypy/translator/stackless/code.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/code.py	(original)
+++ pypy/dist/pypy/translator/stackless/code.py	Sun Apr  9 10:54:12 2006
@@ -60,8 +60,8 @@
 def slp_main_loop():
     currentframe = global_state.top
     
-    while currentframe is not None:
-        nextframe = currentframe.f_back
+    while currentframe:
+        global_state.top = nextframe = currentframe.f_back
         framestate = currentframe.state
         fn, signature, global_state.restart_substate = decode_state(framestate)
         try:

Modified: pypy/dist/pypy/translator/stackless/test/test_transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/test/test_transform.py	Sun Apr  9 10:54:12 2006
@@ -30,6 +30,8 @@
 
 ##     assert s2_1 is s2_2
 
+from pypy.translator.stackless import code
+
 def test_simple_transform():
     from pypy.translator.stackless.code import UnwindException
     def check(x):
@@ -45,13 +47,30 @@
     
 def run_stackless_function(fn, *stacklessfuncs):
     def entry_point(argv):
-        os.write(1, str(fn(len(argv)))+'\n')
+        try:
+            r = fn(len(argv))
+        except code.UnwindException, u:
+            code.global_state.top = u.frame_top
+            code.slp_main_loop()
+            r = code.global_state.retval_long
+        os.write(1, str(r)+'\n')
         return 0
 
     s_list_of_strings = annmodel.SomeList(ListDef(None, annmodel.SomeString()))
     s_list_of_strings.listdef.resize()
     t = TranslationContext()
-    t.buildannotator().build_types(entry_point, [s_list_of_strings])
+    annotator = t.buildannotator()
+    bk = annotator.bookkeeper
+    # we want to make sure that the annotator knows what
+    # code.UnwindException looks like very early on, because otherwise
+    # it can get mutated during the annotation of the low level
+    # helpers which can cause slp_main_loop to get re-annotated after
+    # it is rtyped.  which is bad.
+    unwind_def = bk.getuniqueclassdef(code.UnwindException)
+    unwind_def.generalize_attr('frame_top', annmodel.SomePtr(lltype.Ptr(code.STATE_HEADER)))
+    unwind_def.generalize_attr('frame_bottom', annmodel.SomePtr(lltype.Ptr(code.STATE_HEADER)))
+    
+    annotator.build_types(entry_point, [s_list_of_strings])
     t.buildrtyper().specialize()
 
     st = StacklessTransfomer(t)

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Sun Apr  9 10:54:12 2006
@@ -93,14 +93,6 @@
         mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
         l2a = annmodel.lltype_to_annotation
 
-        slp_main_loop_graph = mixlevelannotator.getgraph(
-            code.slp_main_loop, [], l2a(lltype.Void))
-        SLP_MAIN_LOOP_TYPE = lltype.FuncType([], lltype.Void)
-        self.slp_main_loop_type_ptr = model.Constant(lltype.functionptr(
-            SLP_MAIN_LOOP_TYPE, "slp_main_loop",
-            graph=slp_main_loop_graph),
-            lltype.Ptr(SLP_MAIN_LOOP_TYPE))
-
         annotations = [annmodel.SomeInstance(bk.getuniqueclassdef(code.UnwindException)),
                        annmodel.SomePtr(lltype.Ptr(STATE_HEADER))]
 



More information about the Pypy-commit mailing list