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

« back to all changes in this revision

Viewing changes to demo/uthread.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
"""This is an example that uses the (prototype) Logic Object Space. To run,
 
2
you have to set USE_GREENLETS in pypy.objspace.logic to True and do:
 
3
  
 
4
    $ py.py -o logic uthread.py
 
5
 
 
6
newvar creates a new unbound logical variable. If you try to access an unbound
 
7
variable, the current uthread is blocked, until the variable is bound.
 
8
"""
 
9
 
 
10
X = newvar()
 
11
Y = newvar()
 
12
 
 
13
bind(Y, X) # aliasing
 
14
 
 
15
def f():
 
16
    print "starting"
 
17
    print is_free(X)
 
18
    if Y:
 
19
        print "ok"
 
20
        return
 
21
    print "false"
 
22
    return
 
23
 
 
24
def bind():
 
25
    unify(X, 1)
 
26
 
 
27
uthread(f)
 
28
print "afterwards"
 
29
uthread(bind)