Permalink
Browse files

change the imcc_run function to return a PackFile PMC so we can use i…

…t with the new API. Add a long series of API functions that are needed by main.c. Go through main.c and start converting to the new API.
  • Loading branch information...
1 parent d4e8708 commit 9d25cd4e7d319fab6222aa6bb82e905e98b99a10 @Whiteknight Whiteknight committed Nov 11, 2010
Showing with 137 additions and 74 deletions.
  1. +18 −10 compilers/imcc/main.c
  2. +1 −1 include/parrot/api.h
  3. +63 −2 src/embed/api.c
  4. +14 −0 src/gc/api.c
  5. +41 −61 src/main.c
View
@@ -532,7 +532,7 @@ Compile source code into bytecode (or die trying).
*/
-static void
+static PackFile *
compile_to_bytecode(PARROT_INTERP,
ARGIN(const char * const sourcefile),
ARGIN_NULLOK(const char * const output_file),
@@ -582,6 +582,7 @@ compile_to_bytecode(PARROT_INTERP,
IMCC_info(interp, 1, "%ld lines compiled.\n", IMCC_INFO(interp)->line);
if (per_pbc && !IMCC_INFO(interp)->write_pbc)
PackFile_fixup_subs(interp, PBC_POSTCOMP, NULL);
+ return pf;
}
/*
@@ -599,10 +600,12 @@ and run. This function always returns 0.
int
imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc,
- ARGIN(const char **argv))
+ ARGIN(const char **argv), ARGOUT(PMC **pbcpmc))
{
yyscan_t yyscanner;
const char * const output_file = interp->output_file;
+ PackFile * pf_raw = NULL;
+ *pbcpmc = PMCNULL;
imcc_parseflags(interp, argc, argv);
@@ -645,12 +648,13 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc,
/* If the input file is Parrot bytecode, then we simply read it
into a packfile, which Parrot then loads */
if (STATE_LOAD_PBC(interp)) {
- const int loaded = Parrot_load_bytecode_file(interp, sourcefile);
- if (!loaded)
+ pf_raw = Parrot_pbc_read(interp, sourcefile, 0);
+ if (!pf_raw)
IMCC_fatal_standalone(interp, 1, "main: Packfile loading failed\n");
+ Parrot_pbc_load(interp, pf);
}
else
- compile_to_bytecode(interp, sourcefile, output_file, yyscanner);
+ pf_raw = compile_to_bytecode(interp, sourcefile, output_file, yyscanner);
/* Produce a PBC output file, if one was requested */
if (STATE_WRITE_PBC(interp)) {
@@ -662,13 +666,11 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc,
/* If necessary, load the file written above */
if (STATE_RUN_FROM_FILE(interp) && !STREQ(output_file, "-")) {
- PackFile *pf;
-
IMCC_info(interp, 1, "Loading %s\n", output_file);
- pf = Parrot_pbc_read(interp, output_file, 0);
- if (!pf)
+ pf_raw = Parrot_pbc_read(interp, output_file, 0);
+ if (!pf_raw)
IMCC_fatal_standalone(interp, 1, "Packfile loading failed\n");
- Parrot_pbc_load(interp, pf);
+ Parrot_pbc_load(interp, pf_raw);
SET_STATE_LOAD_PBC(interp);
}
}
@@ -686,6 +688,12 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc,
yylex_destroy(yyscanner);
+ if (pf_raw) {
+ PMC * const _pbcpmc = Parrot_pmc_new(interp, enum_class_PackFile);
+ VTABLE_set_pointer(interp, _pbcpmc, pf_raw);
+ *pbcpmc = _pbcpmc;
+ }
+
/* should the bytecode be run */
if (STATE_RUN_PBC(interp))
return 1;
@@ -14,7 +14,7 @@
typedef struct _Parrot_Init_Args {
void *stacktop;
- INTVAL gc_system;
+ char * gc_system;
INTVAL gc_threshold;
INTVAL hash_seed;
} Parrot_Init_Args;
View
@@ -49,8 +49,12 @@ Parrot_api_make_interpreter(ARGIN_NULLOK(PMC *parent), INTVAL flags, ARGIN_NULLO
if (args) {
if (args->stack_top)
stacktop_ptr = args->stacktop;
- if (args->gc_system)
- interp->gc_sys->sys_type = args->gc_system;
+ if (args->gc_system) {
+ const INTVAL sysid = Parrot_gc_get_system_id(interp, args->gc_system);
+ if (sysid == -1)
+ EMBED_API_FAILURE(interp_pmc, interp);
+ interp->gc_sys->sys_type = sysid;
+ }
if (args->gc_threshold)
interp->gc_threshold = args->gc_threshold;
if (args->hash_seed)
@@ -88,6 +92,9 @@ Parrot_api_set_executable_name(ARGIN(PMC *interp_pmc), ARGIN(Parrot_String) name
EMBED_API_CALLOUT(interp_pmc, interp);
}
+// TODO: Consider merging _destroy_interpreter and _exit_interpreter.
+// it doesn't make sense to call one without calling the other
+
PARROT_API
INTVAL
Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc))
@@ -166,3 +173,57 @@ Parrot_api_build_argv_array(ARGMOD(PMC *interp_pmc), INTVAL argc, ARGIN(char **a
*args = userargv;
EMBED_API_CALLIN(interp_pmc, interp);
}
+
+PARROT_API
+INTVAL
+Parrot_api_set_warnings(ARGMOD(PMC *interp_pmc), INTVAL flags)
+{
+ ASSERT_ARGS(Parrot_api_set_warnings)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ /* Activates the given warnings. (Macro from warnings.h.) */
+ PARROT_WARNINGS_on(interp, (Parrot_warnclass)flags);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+PARROT_API
+INTVAL
+Parrot_api_set_output_file(ARGMOD(PMC *interp_pmc), ARGIN(const char * filename))
+{
+ ASSERT_ARGS(Parrot_api_set_output_file)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ if (!filename && !interp->output_file)
+ interp->output_file = "-";
+ else
+ interp->output_file = filename;
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+PARROT_API
+INTVAL
+Parrt_api_add_library_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
+{
+ ASSERT_ARGS(Parrot_api_add_library_search_path)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_LIBRARY);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+PARROT_API
+INTVAL
+Parrt_api_add_include_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
+{
+ ASSERT_ARGS(Parrot_api_add_include_search_path)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_INCLUDE);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+PARROT_API
+INTVAL
+Parrt_api_add_dynext_search_path(ARGMOD(PMC *interp_pmc), ARGIN(const char *path))
+{
+ ASSERT_ARGS(Parrot_api_add_dynext_search_path)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ Parrot_lib_add_path_from_cstring(interp, path, PARROT_LIB_PATH_DYNEXT);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
View
@@ -105,6 +105,20 @@ implementation, and malloc wrappers for various purposes. These are unused.
#endif
+PARROT_EXPORT
+INTVAL
+Parrot_gc_get_system_id(PARROT_INTERP, const char *name)
+{
+ ASSERT_ARGS(Parrot_gc_get_system_id)
+ if (STREQ(name, "MS"))
+ return MS;
+ if (STREQ(name, "MS2"))
+ return MS2;
+ if (STREQ(name, "INF"))
+ return INF;
+ return -1;
+}
+
/*
=item C<void Parrot_gc_mark_PObj_alive(PARROT_INTERP, PObj *obj)>
Oops, something went wrong.

0 comments on commit 9d25cd4

Please sign in to comment.