~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/translator/stackless/test/test_clone.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pypy.translator.stackless.test.test_transform import \
 
2
     llinterp_stackless_function, run_stackless_function
 
3
from pypy.rlib import rstack
 
4
 
 
5
 
 
6
def test_simple():
 
7
    import py; py.test.skip("to be rewritten with gc_x_clone")
 
8
    def g(lst):
 
9
        lst.append(1)
 
10
        parent = rstack.yield_current_frame_to_caller()
 
11
        # compute a bit
 
12
        lst.append(3)
 
13
        # switch back for the fork
 
14
        parent = parent.switch()
 
15
        lst.append(6)   # we are here twice!
 
16
        return parent
 
17
 
 
18
    def f():
 
19
        lst = []
 
20
        c = g(lst)
 
21
        lst.append(2)
 
22
        c1 = c.switch()
 
23
        lst.append(4)
 
24
        c2 = c1.clone()      # clone() here
 
25
        lst.append(5)
 
26
        end1 = c1.switch()
 
27
        lst.append(7)
 
28
        end2 = c2.switch()
 
29
        lst.append(8)
 
30
        assert not end1
 
31
        assert not end2
 
32
        n = 0
 
33
        for i in lst:
 
34
            n = n*10 + i
 
35
        return n
 
36
 
 
37
    data = llinterp_stackless_function(f)
 
38
    assert data == 123456768
 
39
 
 
40
    res = run_stackless_function(f)
 
41
    assert res == 123456768