From 2afe799a3630222c7868cfd4ac98bb53b52a6bb7 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 8 Jan 2012 11:12:18 -0500 Subject: [PATCH] Refactor Parrot_interp_compile_file to be less obviously dependent on IMCC (though it does still require IMCC internally) --- frontend/parrot_debugger/main.c | 3 +++ include/parrot/interpreter.h | 8 +++++--- src/interp/api.c | 27 ++++++++++++++------------- src/packfile/api.c | 9 ++++++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/frontend/parrot_debugger/main.c b/frontend/parrot_debugger/main.c index 38085cc07c..d5a0a23557 100644 --- a/frontend/parrot_debugger/main.c +++ b/frontend/parrot_debugger/main.c @@ -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");*/ diff --git a/include/parrot/interpreter.h b/include/parrot/interpreter.h index dc8ade1a44..9dce7896a3 100644 --- a/include/parrot/interpreter.h +++ b/include/parrot/interpreter.h @@ -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 @@ -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) \ diff --git a/src/interp/api.c b/src/interp/api.c index 0ee4afceb3..0b037f0282 100644 --- a/src/interp/api.c +++ b/src/interp/api.c @@ -682,14 +682,14 @@ Parrot_interp_set_compiler(PARROT_INTERP, ARGIN(STRING *type), ARGIN(PMC *compil /* -=item C +=item C -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 @@ -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); diff --git a/src/packfile/api.c b/src/packfile/api.c index 3dac0b425a..80b4479475 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -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);