Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[glue/run.pir] when running as a main program, create $*PROGRAM_NAME …
…and @*ARGS
  • Loading branch information
Martin Berends committed Feb 25, 2010
1 parent 2df2463 commit 9a1d71b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/glue/run.pir
Expand Up @@ -9,7 +9,10 @@ src/glue/run.pir - code to initiate execution of a Perl 6 program
=item !UNIT_START(mainline, args)

Invoke the code given by mainline, using C<args> as the initial
(command-line) arguments.
(command-line) arguments. The method C<comp_unit($/)> in
F<Perl6/Actions.pm> generates two calls to this sub, one for
executables and one for libraries, and pushes them into the AST
of the compilation unit.

=cut

Expand All @@ -18,6 +21,29 @@ Invoke the code given by mainline, using C<args> as the initial
.param pmc mainline
.param pmc args :slurpy

# Ignore the args when executed as a library (not main program)
unless args goto unit_start_0

# args is a ResizablePMCArray containing only one entry
# args[0] is also a ResizablePMCArray, of String entries, containing
# the program name or '-e' in args[0][0], followed by
# optional command line arguments in args[0][1] etc.
$P0 = args[0]
# Ignore the args when executed as a library (not main program)
unless $P0 goto unit_start_0

# The first args string belongs in $*PROGRAM_NAME
$P1 = shift $P0 # the first arg is the program name
set_hll_global '$PROGRAM_NAME', $P1

# The remaining args strings belong in @*ARGS
$P1 = new ['Parcel']
splice $P1, $P0, 0, 0
$P2 = new ['Array']
$P2.'!STORE'($P1)
set_hll_global '@ARGS', $P2
unit_start_0:

# INIT time
'!fire_phasers'('INIT')
$P0 = mainline()
Expand Down

0 comments on commit 9a1d71b

Please sign in to comment.