tagged release 0.7.1
[parrot.git] / languages / perl6 / perl6.pir
blob6904987a786627d1d71241e3622b3455b047acd3
1 =head1 TITLE
3 perl6.pir - The Rakudo Perl 6 compiler.
5 =head2 Description
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'.
13 =head2 Functions
15 =over 4
17 =item onload()
19 Creates the Perl 6 compiler by subclassing a C<PCT::HLLCompiler> object.
21 =cut
23 .loadlib 'perl6_group'
24 .loadlib 'perl6_ops'
25 .include 'src/gen_builtins.pir'
27 .namespace [ 'Perl6::Compiler' ]
29 .sub 'onload' :load :init :anon
30     load_bytecode 'PCT.pbc'
32     .local pmc p6meta
33     p6meta = get_hll_global ['Perl6Object'], '$!P6META'
34     p6meta.'new_class'('Perl6::Compiler', 'parent'=>'PCT::HLLCompiler')
35 .end
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
53     $P0 = new 'String'
54     $P0 = <<'USAGE'
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
64 USAGE
65     setattribute self, '$usage', $P0
67     ##  set the $version attribute
68     .local pmc cfg
69     $P0  = new 'String'
70     $P0  = 'This is Rakudo Perl 6'
71     push_eh _handler
73     # currently works in the build tree, but not in the install tree
74     cfg  = _config()
75     $P0 .= ', revision '
76     $S0  = cfg['revision']
77     $P0 .= $S0
78     $P0 .= ' built on parrot '
79     $S0  = cfg['VERSION']
80     $P0 .= $S0
81     $S0  = cfg['DEVEL']
82     $P0 .= $S0
83     $P0 .= "\n"
84     $P0 .= 'for '
85     $S0  = cfg['archname']
86     $P0 .= $S0
87   _handler:
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
92     $P0 = new 'List'
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).
97     $P0 = new 'List'
98     set_hll_global ['Perl6';'Grammar';'Actions'], '@?PACKAGE', $P0
100     ## create a list for holding the stack of nested classes
101     $P0 = new 'List'
102     set_hll_global ['Perl6';'Grammar';'Actions'], '@?CLASS', $P0
104     ## create a list for holding the stack of nested roles
105     $P0 = new 'List'
106     set_hll_global ['Perl6';'Grammar';'Actions'], '@?ROLE', $P0
108     ## create a list for holding the stack of nested grammars
109     $P0 = new 'List'
110     set_hll_global ['Perl6';'Grammar';'Actions'], '@?GRAMMAR', $P0
112     ##  create a list of END blocks to be run
113     $P0 = new 'List'
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'
119     $P0['Str'] = 'e'
120 .end
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.
130 =cut
132 .sub 'check_syntax' :method
133     .param pmc source
134     .param pmc adverbs      :slurpy :named
136     $I0 = adverbs['c']
137     if $I0 goto check_syntax
138     .return ()
139   check_syntax:
140     ## if we're here, then syntax is OK
141     say 'syntax OK'
142     exit 0
143 .end
146 =item main(args :slurpy)  :main
148 Start compilation by passing any command line C<args>
149 to the Perl 6 compiler.
151 =cut
153 .sub 'main' :main
154     .param pmc args_str
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
161     args = new 'List'
162     iter = new 'Iterator', args_str
163   args_loop:
164     unless iter goto args_end
165     $P0 = shift iter
166     push args, $P0
167     goto args_loop
168   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'
175     .local pmc iter
176     $P0 = get_hll_global ['Perl6'], '@?END_BLOCKS'
177     iter = new 'Iterator', $P0
178     iter = .ITERATE_FROM_END
179   iter_loop:
180     unless iter goto iter_end
181     $P0 = pop iter
182     $P0()
183     goto iter_loop
184   iter_end:
185 .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'
194 =back
196 =cut
198 # Local Variables:
199 #   mode: pir
200 #   fill-column: 100
201 # End:
202 # vim: expandtab shiftwidth=4 ft=pir: