3 perl6.pir - The Rakudo Perl 6 compiler.
7 This is the base file for the Rakudo Perl 6 compiler.
9 This file includes the parsing and grammar rules from
10 the src/ directory, loads the relevant PGE libraries,
11 and registers the compiler under the name 'Perl6'.
19 Creates the Perl 6 compiler by subclassing a C<PCT::HLLCompiler> object.
23 .loadlib 'perl6_group'
25 .include 'src/gen_builtins.pir'
27 .namespace [ 'Perl6::Compiler' ]
29 .sub 'onload' :load :init :anon
30 load_bytecode 'PCT.pbc'
33 p6meta = get_hll_global ['Perl6Object'], '$!P6META'
34 p6meta.'new_class'('Perl6::Compiler', 'parent'=>'PCT::HLLCompiler')
37 .sub 'init' :vtable :method
38 load_bytecode 'config.pbc'
40 self.'language'('Perl6')
41 self.'parsegrammar'('Perl6::Grammar')
42 self.'parseactions'('Perl6::Grammar::Actions')
44 ## set the compilation stages in the @stages attribute
45 $P0 = split ' ', 'parse past check_syntax post pir evalpmc'
46 setattribute self, '@stages', $P0
48 ## set the command line options
49 $P0 = split ' ', 'c e=s help|h target=s trace|t=s encoding=s output|o=s version|v'
50 setattribute self, '@cmdoptions', $P0
52 ## set the $usage attribute
55 Usage: perl6 [switches] [--] [programfile] [arguments]
56 -c check syntax only (runs BEGIN and CHECK blocks)
57 -e program one line of program
58 -h, --help display this help text
59 --target=[stage] specify compilation stage to emit
60 -t, --trace=[flags] enable trace flags
61 --encoding=[mode] specify string encoding mode
62 -o, --output=[name] specify name of output file
63 -v, --version display version information
65 setattribute self, '$usage', $P0
67 ## set the $version attribute
70 $P0 = 'This is Rakudo Perl 6'
73 # currently works in the build tree, but not in the install tree
78 $P0 .= ' built on parrot '
88 $P0 .= ".\n\nCopyright 2006-2008, The Perl Foundation.\n"
89 setattribute self, '$version', $P0
91 ## create a list for holding the stack of nested blocks
93 set_hll_global ['Perl6';'Grammar';'Actions'], '@?BLOCK', $P0
95 ## create a list for holding the stack of nested packages
96 ## (that may be roles, modules, classes or grammars).
98 set_hll_global ['Perl6';'Grammar';'Actions'], '@?PACKAGE', $P0
100 ## create a list for holding the stack of nested classes
102 set_hll_global ['Perl6';'Grammar';'Actions'], '@?CLASS', $P0
104 ## create a list for holding the stack of nested roles
106 set_hll_global ['Perl6';'Grammar';'Actions'], '@?ROLE', $P0
108 ## create a list for holding the stack of nested grammars
110 set_hll_global ['Perl6';'Grammar';'Actions'], '@?GRAMMAR', $P0
112 ## create a list of END blocks to be run
114 set_hll_global ['Perl6'], '@?END_BLOCKS', $P0
116 ## tell PAST::Var how to encode Perl6Str and Str values
117 $P0 = get_hll_global ['PAST::Compiler'], '%valflags'
118 $P0['Perl6Str'] = 'e'
123 .namespace ['Perl6::Compiler']
125 =item check_syntax(source [, "option" => value, ...])
127 Check the syntax of C<source> after PAST tree has been built,
128 to ensure C<BEGIN> and C<CHECK> blocks have been executed.
132 .sub 'check_syntax' :method
134 .param pmc adverbs :slurpy :named
137 if $I0 goto check_syntax
140 ## if we're here, then syntax is OK
146 =item main(args :slurpy) :main
148 Start compilation by passing any command line C<args>
149 to the Perl 6 compiler.
156 ## create @ARGS global. We could possibly use the args pmc
157 ## coming directly from Parrot, but currently Parrot provides
158 ## it as a ResizableStringArray and we need Undefs for
159 ## non-existent elements (RSA gives empty strings).
160 .local pmc args, iter
162 iter = new 'Iterator', args_str
164 unless iter goto args_end
169 set_hll_global '@ARGS', args
171 $P0 = compreg 'Perl6'
172 $P1 = $P0.'command_line'(args, 'encoding'=>'utf8', 'transcode'=>'iso-8859-1')
174 .include 'iterator.pasm'
176 $P0 = get_hll_global ['Perl6'], '@?END_BLOCKS'
177 iter = new 'Iterator', $P0
178 iter = .ITERATE_FROM_END
180 unless iter goto iter_end
188 .include 'src/gen_grammar.pir'
189 .include 'src/parser/expression.pir'
190 .include 'src/parser/quote_expression.pir'
191 .include 'src/gen_actions.pir'
202 # vim: expandtab shiftwidth=4 ft=pir: