3 # Set up a PAST data structure that represents a sub and run it.
5 # code for (assuming package scoped variables)
8 # a dump of the PAST looks like this:
12 "stmts" => PMC 'PAST::Stmts' {
15 [0] => PMC 'PAST::Op' {
18 [0] => PMC 'PAST::Op' {
20 [0] => PMC 'PAST::Var' {
25 [1] => PMC 'PAST::Op' {
32 [0] => PMC 'PAST::Val' {
34 <returns> => "Integer"
38 [1] => PMC 'PAST::Val' {
40 <returns> => "Integer"
51 .include "library/dumper.pir"
56 load_bytecode 'PGE.pbc'
57 load_bytecode 'PGE/Text.pbc'
58 load_bytecode 'PGE/Util.pbc'
59 load_bytecode 'PGE/Dumper.pbc'
60 load_bytecode 'PCT.pbc'
66 val_4 = new 'PAST::Val'
67 val_4.init( 'value' => '4', 'returns' => 'Integer' )
70 val_1 = new 'PAST::Val'
71 val_1.init( 'value' => '1', 'returns' => 'Integer' )
74 op_add = new 'PAST::Op'
75 op_add.init( val_4, val_1, 'name' => 'infix:+', 'pirop' => 'n_add' )
78 var_last = new 'PAST::Var'
79 var_last.init( 'name' => 'last', 'scope' => 'package', 'lvalue' => 1 )
82 op_bind = new 'PAST::Op'
83 op_bind.init( var_last, op_add, 'pasttype' => 'bind' )
86 op_say = new 'PAST::Op'
87 op_say.init( op_bind, 'name' => 'say', 'pasttype' => 'call' )
90 stmts = new 'PAST::Stmts'
91 stmts.'init'( op_say, 'name'=>'stmts' )
93 # compile to PIR and display
94 .local pmc astcompiler
95 astcompiler = new [ 'PCT::HLLCompiler' ]
96 astcompiler.'removestage'('parse')
97 astcompiler.'removestage'('past')
99 astcompiler.'eval'(stmts)
101 # _dumper( stmts, 'stmts' )
102 # _dumper( astcompiler, 'astcompiler' )
105 # ost = astcompiler.'post'(stmts)
106 # _dumper( ost, 'ost' )
109 # pir = astcompiler.'pir'(ost)
110 # _dumper( pir, 'pir' )
117 .param pmc args :slurpy
118 if null args goto end
120 iter = new 'Iterator', args
135 # vim: expandtab shiftwidth=4 ft=pir: