tagged release 0.7.1
[parrot.git] / examples / past / blocktype_immediate.pir
blobe7166e6655b5ea86953aa670c68e196e3cc24e1d
1 # Copyright (C) 2007-2008, The Perl Foundation.
2 # $Id$
4 =head1 NAME
6 examples/past/blocktype_immediate.pir - Evaluating a PAST::Block immediately
8 =head1 SYNOPSIS
10     % ./parrot examples/past/blocktype_immediate.pir
12 =head1 DESCRIPTION
14 Create and evaluate a PAST::Block with blocktype 'immediate'.
15 'immediate' means the the block is evaluated end the last value
16 is returned.
18 Beware that this doesn't work yet as expected:
20 '_block10' isn't a closure (no :outer)
21 current instr.: 'anon' pc 3 (EVAL_1:5)
22 called from Sub 'parrot;PCT::HLLCompiler;eval' pc 609 (src/HLLCompiler.pir:368)
23 called from Sub 'main' pc 70 (examples/past/blocktype_immediate.pir:52)
25 =head1 SEE ALSO
27 F<docs/pdds/pdd26_ast.pod>
29 =cut
31 .namespace []
33 .sub '__onload' :init
34     load_bytecode 'PGE.pbc'
35     load_bytecode 'PGE/Text.pbc'
36     load_bytecode 'PGE/Util.pbc'
37     load_bytecode 'PGE/Dumper.pbc'
38     load_bytecode 'PCT.pbc'
39 .end
41 .sub main :main
43     # content of the block
44     .local pmc val_x
45     val_x = new 'PAST::Val'
46     val_x.init( 'value' => '-536870912', 'returns' => 'Integer' )
48     # wrap the content in a block
49     .local pmc var_block
50     var_block = new 'PAST::Block'
51     var_block.init( val_x, 'blocktype' => 'immediate' )
53     # set up compiler
54     .local pmc astcompiler
55     astcompiler = new [ 'PCT::HLLCompiler' ]
56     astcompiler.'removestage'('parse')
57     astcompiler.'removestage'('past')
59     # evaluate
60     .local pmc result
61     ( result ) = astcompiler.'eval'(var_block)
62     _dumper( result, 'result' )
64 .end
66 # Local Variables:
67 #   mode: pir
68 #   fill-column: 100
69 # End:
70 # vim: expandtab shiftwidth=4 ft=pir: