Skip to content

Commit

Permalink
Add a new function to execute a PackFile* as a program
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Feb 5, 2011
1 parent eb13b10 commit 240d5b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
16 changes: 1 addition & 15 deletions src/embed/api.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -451,21 +451,7 @@ Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
if (!pf) if (!pf)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL, Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"Could not get packfile."); "Could not get packfile.");
if (pf->cur_cs) Parrot_pf_execute_bytecode_program(interp, pf, mainargs);
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);
EMBED_API_CALLOUT(interp_pmc, interp) EMBED_API_CALLOUT(interp_pmc, interp)
} }


Expand Down
21 changes: 21 additions & 0 deletions src/packfile/api.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4487,6 +4487,27 @@ PackFile_read_pbc(PARROT_INTERP, ARGIN(STRING *fullname), const int debug)
return pf; 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);
}



/* /*
Expand Down

0 comments on commit 240d5b7

Please sign in to comment.