Ticket #1537: test.pir

File test.pir, 0.8 KB (added by arnsholt, 4 years ago)
Line 
1.sub 'choose'
2    .param pmc options :slurpy
3    .local pmc cc
4    .local pmc chosen
5    .local pmc paths
6
7    if options goto got_options
8    'fail'()
9  got_options:
10    chosen = shift options
11
12    cc = new 'Continuation'
13    set_addr cc, recurse
14    paths = get_global '!paths'
15    push paths, cc
16
17    .return (chosen)
18
19  recurse:
20    .tailcall 'choose'(options :flat)
21.end
22
23.sub 'fail'
24    .local pmc cc
25    .local pmc paths
26
27    paths = get_global '!paths'
28    cc = pop paths
29
30    cc()
31.end
32
33.sub 'main' :main
34    .local pmc cc
35    .local pmc paths
36    .local pmc val
37
38    paths = new 'ResizablePMCArray'
39    set_global '!paths', paths
40
41    cc = new 'Continuation'
42    push paths, cc
43    set_addr cc, final_failure
44
45    val= 'choose'("foo", "bar")
46    say val
47
48    'fail'()
49  final_failure:
50    say 'Done.'
51.end