-
Notifications
You must be signed in to change notification settings - Fork 138
/
coroutine.pasm
58 lines (41 loc) · 974 Bytes
/
coroutine.pasm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Copyright (C) 2001-2005, Parrot Foundation.
=head1 NAME
examples/pasm/coroutine.pasm - Sample co-routines in Parrot
=head1 SYNOPSIS
% ./parrot examples/pasm/coroutine.pasm
=head1 DESCRIPTION
This shows you how to create two coroutines and C<invoke> them.
=head1 SEE ALSO
F<docs/ops/core.pod>
F<docs/pdds/pdd03_calling_conventions.pod>
=cut
.pcc_sub :main main:
# create a coro and save it on the user stack
.const 'Sub' P0 = "MYCOROUTINE"
# a coroutine carries state - clone it
clone P0, P0
# create a second coro
clone P1, P0
# Calling convention says P0 will contain the sub so..
print "Calling 1st co-routine\n"
invokecc P0
invokecc P0
invokecc P0
print "Calling 2nd co-routine\n"
invokecc P1
invokecc P1
invokecc P1
end
# A coroutine
.pcc_sub MYCOROUTINE:
print "Entry\n"
yield
print "Resumed\n"
yield
print "Done\n"
yield
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: