1 # Copyright (C) 2006-2008, Parrot Foundation.
6 The PAST that is set up in this example
7 roughly represents following Perl 6 code:
21 load_bytecode "dumper.pbc"
22 load_bytecode 'PGE.pbc'
23 load_bytecode 'PGE/Text.pbc'
24 load_bytecode 'PGE/Util.pbc'
25 load_bytecode 'PGE/Dumper.pbc'
26 load_bytecode 'PCT.pbc'
33 block = new ['PAST';'Block']
34 block.'init'( 'blocktype' => 'declaration', 'name' => 'foo' )
35 block.'symbol'( '$a', 'scope' => 'lexical' )
36 block.'symbol'( '$b', 'scope' => 'lexical' )
39 stmts = new ['PAST';'Stmts']
41 stmts.'attr'( 'source', 'my $a = 4; my $b = $a + 1; say( $b );', 1 )
45 $P0 = new ['PAST';'Val']
46 $P0.'init'( 'value' => '4', 'returns' => 'Integer' )
47 $P0.'attr'( 'source', '4', 1 )
48 $P1 = new ['PAST';'Var']
49 $P1.'init'( 'name' => '$a', 'viviself' => 'Undef', 'isdecl' => 1 )
50 $P1.'attr'( 'source', '$a', 1 )
51 $P2 = new ['PAST';'Op']
52 $P2.'init'( $P1, $P0, 'pasttype' => 'copy', 'name' => 'infix:=', 'lvalue' => 1 )
53 $P2.'attr'( 'source', '=', 1 )
57 $P0 = new ['PAST';'Var']
58 $P0.'init'( 'name' => '$a', 'viviself' => 'Undef' )
59 $P1 = new ['PAST';'Val']
60 $P1.'init'( 'value' => '1', 'returns' => 'Integer')
61 $P2 = new ['PAST';'Op']
62 $P2.'init'( $P0, $P1, 'name' => 'infix:+', 'pirop' => 'add')
63 $P3 = new ['PAST';'Var']
64 $P3.'init'( 'name' => '$b', 'viviself' => 'Undef', 'isdecl' => 1 )
65 $P4 = new ['PAST';'Op']
66 $P4.'init'( $P3, $P2, 'name' => 'infix:=', 'pasttype' => 'copy')
67 $P4.'attr'( 'source', '=', 1 )
71 $P0 = new ['PAST';'Var']
72 $P0.'init'( 'name' => '$b' )
73 $P1 = new ['PAST';'Op']
74 $P1.'init'( $P0, 'name' => 'say', 'pasttype' => 'call' )
77 # set up compiler, preliminary stages are removed because we
78 # already have a PAST data structure
79 .local pmc astcompiler
80 astcompiler = new [ 'PCT';'HLLCompiler' ]
81 astcompiler.'removestage'('parse')
82 astcompiler.'removestage'('past')
86 # _dumper( block, 'block' )
88 # compile to PIR and display
89 $S99 = astcompiler.'compile'(block, 'target' => 'pir')
94 #compile to bytecode and execute
95 $P99 = astcompiler.'compile'(block)
101 .param pmc args :slurpy
102 if null args goto end
119 # vim: expandtab shiftwidth=4 ft=pir: