Permalink
Browse files

lots of little changes

  • Loading branch information...
1 parent 669ccd4 commit 4a128d50a77c603d481d180cef3be01b71a4637b @Whiteknight Whiteknight committed Nov 9, 2010
Showing with 44 additions and 25 deletions.
  1. +26 −11 src/{embed_api.c → embed/api.c}
  2. +4 −2 src/global_setup.c
  3. +14 −12 src/main.c
@@ -19,26 +19,29 @@
PARROT_API
PARROT_CANNOT_RETURN_NULL
PARROT_MALLOC
-Parrot_Interp
+Parrot_Interp *
Parrot_api_make_interpreter(ARGIN_NULLOK(PMC *parent), INTVAL flags)
{
ASSERT_ARGS(Parrot_api_make_interpreter)
Parrot_set_config_hash();
- Interp * const parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
- Interp * const interp = allocate_interpreter(parent, flags);
+ Parrot_Interp * const parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
+ Parrot_Interp * const interp = allocate_interpreter(parent, flags);
return interp;
}
PARROT_API
INTVAL
-Parrot_api_initialize_interpreter(ARGIN(PMC *interp_pmc))
+Parrot_api_initialize_interpreter(ARGIN(Parrot_Interp *interp), ARGIN_NULLOK(void * stacktop), ARGOUT(PMC ** interp_pmc))
{
ASSERT_ARGS(Parrot_api_initialize_interpreter)
- int stacktop;
+ int alt_stacktop;
if (PMC_IS_NULL(interp_pmc)
return;
- Interp * const interp = GET_RAW_INTERP(interp_pmc);
- initialize_interpreter(interp, (void*)&stacktop);
+ if (stacktop == NULL)
+ stacktop = &alt_stacktop;
+ initialize_interpreter(interp, stacktop);
+ *interp_pmc = VTABLE_get_pmc_keyed_int(interp, iglobals, (INTVAL)IGLOBALS_INTERPRETER);
+ return (!PMC_IS_NULL(interp_pmc);
}
PARROT_API
@@ -59,21 +62,32 @@ INTVAL
Parrot_api_set_executable_name(ARGIN(PMC *interp_pmc), ARGIN(Parrot_String) name)
{
ASSERT_ARGS(Parrot_api_set_executable_name)
- EMBED_API_CALLIN(interp_pmc, interp)
+ EMBED_API_CALLIN(interp_pmc, interp);
PMC * const name_pmc = Parrot_pmc_new(interp, enum_class_String);
VTABLE_set_string_native(interp, name_pmc, name);
VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
name_pmc);
- EMBED_API_CALLOUT(interp_pmc, interp)
+ EMBED_API_CALLOUT(interp_pmc, interp);
}
PARROT_API
void
Parrot_api_destroy_interpreter(ARGIN(PMC *interp_pmc))
{
ASSERT_ARGS(Parrot_api_destroy_interpreter)
- Interp * const interp = GET_RAW_PMC(interp_pmc);
+ EMBED_API_CALLIN(interp_pmc, interp);
Parrot_destroy(interp);
+ EMBED_API_CALLOUT(interp_pmc, interp);
+}
+
+PARROT_API
+void
+Parrot_api_exit_interpreter(ARGIN(PMC *interp_pmc))
+{
+ ASSERT_ARGS(Parrot_api_exit_interpreter)
+ EMBED_API_CALLIN(interp_pmc, interp);
+ Parrot_exit(interp);
+ EMBED_API_CALLOUT(interp_pmc, interp);
}
/*
@@ -90,7 +104,7 @@ stream.
PARROT_API
INTVAL
-Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filename), ARGOUT(INTVAL *result))
+Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filename), ARGOUT(PMC *)
{
ASSERT_ARGS(Parrot_api_load_bytecode_file)
EMBED_API_CALLIN(interp_pmc, interp);
@@ -102,3 +116,4 @@ Parrot_api_load_bytecode_file(ARGMOD(PMC *interp_pmc), ARGIN(const char *filenam
*result = 1;
EMBED_API_CALLOUT(interp_pmc, interp);
}
+
View
@@ -72,8 +72,10 @@ Parrot_set_config_hash_internal(ARGIN(const unsigned char* parrot_config),
unsigned int parrot_config_size)
{
ASSERT_ARGS(Parrot_set_config_hash_internal)
- parrot_config_stored = parrot_config;
- parrot_config_size_stored = parrot_config_size;
+ if (parrot_config_stored != NULL) {
+ parrot_config_stored = parrot_config;
+ parrot_config_size_stored = parrot_config_size;
+ }
}
/*
View
@@ -115,7 +115,8 @@ main(int argc, const char *argv[])
int stacktop;
const char *sourcefile;
const char *execname;
- Interp *interp;
+ Interp *raw_interp;
+ PMC *interp;
int status;
int pir_argc;
const char **pir_argv;
@@ -128,36 +129,37 @@ main(int argc, const char *argv[])
PARROT_BINDTEXTDOMAIN(PACKAGE, LOCALEDIR);
PARROT_TEXTDOMAIN(PACKAGE);
- Parrot_set_config_hash();
-
- interp = allocate_interpreter(NULL, PARROT_NO_FLAGS);
+ raw_interp = Parrot_api_make_interpreter(NULL, PARROT_NO_FLAGS);
/* We parse the arguments, but first store away the name of the Parrot
executable, since parsing destroys that and we want to make it
available. */
execname = argv[0];
/* Parse minimal subset of flags */
- parseflags_minimal(interp, argc, argv);
+ parseflags_minimal(raw_interp, argc, argv);
/* Now initialize interpreter */
- initialize_interpreter(interp, (void*)&stacktop);
+ if (!Parrot_api_initialize_interpreter(raw_interp, (void*)&stacktop, &interp)) {
+ fprintf("PARROT VM: Could not initialize new interpreter");
+ exit(EXIT_FAILURE);
+ }
/* Parse flags */
sourcefile = parseflags(interp, argc, argv, &pir_argc, &pir_argv, &core, &trace);
- Parrot_set_trace(interp, trace);
- Parrot_set_run_core(interp, (Parrot_Run_core_t) core);
- Parrot_set_executable_name(interp, Parrot_str_new(interp, execname, 0));
+ Parrot_api_set_runcore(interp, (Parrot_Run_core_t) core, trace);
+ // TODO: Parrot_str_new -> Parrot_api_str_new
+ Parrot_api_set_executable_name(interp, Parrot_str_new(interp, execname, 0)
- status = imcc_run(interp, sourcefile, argc, argv);
+ status = imcc_run(raw, interp, sourcefile, argc, argv);
if (status)
imcc_run_pbc(interp, interp->output_file, pir_argc, pir_argv);
/* Clean-up after ourselves */
- Parrot_destroy(interp);
- Parrot_exit(interp, 0);
+ Parrot_api_destroy_interpreter(interp);
+ Parrot_api_exit_interpreter(interp, 0);
}
#define SET_FLAG(flag) Parrot_set_flag(interp, (flag))

0 comments on commit 4a128d5

Please sign in to comment.