Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 44 lines (35 sloc) 1.025 kb
b43cb55 Add #!, copyright, Id, and coda to PAST::Transformer::Dynamic example.
tcurtis authored
1 #!./parrot-nqp
2 # Copyright (C) 2010, Parrot Foundation.
3 # $Id$
4
c061861 Regen manifest, add PAST::Transformer::Dynamic and example, and set prop...
tcurtis authored
5 pir::load_bytecode('PCT.pbc');
6 pir::load_bytecode('PAST/Transformer/Dynamic.pbc');
7 pir::load_bytecode('Data/Dumper.pbc');
8
9 sub foldOp ($walker, $node) {
10 if ($node.pirop() eq 'add') &&
11 ($node[0] ~~ PAST::Val) &&
12 ($node[1] ~~ PAST::Val) {
13 my $val := $node[0].value() + $node[1].value();
14 my $result := PAST::Val.new(:value($val));
15 $result;
16 }
17 else {
18 my $children := PAST::Walker::walkChildren($walker, $node);
19 PAST::Walker::replaceChildren($node, $children);
20 $node;
21 }
22 }
23
24 my $comp := Q:PIR { %r = compreg 'NQP-rx' };
25 my $past := $comp.compile('say(1+2);', :target<past>);
26
27 my $dumper := Q:PIR { %r = new ['Data';'Dumper'] };
28 $dumper.dumper($past);
29
30 say("\nChanging:\n");
31
32 my $walker := Q:PIR { %r = new ['PAST'; 'Transformer'; 'Dynamic']};
33 $walker.op(foldOp);
34
35 $walker.walk($past);
36 $dumper.dumper($past);
b43cb55 Add #!, copyright, Id, and coda to PAST::Transformer::Dynamic example.
tcurtis authored
37
38 # Local Variables:
39 # mode: cperl
40 # cperl-indent-level: 4
41 # fill-column: 100
42 # End:
43 # vim: expandtab shiftwidth=4:
Something went wrong with that request. Please try again.