~ubuntu-branches/ubuntu/precise/rakudo/precise

« back to all changes in this revision

Viewing changes to src/Perl6/Compiler.pir

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-05-17 11:31:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517113109-rmfir654u1axbpt4
Tags: 0.1~2011.04-1
* New upstream release (Closes: #601862, #585762, #577502)
* New maintainer
* Switch to 3.0 (quilt) format
* Update dependencies (Closes: #584498)
* Update debian/copyright to lastest DEP5 revision
* Do not generate/install perl6 manpage (now done by the build system)
* Enable tests
* Bump Standards-Version to 3.9.2 (no changes needed)
* Do not install extra LICENSE files and duplicated docs
* Remove debian/clean (no more needed)
* Add Vcs-* fields in debian/control
* Rewrite (short) description
* Update upstream copyright years
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, Patrick R. Michaud
 
2
 
 
3
=head1 NAME
 
4
 
 
5
Perl6::Compiler - Perl6 compiler
 
6
 
 
7
=head1 DESCRIPTION
 
8
 
 
9
=cut
 
10
 
 
11
# Set RAKUDO_HLL to 'perl6' to have Rakudo compile in its own HLL namespace.
 
12
# MUST BE LOWERCASE
 
13
.macro_const RAKUDO_HLL 'perl6'
 
14
 
 
15
.HLL .RAKUDO_HLL
 
16
 
 
17
.loadlib 'perl6_group'
 
18
.loadlib 'perl6_ops'
 
19
.loadlib 'math_ops'
 
20
 
 
21
# for gcd
 
22
.loadlib  'obscure_ops'
 
23
 
 
24
# for pow
 
25
.loadlib 'trans_ops'
 
26
 
 
27
# for bors
 
28
.loadlib 'bit_ops'
 
29
 
 
30
#for printerr
 
31
.loadlib 'io_ops'
 
32
 
 
33
#for sysinfo
 
34
.loadlib 'sys_ops'
 
35
 
 
36
.sub '' :anon :load :init
 
37
    $P0 = get_class ['P6role']
 
38
    unless null $P0 goto startup_ok
 
39
    say "==SORRY=="
 
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"
 
43
    exit 1
 
44
 
 
45
 
 
46
 startup_ok:
 
47
    load_bytecode 'P6Regex.pbc'
 
48
 
 
49
    # Init Rakudo dynops.
 
50
    rakudo_dynop_setup
 
51
 
 
52
    # Set up Mu.
 
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
 
58
 
 
59
    set_hll_global '$!OBJECTREF', objproto
 
60
 
 
61
    ## Also want _dumper for now.
 
62
    load_bytecode 'dumper.pbc'
 
63
 
 
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)
 
70
    .local pmc regexns
 
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
 
85
    $P0 = box .RAKUDO_HLL
 
86
    set_hll_global ['Perl6';'Actions'], '$?RAKUDO_HLL', $P0
 
87
.end
 
88
 
 
89
.sub 'DEBUG'
 
90
    .param string msg
 
91
    printerr msg
 
92
    printerr "\n"
 
93
.end
 
94
 
 
95
.sub '&PARROT'
 
96
    .param pmc obj
 
97
    .local string result
 
98
    result = ''
 
99
  deref_loop:
 
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->'
 
105
    goto deref_next
 
106
  deref_scalar:
 
107
    result .= 'Perl6Scalar->'
 
108
  deref_next:
 
109
    obj = deref obj
 
110
    goto deref_loop
 
111
  deref_done:
 
112
    $P0 = typeof obj
 
113
    $S0 = $P0
 
114
    result .= $S0
 
115
    .return (result)
 
116
.end
 
117
 
 
118
 
 
119
.loadlib 'os'
 
120
.loadlib 'file'
 
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'
 
134
 
 
135
.namespace ['Perl6';'Compiler']
 
136
 
 
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'
 
149
    push $P0, 'c'
 
150
    push $P0, 'n'
 
151
    push $P0, 'p'
 
152
    nqpproto.'addstage'('check_syntax', 'after'=>'past')
 
153
 
 
154
    true = get_hll_global ['Bool'], 'True'
 
155
 
 
156
    # Set up @*INC from $PERL6LIB, languages/perl6/lib and ~/.perl6/lib
 
157
    .local pmc env, interp, config
 
158
    interp = getinterp
 
159
    config = interp[.IGLOBALS_CONFIG_HASH]
 
160
    # Convert PERL6LIB first
 
161
    env = root_new ['parrot';'Env']
 
162
    $S0 = env['PERL6LIB']
 
163
 
 
164
    .local string sep, os
 
165
    sep = ':'
 
166
    os = config['osname']
 
167
    ne os, 'MSWin32', perl6lib_split
 
168
    sep = ';'
 
169
  perl6lib_split:
 
170
    $P0 = split sep, $S0
 
171
    # append ~/.perl6/lib
 
172
    $S0 = env['HOME']
 
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
 
178
  have_home:
 
179
    $S0 = concat $S0, '/.perl6/lib'
 
180
    push $P0, $S0
 
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'
 
186
    push $P0, $S0
 
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
 
190
    $P1 = new ['Parcel']
 
191
    # do not use '&circumfix:<[ ]>' because it makes a list of lists
 
192
    splice $P1, $P0, 0, 0
 
193
    $P2 = new ['Array']
 
194
    $P2.'!STORE'($P1)
 
195
    setprop $P2, 'rw', true
 
196
    set_hll_global '@INC', $P2
 
197
.end
 
198
 
 
199
.sub load_module :method
 
200
    .param string name
 
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
 
208
    pop_eh
 
209
    goto done
 
210
  no_precompiled:
 
211
    pop_eh
 
212
    filename = concat base, '.pm'
 
213
    self.'evalfiles'(filename)
 
214
  done:
 
215
    module = self.'get_module'(name)
 
216
    .return (module)
 
217
.end
 
218
 
 
219
.sub 'backtrace' :method
 
220
    .param pmc exception
 
221
    $P0 = get_hll_global ['Perl6'], 'BacktracePrinter'
 
222
    $S0 = $P0.'backtrace_for'(exception)
 
223
    .return ($S0)
 
224
.end
 
225
 
 
226
.sub 'main' :main
 
227
    .param pmc args_str
 
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')
 
234
    exit 0
 
235
.end
 
236
 
 
237
 
 
238
.sub 'pir' :method
 
239
    .param pmc source
 
240
    .param pmc adverbs         :slurpy :named
 
241
    $P0 = compreg 'POST'
 
242
    $S0 = $P0.'to_pir'(source, adverbs :flat :named)
 
243
    $S0 = concat ".loadlib 'perl6_ops'\n", $S0
 
244
    .return ($S0)
 
245
.end
 
246
 
 
247
 
 
248
.sub 'check_syntax' :method
 
249
    .param pmc source
 
250
    .param pmc adverbs         :slurpy :named
 
251
    $I0 = adverbs['c']
 
252
    unless $I0 goto no_check
 
253
    say 'syntax OK'
 
254
    exit 0
 
255
  no_check:
 
256
    .return ()
 
257
.end
 
258
    
 
259
 
 
260
.sub 'version' :method
 
261
    .local pmc interp, config, rev, version
 
262
    interp = getinterp
 
263
    config = interp[.IGLOBALS_CONFIG_HASH]
 
264
    version = config['VERSION']
 
265
    rev    = config['git_describe']
 
266
 
 
267
    say ''
 
268
    print 'This is Rakudo Perl 6, version '
 
269
    print .RAKUDO_VERSION
 
270
    print ' built on parrot '
 
271
    print version
 
272
  if null rev goto done_rev
 
273
    print ' '
 
274
    print rev
 
275
  done_rev:
 
276
    say ''
 
277
    say ''
 
278
    say 'Copyright 2008-2011, The Perl Foundation'
 
279
    say ''
 
280
    exit 0
 
281
.end
 
282
 
 
283
.sub '' :anon
 
284
    .annotate 'file', 'CORE.setting'
 
285
.end
 
286
.include 'src/gen/core.pir'
 
287
 
 
288
# Cheats go at the end, because some of them are in the 'parrot' HLL
 
289
# namespace.
 
290
.include 'src/gen/cheats.pir'
 
291
 
 
292
.sub '' :anon
 
293
    .annotate 'file', ''
 
294
.end
 
295
 
 
296
=cut
 
297
 
 
298
# Local Variables:
 
299
#   mode: pir
 
300
#   fill-column: 100
 
301
# End:
 
302
# vim: expandtab shiftwidth=4 ft=pir: