Skip to content

Commit

Permalink
Refactor Parrot_interp_compile_file to be less obviously dependent on…
Browse files Browse the repository at this point in the history
… IMCC (though it does still require IMCC internally)
  • Loading branch information
Whiteknight committed Jan 8, 2012
1 parent 7241997 commit 2afe799
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions frontend/parrot_debugger/main.c
Expand Up @@ -203,8 +203,11 @@ main(int argc, const char *argv[])
else {
STRING *str = Parrot_str_new(interp, filename, 0);
Parrot_PackFile pf = Parrot_pf_get_packfile_pmc(interp, PackFile_new(interp, 0), str);
STRING * const compiler_s = Parrot_str_new(interp, "PIR", 0);
PMC * const compiler = Parrot_interp_get_compiler(interp, compiler_s);

Parrot_pf_set_current_packfile(interp, pf);

Parrot_interp_compile_file(interp, str, 0);
/*if (errmsg)
Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not compile file");*/
Expand Down
8 changes: 5 additions & 3 deletions include/parrot/interpreter.h
Expand Up @@ -342,9 +342,10 @@ PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_interp_compile_file(PARROT_INTERP,
ARGIN(STRING *fullname),
INTVAL is_pasm)
ARGIN(PMC *compiler))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
__attribute__nonnull__(2)
__attribute__nonnull__(3);

PARROT_EXPORT
PARROT_CAN_RETURN_NULL
Expand Down Expand Up @@ -510,7 +511,8 @@ void Parrot_interp_really_destroy(PARROT_INTERP, int exit_code, void *arg)
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_interp_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(fullname))
, PARROT_ASSERT_ARG(fullname) \
, PARROT_ASSERT_ARG(compiler))
#define ASSERT_ARGS_Parrot_interp_compile_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(code) \
Expand Down
27 changes: 14 additions & 13 deletions src/interp/api.c
Expand Up @@ -682,14 +682,14 @@ Parrot_interp_set_compiler(PARROT_INTERP, ARGIN(STRING *type), ARGIN(PMC *compil

/*
=item C<PMC * Parrot_interp_compile_file(PARROT_INTERP, STRING *fullname, INTVAL
is_pasm)>
=item C<PMC * Parrot_interp_compile_file(PARROT_INTERP, STRING *fullname, PMC
*compiler)>
Compile code file.
Compile code file. Take a reference to a compiler PMC. Currently only PIR and
PASM compilers (IMCC-based) are supported
TODO: This should take a PMC* option for the compiler to use. Do not assume
we have PIR/PASM compilers installed, and do not assume that the user is
going to want to use either of these. TT #2135.
TODO: This should probably be deleted entirely, and higher-level compilation
abstractions used instead.
=cut
Expand All @@ -698,15 +698,16 @@ going to want to use either of these. TT #2135.
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PMC *
Parrot_interp_compile_file(PARROT_INTERP, ARGIN(STRING *fullname), INTVAL is_pasm)
Parrot_interp_compile_file(PARROT_INTERP, ARGIN(STRING *fullname), ARGIN(PMC *compiler))
{
ASSERT_ARGS(Parrot_interp_compile_file)
PMC * result = NULL;
UINTVAL regs_used[4] = {3, 3, 3, 3};
PMC * const newcontext = Parrot_push_context(interp, regs_used);
STRING * const compiler_s = is_pasm ? CONST_STRING(interp, "PASM") : CONST_STRING(interp, "PIR");
PMC * compiler = Parrot_interp_get_compiler(interp, compiler_s);
imc_info_t *imcc = (imc_info_t *) VTABLE_get_pointer(interp, compiler);
PMC * result = NULL;
UINTVAL regs_used[4] = {3, 3, 3, 3};
PMC * const newcontext = Parrot_push_context(interp, regs_used);
imc_info_t * const imcc = (imc_info_t *) VTABLE_get_pointer(interp, compiler);
const INTVAL is_pasm = VTABLE_get_integer(interp, compiler);

//fprintf(stderr, "\nParrot_interp_compile_file: is_pasm = %d\n", is_pasm);

Parrot_block_GC_mark(interp);
Parrot_pcc_set_HLL(interp, newcontext, 0);
Expand Down
9 changes: 8 additions & 1 deletion src/packfile/api.c
Expand Up @@ -2008,8 +2008,15 @@ static void
compile_file(PARROT_INTERP, ARGIN(STRING *path), INTVAL is_pasm)
{
ASSERT_ARGS(compile_file)
//fprintf(stderr, "\ncompile_file: is_pasm = %d\n", is_pasm);
PackFile_ByteCode * const cur_code = interp->code;
PMC * const pf_pmc = Parrot_interp_compile_file(interp, path, is_pasm);
PMC * compiler;
if (is_pasm)
compiler = Parrot_interp_get_compiler(interp, CONST_STRING(interp, "PASM"));
else
compiler = Parrot_interp_get_compiler(interp, CONST_STRING(interp, "PIR"));
//fprintf(stderr, "\ncompile_file: is_pasm = %d\n", VTABLE_get_integer(interp, compiler));
PMC * const pf_pmc = Parrot_interp_compile_file(interp, path, compiler);
PMC * const pbc_cache = VTABLE_get_pmc_keyed_int(interp,
interp->iglobals, IGLOBALS_LOADED_PBCS);
PackFile * const pf = (PackFile*) VTABLE_get_pointer(interp, pf_pmc);
Expand Down

0 comments on commit 2afe799

Please sign in to comment.