Index: parrot-svn/config/gen/makefiles/root.in =================================================================== --- parrot-svn.orig/config/gen/makefiles/root.in +++ parrot-svn/config/gen/makefiles/root.in @@ -2181,7 +2181,8 @@ win32-inno-installer : world installable # ############################################################################### -exec : $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) +# usage: make exec EXEC=examples/c/test_main +exec : $(SRC_DIR)/exec_start$(O) $(EXEC)$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT) $(LINK) @ld_out@$(EXEC)$(EXE) $(EXEC)$(O) $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) @rpath_blib@ $(ALL_PARROT_LIBS) $(LINKFLAGS) ###### OS depend targets ########## Index: parrot-svn/examples/c/test_main.c =================================================================== --- parrot-svn.orig/examples/c/test_main.c +++ parrot-svn/examples/c/test_main.c @@ -19,14 +19,18 @@ still clean, Parrot embedding. */ -#include "parrot/embed.h" -#include "parrot/longopt.h" #include #include #include -#define setopt(flag) Parrot_setflag(interp, (flag), (*argv)[0]+2); -#define unsetopt(flag) Parrot_setflag(interp, (flag), 0) +#include "parrot/embed.h" +#include "parrot/longopt.h" + +#define SET_FLAG(flag) Parrot_set_flag(interp, (flag)) +#define SET_DEBUG(flag) Parrot_set_debug(interp, (flag)) +#define SET_TRACE(flag) Parrot_set_trace(interp, (flag)) +#define SET_CORE(core) interp->run_core |= (core) +#define UNSET_FLAG(flag) Parrot_clear_flag(interp, (flag)) static char *parseflags(PARROT_INTERP, int *argc, char **argv[]); @@ -38,9 +42,9 @@ static struct longopt_opt_decl options[] { 'd', 'd', 0, { "--debug" } }, { 'h', 'h', 0, { "--help" } }, { 'j', 'j', 0, { "--jit" } }, - { 'o', 'o', 0, { "--output-file" } }, + { 'o', 'o', 0, { "--output" } }, { 'p', 'p', 0, { "--profile" } }, - { 'P', 'P', 0, { "--prederefrenced-core" } }, + { 'P', 'P', 0, { "--predereferenced-core" } }, { 'S', 'S', 0, { "--switched-core" } }, { 'g', 'g', 0, { "--no-computed-goto" } }, { 't', 't', 0, { "--trace" } }, @@ -51,9 +55,9 @@ static struct longopt_opt_decl options[] {'\0', 0, 0, { NULL } } }; -static void usage(void); +static void usage(PARROT_INTERP); -static void version(void); +static void version(PARROT_INTERP); /* @@ -80,13 +84,13 @@ main(int argc, char *argv[]) filename = parseflags(interp, &argc, &argv); - pf = Parrot_readbc(interp, filename); + pf = Parrot_pbc_read(interp, filename, 0); if (!pf) { return 1; } - Parrot_loadbc(interp, pf); + Parrot_pbc_load(interp, pf); Parrot_runcode(interp, argc, argv); Parrot_destroy(interp); @@ -111,7 +115,7 @@ parseflags(PARROT_INTERP, int *argc, cha struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; if (*argc == 1) { - usage(); + usage(interp); } ++*argv; @@ -120,48 +124,56 @@ parseflags(PARROT_INTERP, int *argc, cha #ifdef HAVE_COMPUTED_GOTO - setopt(PARROT_CGOTO_FLAG); + SET_CORE(PARROT_CGOTO_CORE); #endif - while (longopt_get(interp, *argc, *argv, options, &opt)) { + while (longopt_get(interp, *argc, (const char **)*argv, options, &opt)) { if (opt.opt_id == -1) { - fprintf(stderr, "parrot: %s\n", opt.opt_error); + fprintf(stderr, "main: %s\n", opt.opt_error); Parrot_exit(interp, 1); } switch (opt.opt_id) { case 'b': - setopt(PARROT_BOUNDS_FLAG); + SET_FLAG(PARROT_BOUNDS_FLAG); break; case 'j': - setopt(PARROT_JIT_FLAG); + SET_CORE(PARROT_JIT_CORE); break; case 'o': - setopt(PARROT_EXEC_FLAG); + interp->output_file = opt.opt_arg; break; case 'p': - setopt(PARROT_PROFILE_FLAG); + SET_FLAG(PARROT_PROFILE_FLAG); break; case 'P': - setopt(PARROT_PREDEREF_FLAG); + SET_CORE(PARROT_SWITCH_CORE); + /*SET_FLAG(PARROT_PREDEREF_FLAG);*/ break; case 'S': - setopt(PARROT_SWITCH_FLAG); + SET_CORE(PARROT_SWITCH_CORE); break; case 'g': - unsetopt(PARROT_CGOTO_FLAG); + SET_CORE(PARROT_CGOTO_CORE); break; case 't': - setopt(PARROT_TRACE_FLAG); + SET_TRACE(1); + SET_CORE(PARROT_SWITCH_CORE); +#ifdef HAVE_COMPUTED_GOTO + SET_CORE(PARROT_CGP_CORE); +#endif +#ifdef JIT_CAPABLE + SET_CORE(PARROT_JIT_CORE); +#endif break; case 'd': - setopt(PARROT_DEBUG_FLAG); + SET_DEBUG(1); break; case 'h': - usage(); + usage(interp); break; case 'v': - version(); + version(interp); break; case 'w': Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG); @@ -172,16 +184,20 @@ parseflags(PARROT_INTERP, int *argc, cha fgetc(stdin); break; case OPT_GC_DEBUG: -#if DISABLE_GC_DEBUG +#ifdef DISABLE_GC_DEBUG Parrot_warn(interp, PARROT_WARNINGS_ALL_FLAG, "PARROT_GC_DEBUG is set but the binary was " "compiled with DISABLE_GC_DEBUG."); #endif - setopt(PARROT_GC_DEBUG_FLAG); + SET_FLAG(PARROT_GC_DEBUG_FLAG); break; case OPT_DESTROY_FLAG: - setopt(PARROT_DESTROY_FLAG); + SET_FLAG(PARROT_DESTROY_FLAG); break; + default: + fprintf(stderr, + "main: Invalid flag '%s' used.\n", + (*argv)[0]); } } *argv += opt.opt_index; @@ -190,7 +206,7 @@ parseflags(PARROT_INTERP, int *argc, cha if ((*argv)[0]) return (*argv)[0]; else { - usage(); + usage(interp); return 0; /* This won't happen */ } } @@ -198,7 +214,7 @@ parseflags(PARROT_INTERP, int *argc, cha /* =item C +usage(PARROT_INTERP)> Returns the user help. @@ -207,7 +223,7 @@ Returns the user help. */ static void -usage(void) +usage(PARROT_INTERP) { #ifdef HAVE_COMPUTED_GOTO const char* cgoto_info = "Deactivate computed goto"; @@ -230,19 +246,19 @@ usage(void) -v --version Display version information\n\ -. --wait Wait for a keypress (gives Windows users\n\ time to attach a debugger)\n\ + -o --output=FILE Output to file\n\ --gc-debug\n\ Enable garbage collection debugging mode. This may also be enabled\n\ by setting the environment variable $PARROT_GC_DEBUG to 1.\n\ \n", cgoto_info); - Parrot_exit(interp, 0); } /* =item C +version(PARROT_INTERP)> Returns the version information. @@ -251,12 +267,12 @@ Returns the version information. */ static void -version(void) +version(PARROT_INTERP) { fprintf(stderr, "This is parrot version " PARROT_VERSION " built for " PARROT_ARCHNAME "\n\ -Copyright (C) 2001-2003, The Perl Foundation.\n\ +Copyright (C) 2001-2009, The Perl Foundation.\n\ \n\ Parrot may be copied only under the terms of either the Artistic License or the\ \n\