Skip to content

Commit

Permalink
Command line args are passed into the main sub with new
Browse files Browse the repository at this point in the history
calling conventions, no longer in P5.


git-svn-id: https://svn.parrot.org/parrot/trunk@12064 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bschmalhofer committed Mar 28, 2006
1 parent 0eccb09 commit 71a307f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 57 deletions.
4 changes: 2 additions & 2 deletions config/gen/makefiles/root.in
@@ -1,4 +1,4 @@
# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
# Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
# $Id$

###############################################################################
Expand Down Expand Up @@ -894,7 +894,7 @@ examples-clean:

# hello
hello: test_prep examples/pasm/hello$(EXE)
$(CUR_DIR)/examples/pasm/hello$(EXE)
$(CUR_DIR)/examples/pasm/hello$(EXE) "from your friendly makefile"

examples/pasm/hello.pbc: examples/pasm/hello.pasm
$(PARROT) -o examples/pasm/hello.pbc examples/pasm/hello.pasm
Expand Down
19 changes: 17 additions & 2 deletions examples/pasm/hello.pasm
Expand Up @@ -11,5 +11,20 @@ for showing how to create an executable from PASM.

=cut

print "Hello World\n"
end
# Get @ARGV as a ResizableStringArray
get_params "(0)", P0

# Discard the program name
shift S0, P0

# Look for additional args
if P0, FOUND_EXTRA_ARG
print "Hello World\n"
end

FOUND_EXTRA_ARG:
shift S1, P0
print "Hello "
print S1
print "\n"
end
5 changes: 2 additions & 3 deletions src/embed.c
@@ -1,5 +1,5 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
$Id$
=head1 NAME
Expand Down Expand Up @@ -458,7 +458,6 @@ setup_argv(Interp *interpreter, int argc, char ** argv)
argc);
}

/* XXX @ARGS should propably be a ResizableStringArray */
userargv = pmc_new_noinit(interpreter, enum_class_ResizableStringArray);
/* immediately anchor pmc to root set */
VTABLE_set_pmc_keyed_int(interpreter, interpreter->iglobals,
Expand Down Expand Up @@ -767,7 +766,7 @@ Parrot_runcode(Interp *interpreter, int argc, char *argv[])
PIO_eprintf(interpreter, " ***\n");
}

/* Set up @ARGS (or whatever this language calls it) in P5. */
/* Set up @ARGS (or whatever this language calls it) in userargv. */
userargv = setup_argv(interpreter, argc, argv);

#if EXEC_CAPABLE
Expand Down
53 changes: 5 additions & 48 deletions src/exec_start.c
@@ -1,5 +1,5 @@
/*
Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
$Id$
=head1 NAME
Expand Down Expand Up @@ -36,51 +36,7 @@ opcode_t* run_compiled(Interp *interpreter,

/*
=item C<static void
setup_argv(Interp *interpreter, int argc, char ** argv)>
Stolen from F<embed.c>.
=cut
*/

static void
setup_argv(Interp *interpreter, int argc, char ** argv)
{
INTVAL i;
PMC *userargv;

if (Interp_debug_TEST(interpreter, PARROT_START_DEBUG_FLAG)) {
PIO_eprintf(interpreter,
"*** Parrot VM: Setting up ARGV array in P5. Current argc: %d ***\n",
argc);
}

userargv = pmc_new_noinit(interpreter, enum_class_SArray);
/* immediately anchor pmc to root set */
REG_PMC(5) = userargv;
VTABLE_set_pmc_keyed_int(interpreter, interpreter->iglobals,
(INTVAL)IGLOBALS_ARGV_LIST, userargv);
VTABLE_init(interpreter, userargv);
VTABLE_set_integer_native(interpreter, userargv, argc);

for (i = 0; i < argc; i++) {
/* Run through argv, adding everything to @ARGS. */
STRING *arg = string_make(interpreter, argv[i], strlen(argv[i]),
"binary", PObj_external_FLAG);

if (Interp_debug_TEST(interpreter, PARROT_START_DEBUG_FLAG)) {
PIO_eprintf(interpreter, "\t%vd: %s\n", i, argv[i]);
}

VTABLE_push_string(interpreter, userargv, arg);
}
}

/*
=item C<int main(int argc, char **argv)>
=item C<int main(int argc, char * argv[])>
The run-loop.
Expand All @@ -89,7 +45,8 @@ The run-loop.
*/

int
main(int argc, char **argv) {
main(int argc, char * argv[])
{
/* long * opp; */
Interp * interpreter;
struct PackFile * pf;
Expand Down Expand Up @@ -161,7 +118,7 @@ main(int argc, char **argv) {
=head1 SEE ALSO
F<include/parrot/exec.h>, F<include/parrot/exec_save.h>, F<src/exec.c>
and F<src/exec_start.c>.
and F<compilers/imcc/main.c>.
=head1 HISTORY
Expand Down
4 changes: 2 additions & 2 deletions src/mmd.c
Expand Up @@ -1254,8 +1254,8 @@ Default implementation of MMD lookup. The signature contains the letters
=item C<PMC *Parrot_MMD_search_default_func(Interp *, STRING *meth)>
Default implementation of MMD lookup. The signature contains the letters
"INSP" for the argument types. B<PMC> arguments are taken from registers
C<P5> and up according to calling conventions.
"INSP" for the argument types. B<PMC> arguments are taken from
the argument tuple.
=cut
Expand Down

0 comments on commit 71a307f

Please sign in to comment.