[pypy-svn] r25526 - in pypy/branch/stacklesscfg/pypy/translator/stackless: . test

hpk at codespeak.net hpk at codespeak.net
Fri Apr 7 20:54:07 CEST 2006


Author: hpk
Date: Fri Apr  7 20:54:06 2006
New Revision: 25526

Modified:
   pypy/branch/stacklesscfg/pypy/translator/stackless/code.py
   pypy/branch/stacklesscfg/pypy/translator/stackless/test/test_transform.py
   pypy/branch/stacklesscfg/pypy/translator/stackless/transform.py
Log:
progressing a bit more towards the stackless loop and passing
a small example - but the graphs are still not completely
valid -> but dinner now :) 


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	Fri Apr  7 20:54:06 2006
@@ -21,10 +21,6 @@
 
 global_state = StacklessData()
 
-class UnwindException(Exception):
-    def __init__(self):
-        self.frame = null_state
-
 void_void_func = lltype.Ptr(lltype.FuncType([], lltype.Void))
 long_void_func = lltype.Ptr(lltype.FuncType([], lltype.Signed))
 longlong_void_func = lltype.Ptr(lltype.FuncType([], lltype.SignedLongLong))
@@ -53,33 +49,33 @@
 def decode_state(state):
     return null_address, 'void', 0
 
+class UnwindException(Exception):
+    def __init__(self):
+        self.frame_top = null_state   # points to frame that first caught 
+                                      # the UnwindException 
+        self.frame_bottom = null_state 
+        # walking frame_top.f_back.f_back... goes to frame_bottom 
+        #
+
 def slp_main_loop():
-    while 1:
-        pending = global_state.top
-        while 1:
-            back = pending.f_back
-
-            state = pending.state
-            fn, signature, global_state.restart_substate = decode_state(state)
-
-            try:
-                call_function(fn, signature)
-            #except Exception, e: #KeyError, u: # XXX should be UnwindException 
-            #    #pending = u.frame
-            #    break
-            except Exception, e:
-                global_state.exception = e
-            else:
-                global_state.exception = None
-
-            if not back:
-                if global_state.exception:
-                    raise global_state.exception
-                return
-
-            pending = back
-            global_state.top = pending
-
-        if global_state.bottom:
-            assert global_state.bottom.f_back is None
-            global_state.bottom.f_back = back
+    currentframe = global_state.top
+    
+    while currentframe is not None:
+        nextframe = currentframe.f_back
+        framestate = currentframe.state
+        fn, signature, global_state.restart_substate = decode_state(framestate)
+        try:
+            call_function(fn, signature)
+        except UnwindException, u:   #XXX annotation support needed 
+            nextframe = u.frame_top 
+        except Exception, e:
+            global_state.exception = e
+        else:
+            global_state.exception = None
+
+        currentframe = nextframe 
+
+    if global_state.exception is not None:
+        raise global_state.exception
+
+

Modified: pypy/branch/stacklesscfg/pypy/translator/stackless/test/test_transform.py
==============================================================================
--- pypy/branch/stacklesscfg/pypy/translator/stackless/test/test_transform.py	(original)
+++ pypy/branch/stacklesscfg/pypy/translator/stackless/test/test_transform.py	Fri Apr  7 20:54:06 2006
@@ -2,6 +2,7 @@
 from pypy.rpython.memory.gctransform import varoftype
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.translator.translator import TranslationContext, graphof
+from pypy.objspace.flow.model import checkgraph
 from pypy import conftest
 
 ## def test_frame_types():
@@ -25,16 +26,26 @@
 ##     assert s2_1 is s2_2
 
 def test_simple_transform():
-    def g():
+    from pypy.translator.stackless.code import UnwindException
+    def check(x):
+        if x:
+            raise UnwindException # XXX or so
+    def g(x):
+        check(x)
         return 2
     def example(x):
-        return g() + x + 1
+        return g(x) + x + 1
     t = TranslationContext()
     t.buildannotator().build_types(example, [int])
     t.buildrtyper().specialize()
-    example_graph = graphof(t, example)
     st = StacklessTransfomer(t)
-    st.transform_graph(example_graph)
+    st.transform_graph(graphof(t, example))
+    st.transform_graph(graphof(t, g))
+    st.transform_graph(graphof(t, check))
+    #for graph in t.graphs: 
+        #checkgraph(graph) # XXX
+        #st.transform_graph(graph)
+    example_graph = graphof(t, example)
     if conftest.option.view:
         t.view()
     

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	Fri Apr  7 20:54:06 2006
@@ -1,5 +1,5 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rpython import rarithmetic
+from pypy.rpython import rarithmetic, rclass
 from pypy.translator.backendopt import support
 from pypy.objspace.flow import model
 from pypy.rpython.memory.gctransform import varoftype
@@ -143,9 +143,14 @@
                 
                 save_block = self.generate_save_block(link.args, var_unwind_exception)
 
-                newlink = model.Link(link.args + [var_unwind_exception], save_block, model.Constant(SystemExit))
+                newlink = model.Link(link.args + [var_unwind_exception], 
+                                     save_block, code.UnwindException)
+                r_case = rclass.get_type_repr(self.translator.rtyper)
+                newlink.llexitcase = r_case.convert_const(newlink.exitcase)
                 block.exitswitch = model.c_last_exception
-                block.exits.append(newlink)
+                block.recloseblock(link, newlink) # exits.append(newlink)
+    # ARGH ... 
+
                 block = after_block
                 i = 0
             else:
@@ -159,7 +164,8 @@
         var_unwind_exception0 = copyvar(self.translator, var_unwind_exception)
         from pypy.rpython.rclass import getinstancerepr
         var_unwind_exception = varoftype(getinstancerepr(self.translator.rtyper,
-            self.translator.annotator.bookkeeper.getuniqueclassdef(SystemExit)).lowleveltype)
+            self.translator.annotator.bookkeeper.getuniqueclassdef(
+                code.UnwindException)).lowleveltype)
 
         fields = []
         for i, v in enumerate(varstosave):



More information about the Pypy-commit mailing list