1
# Copyright (C) 2009, Patrick R. Michaud
5
Perl6::Compiler - Perl6 compiler
11
# Set RAKUDO_HLL to 'perl6' to have Rakudo compile in its own HLL namespace.
13
.macro_const RAKUDO_HLL 'perl6'
17
.loadlib 'perl6_group'
22
.loadlib 'obscure_ops'
36
.sub '' :anon :load :init
37
$P0 = get_class ['P6role']
38
unless null $P0 goto startup_ok
40
say "Unable to find Perl 6 low-level runtime files"
41
say " If you want to run Rakudo outside of the build directory,"
42
say " run 'make install' and use the installed perl6 binary"
47
load_bytecode 'P6Regex.pbc'
53
.local pmc objproto, p6meta
54
$P0 = get_root_global ['parrot'], 'P6metaclass'
55
objproto = $P0.'new_class'('Mu')
56
p6meta = objproto.'HOW'()
57
set_hll_global ['Mu'], '$!P6META', p6meta
59
set_hll_global '$!OBJECTREF', objproto
61
## Also want _dumper for now.
62
load_bytecode 'dumper.pbc'
64
## Bring in PAST, PCT, HLL, and NQP namespaces from parrot hllns
65
.local pmc hllns, parrotns, imports
66
hllns = get_hll_namespace
67
parrotns = get_root_namespace ['parrot']
68
imports = split ' ', 'PAST PCT HLL _dumper'
69
parrotns.'export_to'(hllns, imports)
71
regexns = hllns.'make_namespace'('Regex')
72
$P0 = get_root_namespace ['parrot';'Regex';'Cursor']
73
regexns.'add_namespace'('Cursor', $P0)
74
$P0 = get_root_global ['parrot';'Regex'], 'Cursor'
75
regexns['Cursor'] = $P0
76
$P0 = get_root_namespace ['parrot';'Regex';'Match']
77
regexns.'add_namespace'('Match', $P0)
78
$P0 = get_root_global ['parrot';'Regex'], 'Match'
79
regexns['Match'] = $P0
80
$P0 = get_root_namespace ['parrot';'Regex';'P6Regex']
81
regexns.'add_namespace'('P6Regex', $P0)
82
$P0 = get_root_global ['parrot';'Regex'], 'P6Regex'
83
regexns['P6Regex'] = $P0
84
# Tell the actions compiler what hllns we're using
86
set_hll_global ['Perl6';'Actions'], '$?RAKUDO_HLL', $P0
100
$I0 = isa obj, 'ObjectRef'
101
unless $I0 goto deref_done
102
$I0 = isa obj, 'Perl6Scalar'
103
if $I0 goto deref_scalar
104
result .= 'ObjectRef->'
107
result .= 'Perl6Scalar->'
121
.include 'src/gen/version.pir'
122
.include 'src/gen/builtins.pir'
123
.include 'src/gen/signature_pm.pir'
124
.include 'src/gen/parameter_pm.pir'
125
.include 'src/gen/package_pm.pir'
126
.include 'src/gen/module_pm.pir'
127
.include 'src/gen/role_pm.pir'
128
.include 'src/gen/locator_pm.pir'
129
.include 'src/gen/versiondetectionactions_pm.pir'
130
.include 'src/gen/loader_pm.pir'
131
.include 'src/gen/backtraceprinter_pm.pir'
132
.include 'src/gen/perl6-grammar.pir'
133
.include 'src/gen/perl6-actions.pir'
135
.namespace ['Perl6';'Compiler']
137
.sub '' :anon :load :init
138
# Set up parser/actions.
139
.local pmc p6meta, nqpproto, true
140
p6meta = get_hll_global ['Mu'], '$!P6META'
141
nqpproto = p6meta.'new_class'('Perl6::Compiler', 'parent'=>'HLL::Compiler')
142
nqpproto.'language'('perl6')
143
$P0 = get_hll_global ['Perl6'], 'Grammar'
144
nqpproto.'parsegrammar'($P0)
145
$P0 = get_hll_global ['Perl6'], 'Actions'
146
nqpproto.'parseactions'($P0)
147
$P0 = getattribute nqpproto, '@cmdoptions'
148
push $P0, 'parsetrace'
152
nqpproto.'addstage'('check_syntax', 'after'=>'past')
154
true = get_hll_global ['Bool'], 'True'
156
# Set up @*INC from $PERL6LIB, languages/perl6/lib and ~/.perl6/lib
157
.local pmc env, interp, config
159
config = interp[.IGLOBALS_CONFIG_HASH]
160
# Convert PERL6LIB first
161
env = root_new ['parrot';'Env']
162
$S0 = env['PERL6LIB']
164
.local string sep, os
166
os = config['osname']
167
ne os, 'MSWin32', perl6lib_split
171
# append ~/.perl6/lib
173
if $S0 goto have_home # for users of unix-y systems
174
# here only for those of a fenestral persuasion
175
$S0 = env['HOMEDRIVE']
176
$S1 = env['HOMEPATH']
177
$S0 = concat $S0, $S1
179
$S0 = concat $S0, '/.perl6/lib'
181
# append the installed Parrot languages/perl6/lib directory
182
$S0 = config['libdir']
183
$S1 = config['versiondir']
184
$S0 = concat $S0, $S1
185
$S0 = concat $S0, '/languages/perl6/lib'
187
# append the current directory
188
push $P0, '.' # remove this when 'use lib' works fine
189
# $P0 now has all the directories, move them to @*INC
191
# do not use '&circumfix:<[ ]>' because it makes a list of lists
192
splice $P1, $P0, 0, 0
195
setprop $P2, 'rw', true
196
set_hll_global '@INC', $P2
199
.sub load_module :method
201
.local string base, filename
202
.local pmc namelist, module
203
namelist = self.'parse_name'(name)
204
base = join '/', namelist
205
push_eh no_precompiled
206
filename = concat base, '.pir'
207
load_bytecode filename
212
filename = concat base, '.pm'
213
self.'evalfiles'(filename)
215
module = self.'get_module'(name)
219
.sub 'backtrace' :method
221
$P0 = get_hll_global ['Perl6'], 'BacktracePrinter'
222
$S0 = $P0.'backtrace_for'(exception)
228
# Fire any of the setting's INIT phasers before we enter the runloop, so
229
# e.g. $*OUT is available to the actual code's BEGIN blocks.
230
'!fire_phasers'('INIT')
231
$P0 = compreg 'perl6'
232
$P1 = $P0.'command_line'(args_str, 'encoding'=>'utf8', 'transcode'=>'ascii iso-8859-1')
233
'!fire_phasers'('END')
240
.param pmc adverbs :slurpy :named
242
$S0 = $P0.'to_pir'(source, adverbs :flat :named)
243
$S0 = concat ".loadlib 'perl6_ops'\n", $S0
248
.sub 'check_syntax' :method
250
.param pmc adverbs :slurpy :named
252
unless $I0 goto no_check
260
.sub 'version' :method
261
.local pmc interp, config, rev, version
263
config = interp[.IGLOBALS_CONFIG_HASH]
264
version = config['VERSION']
265
rev = config['git_describe']
268
print 'This is Rakudo Perl 6, version '
269
print .RAKUDO_VERSION
270
print ' built on parrot '
272
if null rev goto done_rev
278
say 'Copyright 2008-2011, The Perl Foundation'
284
.annotate 'file', 'CORE.setting'
286
.include 'src/gen/core.pir'
288
# Cheats go at the end, because some of them are in the 'parrot' HLL
290
.include 'src/gen/cheats.pir'
302
# vim: expandtab shiftwidth=4 ft=pir: