[pypy-svn] r26901 - in pypy/dist/pypy: rpython translator/stackless translator/stackless/test

arigo at codespeak.net arigo at codespeak.net
Sat May 6 22:50:06 CEST 2006


Author: arigo
Date: Sat May  6 22:50:05 2006
New Revision: 26901

Modified:
   pypy/dist/pypy/rpython/annlowlevel.py
   pypy/dist/pypy/translator/stackless/test/test_depth.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(pedronis, arigo)
Start supporting programs that use the native rpython.rstack interface
instead of their code.*() equivalents.



Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py	(original)
+++ pypy/dist/pypy/rpython/annlowlevel.py	Sat May  6 22:50:05 2006
@@ -116,7 +116,7 @@
     def __init__(self, rtyper):
         self.rtyper = rtyper
         self.policy = MixLevelAnnotatorPolicy(rtyper)
-        self.pending = []     # list of (graph, args_s, s_result)
+        self.pending = []     # list of (ll_function, graph, args_s, s_result)
         self.delayedreprs = []
         self.delayedconsts = []
         self.delayedfuncs = []
@@ -131,7 +131,7 @@
         for v_arg, s_arg in zip(graph.getargs(), args_s):
             self.rtyper.annotator.setbinding(v_arg, s_arg)
         self.rtyper.annotator.setbinding(graph.getreturnvar(), s_result)
-        self.pending.append((graph, args_s, s_result))
+        self.pending.append((ll_function, graph, args_s, s_result))
         return graph
 
     def delayedfunction(self, ll_function, args_s, s_result):
@@ -172,15 +172,17 @@
         # push all the graphs into the annotator's pending blocks dict at once
         rtyper = self.rtyper
         ann = rtyper.annotator
-        for graph, args_s, s_result in self.pending:
+        bk = ann.bookkeeper
+        for ll_function, graph, args_s, s_result in self.pending:
             # mark the return block as already annotated, because the return var
             # annotation was forced in getgraph() above.  This prevents temporary
             # less general values reaching the return block from crashing the
             # annotator (on the assert-that-new-binding-is-not-less-general).
             ann.annotated[graph.returnblock] = graph
-            ann.build_graph_types(graph, args_s, complete_now=False)
+            s_function = bk.immutablevalue(ll_function)
+            bk.emulate_pbc_call(graph, s_function, args_s)
         ann.complete_helpers(self.policy)
-        for graph, args_s, s_result in self.pending:
+        for ll_function, graph, args_s, s_result in self.pending:
             s_real_result = ann.binding(graph.getreturnvar())
             if s_real_result != s_result:
                 raise Exception("wrong annotation for the result of %r:\n"

Modified: pypy/dist/pypy/translator/stackless/test/test_depth.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_depth.py	(original)
+++ pypy/dist/pypy/translator/stackless/test/test_depth.py	Sat May  6 22:50:05 2006
@@ -1,90 +1,100 @@
 from pypy.translator.stackless.test.test_transform import \
      llinterp_stackless_function, run_stackless_function
 from pypy.translator.stackless import code
+from pypy.rpython import rstack
 import py
 import os
 
-def test_simple():
-    def g1():
-        "just to check Void special cases around the code"
-    def g2(ignored):
-        pass
-        g1()
-    def f(n):
-        g1()
-        if n > 0:
-            res = f(n-1)
-        else:
-            res = code.stack_frames_depth()
-        g2(g1)
-        return res
-
-    def fn(ignored):
-        count0 = f(0)
-        count10 = f(10)
-        return count10 - count0
-
-    res = llinterp_stackless_function(fn)
-    assert res == 10
-
-    res = run_stackless_function(fn)
-    assert res.strip() == "10"
-
-def test_with_ptr():
-    def f(n):
-        if n > 0:
-            res = f(n-1)
-        else:
-            res = code.stack_frames_depth(), 1
-        return res
-
-    def fn(ignored):
-        count0, _ = f(0)
-        count10, _ = f(10)
-        return count10 - count0
-
-    res = llinterp_stackless_function(fn)
-    assert res == 10
-
-    res = run_stackless_function(fn)
-    assert res.strip() == "10"
-
-def test_manytimes():
-    def f(n):
-        if n > 0:
-            res = f(n-1)
-        else:
-            res = code.stack_frames_depth(), 1
-        return res
-
-    def fn(ignored):
-        count0, _ = f(0)
-        count10, _ = f(100)
-        return count10 - count0
-
-    res = llinterp_stackless_function(fn)
-    assert res == 100
-
-    res = run_stackless_function(fn)
-    assert res.strip() == "100"
-
-def test_arguments():
-    def f(n, d, t):
-        if n > 0:
-            res = f(n-1, d, t)
-        else:
-            res = code.stack_frames_depth(), d, t
-        return res
-
-    def fn(ignored):
-        count0, d, t = f(0, 5.5, (1, 2))
-        count10, d, t = f(10, 5.5, (1, 2))
-        return count10 - count0 + int(d)
-
-    res = llinterp_stackless_function(fn)
-    assert res == 15
-
-    res = run_stackless_function(fn)
-    assert res.strip() == "15"
-    
 
+class TestFromCode:
+    stack_frames_depth = staticmethod(code.stack_frames_depth)
+
+    def _freeze_(self):
+        return True
+
+    def test_simple(self):
+        def g1():
+            "just to check Void special cases around the code"
+        def g2(ignored):
+            pass
+            g1()
+        def f(n):
+            g1()
+            if n > 0:
+                res = f(n-1)
+            else:
+                res = self.stack_frames_depth()
+            g2(g1)
+            return res
+
+        def fn(ignored):
+            count0 = f(0)
+            count10 = f(10)
+            return count10 - count0
+
+        res = llinterp_stackless_function(fn)
+        assert res == 10
+
+        res = run_stackless_function(fn)
+        assert res.strip() == "10"
+
+    def test_with_ptr(self):
+        def f(n):
+            if n > 0:
+                res = f(n-1)
+            else:
+                res = self.stack_frames_depth(), 1
+            return res
+
+        def fn(ignored):
+            count0, _ = f(0)
+            count10, _ = f(10)
+            return count10 - count0
+
+        res = llinterp_stackless_function(fn)
+        assert res == 10
+
+        res = run_stackless_function(fn)
+        assert res.strip() == "10"
+
+    def test_manytimes(self):
+        def f(n):
+            if n > 0:
+                res = f(n-1)
+            else:
+                res = self.stack_frames_depth(), 1
+            return res
+
+        def fn(ignored):
+            count0, _ = f(0)
+            count10, _ = f(100)
+            return count10 - count0
+
+        res = llinterp_stackless_function(fn)
+        assert res == 100
+
+        res = run_stackless_function(fn)
+        assert res.strip() == "100"
+
+    def test_arguments(self):
+        def f(n, d, t):
+            if n > 0:
+                res = f(n-1, d, t)
+            else:
+                res = self.stack_frames_depth(), d, t
+            return res
+
+        def fn(ignored):
+            count0, d, t = f(0, 5.5, (1, 2))
+            count10, d, t = f(10, 5.5, (1, 2))
+            return count10 - count0 + int(d)
+
+        res = llinterp_stackless_function(fn)
+        assert res == 15
+
+        res = run_stackless_function(fn)
+        assert res.strip() == "15"
+
+
+class TestFromRStack(TestFromCode):
+    stack_frames_depth = staticmethod(rstack.stack_frames_depth)

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Sat May  6 22:50:05 2006
@@ -10,6 +10,7 @@
 from pypy.rpython.rclass import getinstancerepr
 from pypy.rpython.rbuiltin import gen_cast
 from pypy.rpython.rtyper import LowLevelOpList
+from pypy.rpython.module import ll_stackless
 
 from pypy.translator.stackless.code import STATE_HEADER, null_state
 
@@ -117,6 +118,14 @@
         self.fetch_retval_void_p_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_void_p, [], annmodel.SomeAddress())
 
+        s_StatePtr = annmodel.SomePtr(lltype.Ptr(code.STATE_HEADER))
+        self.stack_frames_depth_ptr = mixlevelannotator.constfunc(
+            code.stack_frames_depth, [], annmodel.SomeInteger())
+##        self.yield_current_frame_to_caller_ptr = mixlevelannotator.constfunc(
+##            code.yield_current_frame_to_caller, [], s_StatePtr)
+##        self.ll_frame_switch_ptr = mixlevelannotator.constfunc(
+##            code.ll_frame_switch, [s_StatePtr], s_StatePtr)
+
         mixlevelannotator.finish()
 
         s_global_state = bk.immutablevalue(code.global_state)
@@ -323,6 +332,15 @@
         while i < len(block.operations):
             op = block.operations[i]
             if op.opname in ('direct_call', 'indirect_call'):
+                # trap calls to stackless-related suggested primitives
+                if op.opname == 'direct_call':
+                    func = getattr(op.args[0].value._obj, '_callable', None)
+                    if func is ll_stackless.ll_stackless_stack_frames_depth:
+                        op = model.SpaceOperation(
+                            'direct_call', [self.stack_frames_depth_ptr],
+                            op.result)
+                        block.operations[i] = op
+
                 if i == len(block.operations) - 1 \
                        and block.exitswitch == model.c_last_exception:
                     link = block.exits[0]



More information about the Pypy-commit mailing list