Permalink
Browse files

Add a new function to execute a PackFile* as a program

  • Loading branch information...
1 parent eb13b10 commit 240d5b77cfcd18cfeff49a49a39df326dc452194 @Whiteknight Whiteknight committed Feb 5, 2011
Showing with 22 additions and 15 deletions.
  1. +1 −15 src/embed/api.c
  2. +21 −0 src/packfile/api.c
View
@@ -451,21 +451,7 @@ Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
if (!pf)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"Could not get packfile.");
- if (pf->cur_cs)
- Parrot_pf_set_current_packfile(interp, pf);
- PackFile_fixup_subs(interp, PBC_MAIN, NULL);
- main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
-
- /* if no sub was marked being :main, we create a dummy sub with offset 0 */
-
- if (!main_sub)
- main_sub = set_current_sub(interp);
-
- Parrot_pcc_set_sub(interp, CURRENT_CONTEXT(interp), NULL);
- Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
-
- VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST, mainargs);
- Parrot_pcc_invoke_sub_from_c_args(interp, main_sub, "P->", mainargs);
+ Parrot_pf_execute_bytecode_program(interp, pf, mainargs);
EMBED_API_CALLOUT(interp_pmc, interp)
}
View
@@ -4487,6 +4487,27 @@ PackFile_read_pbc(PARROT_INTERP, ARGIN(STRING *fullname), const int debug)
return pf;
}
+void
+Parrot_pf_execute_bytecode_program(PARROT_INTERP, ARGMOD(PackFile *pf), ARGMOD(PMC *args))
+{
+ ASSERT_ARGS(Parrot_pf_execute_bytecode_program)
+ if (pf->cur_cs)
+ Parrot_pf_set_current_packfile(interp, pf);
+ PackFile_fixup_subs(interp, PBC_MAIN, NULL);
+ main_sub = Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp));
+
+ /* if no sub was marked being :main, we create a dummy sub with offset 0 */
+
+ if (!main_sub)
+ main_sub = set_current_sub(interp);
+
+ Parrot_pcc_set_sub(interp, CURRENT_CONTEXT(interp), NULL);
+ Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
+
+ VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST, args);
+ Parrot_pcc_invoke_sub_from_c_args(interp, main_sub, "P->", args);
+}
+
/*

0 comments on commit 240d5b7

Please sign in to comment.