From 5a85e76fa2445f0f9a0455aa636496e884a3ead7 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 6 Jan 2011 20:09:20 -0500 Subject: [PATCH 01/28] remove PackFile_new_dummy. A few test failures pop up --- src/embed.c | 9 --------- src/packfile/api.c | 36 +++++------------------------------- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/src/embed.c b/src/embed.c index 1a58869635..3ba9d1d07f 100644 --- a/src/embed.c +++ b/src/embed.c @@ -1131,15 +1131,6 @@ Parrot_compile_string(PARROT_INTERP, Parrot_String type, ARGIN(const char *code) /* For the benefit of embedders that do not load any pbc * before compiling a string */ - if (!interp->initial_pf) { - /* SIDE EFFECT: PackFile_new_dummy sets interp->initial_pf */ - interp->initial_pf = PackFile_new_dummy(interp, CONST_STRING(interp, "compile_string")); - /* Assumption: there is no valid reason to fail to create it. - * If the assumption changes, replace the assertion with a - * runtime check */ - PARROT_ASSERT(interp->initial_pf); - } - if (STRING_equal(interp, CONST_STRING(interp, "PIR"), type)) return IMCC_compile_pir_s(interp, code, error); diff --git a/src/packfile/api.c b/src/packfile/api.c index 64d705a3e9..51707e4c71 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -1464,35 +1464,6 @@ PackFile_new(PARROT_INTERP, INTVAL is_mapped) return pf; } - -/* - -=item C - -Creates a new (initial) dummy PackFile. This is necessary if the interpreter -doesn't load any bytecode but instead uses C. - -=cut - -*/ - -PARROT_EXPORT -PARROT_WARN_UNUSED_RESULT -PARROT_CAN_RETURN_NULL -PackFile * -PackFile_new_dummy(PARROT_INTERP, ARGIN(STRING *name)) -{ - ASSERT_ARGS(PackFile_new_dummy) - - PackFile * const pf = PackFile_new(interp, 0); - interp->initial_pf = pf; - interp->code = pf->cur_cs - = PF_create_default_segs(interp, name, 1); - - return pf; -} - - /* =item Cinitial_pf) { - interp->initial_pf = PackFile_new_dummy(interp, CONST_STRING(interp, "dummy")); - /* PackFile_new_dummy must never fail */ + PackFile * const pf = PackFile_new(interp, 0); + STRING * const name = CONST_STRING(interp, "dummy"); + interp->initial_pf = pf; + interp->code = pf->cur_cs + = PF_create_default_segs(interp, name, 1); PARROT_ASSERT(interp->initial_pf); } PackFile_add_segment(interp, &interp->initial_pf->directory, From 74c1720d570839599151113b3cafbac2f9740662 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Wed, 12 Jan 2011 11:29:44 -0500 Subject: [PATCH 02/28] PackFile_append_pbc is renamed PackFile_append, and takes a PackFile argument instead of a char* filename --- include/parrot/packfile.h | 10 ---------- src/packfile/api.c | 18 +++++++++--------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/parrot/packfile.h b/include/parrot/packfile.h index f1af40674d..9512db304d 100644 --- a/include/parrot/packfile.h +++ b/include/parrot/packfile.h @@ -764,13 +764,6 @@ PARROT_CANNOT_RETURN_NULL PackFile * PackFile_new(PARROT_INTERP, INTVAL is_mapped) __attribute__nonnull__(1); -PARROT_EXPORT -PARROT_WARN_UNUSED_RESULT -PARROT_CAN_RETURN_NULL -PackFile * PackFile_new_dummy(PARROT_INTERP, ARGIN(STRING *name)) - __attribute__nonnull__(1) - __attribute__nonnull__(2); - PARROT_EXPORT void PackFile_Segment_destroy(PARROT_INTERP, ARGMOD(PackFile_Segment *self)) __attribute__nonnull__(1) @@ -1005,9 +998,6 @@ void Parrot_trace_eprintf(ARGIN(const char *s), ...) , PARROT_ASSERT_ARG(dir)) #define ASSERT_ARGS_PackFile_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp)) -#define ASSERT_ARGS_PackFile_new_dummy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(name)) #define ASSERT_ARGS_PackFile_Segment_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(self)) diff --git a/src/packfile/api.c b/src/packfile/api.c index e7ced034fd..b0d110bfb4 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -240,8 +240,8 @@ static void mark_1_ct_seg(PARROT_INTERP, ARGMOD(PackFile_ConstTable *ct)) PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL -static PackFile * PackFile_append_pbc(PARROT_INTERP, - ARGIN_NULLOK(const char *filename)) +static PackFile * PackFile_append(PARROT_INTERP, + ARGIN_NULLOK(PackFile * const pf)) __attribute__nonnull__(1); PARROT_WARN_UNUSED_RESULT @@ -419,7 +419,7 @@ static int sub_pragma(PARROT_INTERP, #define ASSERT_ARGS_mark_1_ct_seg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(ct)) -#define ASSERT_ARGS_PackFile_append_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ +#define ASSERT_ARGS_PackFile_append __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp)) #define ASSERT_ARGS_PackFile_Constant_unpack_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ @@ -4206,7 +4206,8 @@ compile_or_load_file(PARROT_INTERP, ARGIN(STRING *path), Parrot_hll_get_HLL_namespace(interp, parrot_hll_id)); if (file_type == PARROT_RUNTIME_FT_PBC) { - PackFile * const pf = PackFile_append_pbc(interp, filename); + PackFile * pf = Parrot_pbc_read(interp, filename, 0); + pf = PackFile_append(interp, pf); Parrot_str_free_cstring(filename); if (!pf) @@ -4315,8 +4316,8 @@ Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name)) /* -=item C +=item C Reads and appends a PBC it to the current directory. Fixes up sub addresses in newly loaded bytecode and runs C<:load> subs. @@ -4328,10 +4329,9 @@ newly loaded bytecode and runs C<:load> subs. PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static PackFile * -PackFile_append_pbc(PARROT_INTERP, ARGIN_NULLOK(const char *filename)) +PackFile_append(PARROT_INTERP, ARGIN_NULLOK(PackFile * const pf)) { - ASSERT_ARGS(PackFile_append_pbc) - PackFile * const pf = Parrot_pbc_read(interp, filename, 0); + ASSERT_ARGS(PackFile_append) if (pf) { /* An embedder can try to load_bytecode without having an initial_pf */ From fa6d538430e45b9bc8307715ce6728b63fa6c4dd Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Wed, 12 Jan 2011 15:34:54 -0500 Subject: [PATCH 03/28] make sure initial_pf is in place whenever we build default segs --- src/packfile/api.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/packfile/api.c b/src/packfile/api.c index b0d110bfb4..c454c0e186 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -1773,18 +1773,27 @@ PackFile_ByteCode * PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), int add) { ASSERT_ARGS(PF_create_default_segs) - PackFile * const pf = interp->initial_pf; - PackFile_ByteCode * const cur_cs = - (PackFile_ByteCode *)create_seg(interp, &pf->directory, - PF_BYTEC_SEG, BYTE_CODE_SEGMENT_NAME, file_name, add); - cur_cs->const_table = - (PackFile_ConstTable *)create_seg(interp, &pf->directory, - PF_CONST_SEG, CONSTANT_SEGMENT_NAME, file_name, add); + /* create an initial_pf if we don't already have one */ + if (!interp->initial_pf) { + PackFile * const pf = PackFile_new(interp, 0); + interp->initial_pf = pf; + } - cur_cs->const_table->code = cur_cs; + { + PackFile * const pf = interp->initial_pf; + PackFile_ByteCode * const cur_cs = + (PackFile_ByteCode *)create_seg(interp, &pf->directory, + PF_BYTEC_SEG, BYTE_CODE_SEGMENT_NAME, file_name, add); - return cur_cs; + cur_cs->const_table = + (PackFile_ConstTable *)create_seg(interp, &pf->directory, + PF_CONST_SEG, CONSTANT_SEGMENT_NAME, file_name, add); + + cur_cs->const_table->code = cur_cs; + + return cur_cs; + } } @@ -4334,13 +4343,9 @@ PackFile_append(PARROT_INTERP, ARGIN_NULLOK(PackFile * const pf)) ASSERT_ARGS(PackFile_append) if (pf) { - /* An embedder can try to load_bytecode without having an initial_pf */ if (!interp->initial_pf) { - PackFile * const pf = PackFile_new(interp, 0); STRING * const name = CONST_STRING(interp, "dummy"); - interp->initial_pf = pf; - interp->code = pf->cur_cs - = PF_create_default_segs(interp, name, 1); + interp->code = PF_create_default_segs(interp, name, 1); PARROT_ASSERT(interp->initial_pf); } PackFile_add_segment(interp, &interp->initial_pf->directory, From 9d9cd51abc2a5b9f01557d077775a5842f0c7b81 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 09:17:34 -0500 Subject: [PATCH 04/28] We always need an initial_pf, so just create it when we initialize the interpreter. Then we don't need to be checking for it later --- src/interp/inter_create.c | 1 + src/packfile/api.c | 32 ++++++++++++-------------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/interp/inter_create.c b/src/interp/inter_create.c index b9788ceee3..f19b0a0cbb 100644 --- a/src/interp/inter_create.c +++ b/src/interp/inter_create.c @@ -256,6 +256,7 @@ initialize_interpreter(PARROT_INTERP, ARGIN(void *stacktop)) interp->all_op_libs = NULL; interp->evc_func_table = NULL; interp->evc_func_table_size = 0; + interp->initial_pf = PackFile_new(interp, 0); interp->code = NULL; /* And a dynamic environment stack */ diff --git a/src/packfile/api.c b/src/packfile/api.c index c454c0e186..9ad6ffa025 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -1773,27 +1773,18 @@ PackFile_ByteCode * PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), int add) { ASSERT_ARGS(PF_create_default_segs) + PackFile * const pf = interp->initial_pf; + PackFile_ByteCode * const cur_cs = + (PackFile_ByteCode *)create_seg(interp, &pf->directory, + PF_BYTEC_SEG, BYTE_CODE_SEGMENT_NAME, file_name, add); - /* create an initial_pf if we don't already have one */ - if (!interp->initial_pf) { - PackFile * const pf = PackFile_new(interp, 0); - interp->initial_pf = pf; - } - - { - PackFile * const pf = interp->initial_pf; - PackFile_ByteCode * const cur_cs = - (PackFile_ByteCode *)create_seg(interp, &pf->directory, - PF_BYTEC_SEG, BYTE_CODE_SEGMENT_NAME, file_name, add); + cur_cs->const_table = + (PackFile_ConstTable *)create_seg(interp, &pf->directory, + PF_CONST_SEG, CONSTANT_SEGMENT_NAME, file_name, add); - cur_cs->const_table = - (PackFile_ConstTable *)create_seg(interp, &pf->directory, - PF_CONST_SEG, CONSTANT_SEGMENT_NAME, file_name, add); + cur_cs->const_table->code = cur_cs; - cur_cs->const_table->code = cur_cs; - - return cur_cs; - } + return cur_cs; } @@ -4341,12 +4332,13 @@ static PackFile * PackFile_append(PARROT_INTERP, ARGIN_NULLOK(PackFile * const pf)) { ASSERT_ARGS(PackFile_append) + PARROT_ASSERT(interp->initial_pf); if (pf) { - if (!interp->initial_pf) { + if (!interp->code) { STRING * const name = CONST_STRING(interp, "dummy"); interp->code = PF_create_default_segs(interp, name, 1); - PARROT_ASSERT(interp->initial_pf); + PARROT_ASSERT(interp->code); } PackFile_add_segment(interp, &interp->initial_pf->directory, &pf->directory.base); From fc0f759060202a29ee43952bc236cd11c8ce95f0 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 09:45:03 -0500 Subject: [PATCH 05/28] Add some accessors for interp->initial_pf and interp->code to the packfile API. Add a new function to set a packfile as the itnerp's current packfile. Use this new function to reimplement Parrot_pbc_load, and replace several uses of Parrot_pbc_load with Parrot_pf_set_current_packfile. While I'm there, use some proper values for Exception type in embedding api --- compilers/imcc/main.c | 6 ++-- include/parrot/packfile.h | 22 +++++++++++++++ src/embed.c | 12 ++------ src/embed/api.c | 30 +++++++++++--------- src/packfile/api.c | 59 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 102 insertions(+), 27 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index d674b7d76d..3d51260e69 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -614,7 +614,7 @@ compile_to_bytecode(PARROT_INTERP, opt_desc, opt_level); pf = PackFile_new(interp, 0); - Parrot_pbc_load(interp, pf); + Parrot_pf_set_current_packfile(interp, pf); IMCC_push_parser_state(interp); IMCC_INFO(interp)->state->file = mem_sys_strdup(sourcefile); @@ -736,7 +736,7 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, pf_raw = Parrot_pbc_read(interp, sourcefile, 0); if (!pf_raw) IMCC_fatal_standalone(interp, 1, "main: Packfile loading failed\n"); - Parrot_pbc_load(interp, pf_raw); + Parrot_pf_set_current_packfile(interp, pf_raw); } else pf_raw = compile_to_bytecode(interp, sourcefile, output_file, yyscanner); @@ -755,7 +755,7 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, pf_raw = Parrot_pbc_read(interp, output_file, 0); if (!pf_raw) IMCC_fatal_standalone(interp, 1, "Packfile loading failed\n"); - Parrot_pbc_load(interp, pf_raw); + Parrot_pf_set_current_packfile(interp, pf_raw); SET_STATE_LOAD_PBC(interp); } } diff --git a/include/parrot/packfile.h b/include/parrot/packfile.h index 9512db304d..1d55e45614 100644 --- a/include/parrot/packfile.h +++ b/include/parrot/packfile.h @@ -877,6 +877,12 @@ PackFile_Debug * Parrot_new_debug_seg(PARROT_INTERP, __attribute__nonnull__(2) FUNC_MODIFIES(*cs); +PARROT_EXPORT +void Parrot_pf_set_current_packfile(PARROT_INTERP, + ARGIN(PackFile * const pf)) + __attribute__nonnull__(1) + __attribute__nonnull__(2); + PARROT_EXPORT PARROT_IGNORABLE_RESULT PARROT_CANNOT_RETURN_NULL @@ -945,6 +951,12 @@ const opcode_t * PackFile_Annotations_unpack(PARROT_INTERP, __attribute__nonnull__(3) FUNC_MODIFIES(*seg); +PackFile_ByteCode * Parrot_pf_get_current_code_segment(PARROT_INTERP) + __attribute__nonnull__(1); + +PackFile * Parrot_pf_get_current_packfile(PARROT_INTERP) + __attribute__nonnull__(1); + void Parrot_trace_eprintf(ARGIN(const char *s), ...) __attribute__nonnull__(1); @@ -1041,6 +1053,10 @@ void Parrot_trace_eprintf(ARGIN(const char *s), ...) #define ASSERT_ARGS_Parrot_new_debug_seg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(cs)) +#define ASSERT_ARGS_Parrot_pf_set_current_packfile \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(pf)) #define ASSERT_ARGS_Parrot_switch_to_cs __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(new_cs)) @@ -1071,6 +1087,12 @@ void Parrot_trace_eprintf(ARGIN(const char *s), ...) PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(seg) \ , PARROT_ASSERT_ARG(cursor)) +#define ASSERT_ARGS_Parrot_pf_get_current_code_segment \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp)) +#define ASSERT_ARGS_Parrot_pf_get_current_packfile \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp)) #define ASSERT_ARGS_Parrot_trace_eprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(s)) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ diff --git a/src/embed.c b/src/embed.c index 3ba9d1d07f..52840dae3d 100644 --- a/src/embed.c +++ b/src/embed.c @@ -597,13 +597,7 @@ void Parrot_pbc_load(PARROT_INTERP, ARGIN(Parrot_PackFile pf)) { ASSERT_ARGS(Parrot_pbc_load) - if (!pf) { - Parrot_io_eprintf(interp, "Invalid packfile\n"); - return; - } - - interp->initial_pf = pf; - interp->code = pf->cur_cs; + Parrot_pf_set_current_packfile(interp, pf); } /* @@ -628,7 +622,7 @@ Parrot_load_bytecode_file(PARROT_INTERP, ARGIN(const char *filename)) Parrot_warn_experimental(interp, "Parrot_load_bytecode_file is experimental"); if (!pf) return 0; - Parrot_pbc_load(interp, pf); + Parrot_pf_set_current_packfile(interp, pf); return 1; } @@ -1100,7 +1094,7 @@ Parrot_run_native(PARROT_INTERP, native_func_t func) pf->cur_cs->op_func_table = op_func_table; /* TODO fill out cur_cs with op_mapping */ - Parrot_pbc_load(interp, pf); + Parrot_pf_set_current_packfile(interp, pf); run_native = func; diff --git a/src/embed/api.c b/src/embed/api.c index c1f01ae4dd..98e9014e22 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -328,7 +328,8 @@ Parrot_api_load_bytecode_file(Parrot_PMC interp_pmc, EMBED_API_CALLIN(interp_pmc, interp) PackFile * const pf = Parrot_pbc_read(interp, filename, 0); if (!pf) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not load packfile"); + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE, + "Could not load packfile"); do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL); *pbc = Parrot_pmc_new(interp, enum_class_UnManagedStruct); VTABLE_set_pointer(interp, *pbc, pf); @@ -357,11 +358,11 @@ Parrot_api_load_bytecode_bytes(Parrot_PMC interp_pmc, ASSERT_ARGS(Parrot_api_load_bytecode_bytes) EMBED_API_CALLIN(interp_pmc, interp) PackFile * const pf = PackFile_new(interp, 0); - if (!pf) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not create packfile"); + PARROT_ASSERT(pf); if (!PackFile_unpack(interp, pf, (const opcode_t *)pbc, bytecode_size)) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "could not unpack packfile"); + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE, + "could not unpack packfile"); do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL); *pbcpmc = Parrot_pmc_new(interp, enum_class_UnManagedStruct); VTABLE_set_pointer(interp, *pbcpmc, pf); @@ -401,9 +402,10 @@ Parrot_api_ready_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, } if (!pf) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile"); - if (pf->cur_cs != NULL) - Parrot_pbc_load(interp, 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)); Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table); @@ -441,9 +443,10 @@ Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, } if (!pf) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile"); - if (pf->cur_cs != NULL) - Parrot_pbc_load(interp, 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)); @@ -481,9 +484,10 @@ Parrot_api_disassemble_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, EMBED_API_CALLIN(interp_pmc, interp) PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc); if (!pf) - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Could not get packfile"); - if (pf->cur_cs != NULL) - Parrot_pbc_load(interp, 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); /* TODO: Break up the dependency with emebed.c */ Parrot_disassemble(interp, outfile, (Parrot_disassemble_options)opts); EMBED_API_CALLOUT(interp_pmc, interp); diff --git a/src/packfile/api.c b/src/packfile/api.c index 9ad6ffa025..fe19bcda56 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -1752,6 +1752,62 @@ create_seg(PARROT_INTERP, ARGMOD(PackFile_Directory *dir), pack_file_types t, return seg; } +/* + +=item C + +Get the interpreter's currently active PackFile + +=cut + +*/ + +PackFile * +Parrot_pf_get_current_packfile(PARROT_INTERP) +{ + ASSERT_ARGS(Parrot_pf_get_current_packfile) + return interp->initial_pf; +} + +/* + +=item C + +Get's the interpreter's currently active bytecode segment + +=cut + +*/ + +PackFile_ByteCode * +Parrot_pf_get_current_code_segment(PARROT_INTERP) +{ + ASSERT_ARGS(Parrot_pf_get_current_code_segment) + return interp->code; +} + +/* + +=item C + +Set's the current packfile for the interpreter. + +=cut + +*/ + +PARROT_EXPORT +void +Parrot_pf_set_current_packfile(PARROT_INTERP, ARGIN(PackFile * const pf)) +{ + ASSERT_ARGS(Parrot_pf_set_current_packfile) + if (!pf) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL, + "Cannot set null packfile"); + + interp->initial_pf = pf; + interp->code = pf->cur_cs; +} /* @@ -4316,8 +4372,7 @@ Parrot_load_language(PARROT_INTERP, ARGIN_NULLOK(STRING *lang_name)) /* -=item C +=item C Reads and appends a PBC it to the current directory. Fixes up sub addresses in newly loaded bytecode and runs C<:load> subs. From 21b259b596a1e1224206bccab4c73ccc5b460d54 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 10:40:42 -0500 Subject: [PATCH 06/28] create a new function Parrot_pf_create_default_segments to start replacing PF_create_default_segs. Add a new parameter to PF_create_default_segs that forces us to update interp->code, so we don't need to do the assignment in IMCC --- compilers/imcc/main.c | 8 ++++++-- compilers/imcc/parser_util.c | 3 ++- compilers/imcc/pbc.c | 8 +++++--- include/parrot/packfile.h | 20 ++++++++++++++++++- src/packfile/api.c | 38 ++++++++++++++++++++++++++++++++---- 5 files changed, 66 insertions(+), 11 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 3d51260e69..b817904d27 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -491,14 +491,15 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file)) size_t size; opcode_t *packed; FILE *fp; + PackFile_ByteCode * interp_code = Parrot_pf_get_current_code_segment(interp); IMCC_info(interp, 1, "Writing %s\n", output_file); - size = PackFile_pack_size(interp, interp->code->base.pf) * + size = PackFile_pack_size(interp, interp_code->base.pf) * sizeof (opcode_t); IMCC_info(interp, 1, "packed code %d bytes\n", size); packed = (opcode_t*) mem_sys_allocate(size); - PackFile_pack(interp, interp->code->base.pf, packed); + PackFile_pack(interp, interp_code->base.pf, packed); if (STREQ(output_file, "-")) fp = stdout; else if ((fp = fopen(output_file, "wb")) == NULL) @@ -615,6 +616,9 @@ compile_to_bytecode(PARROT_INTERP, pf = PackFile_new(interp, 0); Parrot_pf_set_current_packfile(interp, pf); + /* If I comment out the above two lines and replace with this one below, + Parrot builds and all tests pass. */ + /*pf = Parrot_pf_get_current_packfile(interp);*/ IMCC_push_parser_state(interp); IMCC_INFO(interp)->state->file = mem_sys_strdup(sourcefile); diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 34b4ea8b46..090fbb5db7 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -528,6 +528,7 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, { ASSERT_ARGS(imcc_compile) /* imcc always compiles to interp->code + * XXX: This is EXTREMELY bad. IMCC should not write to interp->code * save old cs, make new */ STRING *name; @@ -564,7 +565,7 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, UNLOCK(eval_nr_lock); name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number); - new_cs = PF_create_default_segs(interp, name, 0); + new_cs = PF_create_default_segs(interp, name, 0, 0); old_cs = Parrot_switch_to_cs(interp, new_cs, 0); IMCC_INFO(interp)->cur_namespace = NULL; diff --git a/compilers/imcc/pbc.c b/compilers/imcc/pbc.c index c5dbe04bf8..2b206cd3d8 100644 --- a/compilers/imcc/pbc.c +++ b/compilers/imcc/pbc.c @@ -326,7 +326,8 @@ static int add_const_table_pmc(PARROT_INTERP, ARGIN(PMC *pmc)) { ASSERT_ARGS(add_const_table_pmc) - PackFile_ConstTable *ct = interp->code->const_table; + PackFile_ByteCode * const bc = Parrot_pf_get_current_code_segment(interp); + PackFile_ConstTable * const ct = bc->const_table; if (!ct->pmc.constants) ct->pmc.constants = @@ -357,6 +358,7 @@ int e_pbc_open(PARROT_INTERP, SHIM(const char *param)) { ASSERT_ARGS(e_pbc_open) + PackFile_ByteCode * const current_bc = Parrot_pf_get_current_code_segment(interp); code_segment_t * const cs = mem_gc_allocate_zeroed_typed(interp, code_segment_t); if (!IMCC_INFO(interp)->globals) @@ -384,12 +386,12 @@ e_pbc_open(PARROT_INTERP, SHIM(const char *param)) cs->prev->next = cs; /* we need some segments */ - if (!interp->code) { + if (!current_bc) { const char *n = IMCC_INFO(interp)->state->file; STRING *name = Parrot_str_new(interp, n, strlen(n)); PMC *self; - cs->seg = interp->code = PF_create_default_segs(interp, name, 1); + cs->seg = PF_create_default_segs(interp, name, 1, 1); } IMCC_INFO(interp)->globals->cs = cs; diff --git a/include/parrot/packfile.h b/include/parrot/packfile.h index 1d55e45614..5c53f8a20e 100644 --- a/include/parrot/packfile.h +++ b/include/parrot/packfile.h @@ -877,6 +877,18 @@ PackFile_Debug * Parrot_new_debug_seg(PARROT_INTERP, __attribute__nonnull__(2) FUNC_MODIFIES(*cs); +PARROT_EXPORT +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PackFile_ByteCode * Parrot_pf_create_default_segments(PARROT_INTERP, + ARGMOD(PackFile * const pf), + ARGIN(STRING * file_name), + int add) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(* const pf); + PARROT_EXPORT void Parrot_pf_set_current_packfile(PARROT_INTERP, ARGIN(PackFile * const pf)) @@ -897,7 +909,8 @@ PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PackFile_ByteCode * PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), - int add) + int add, + int set_def) __attribute__nonnull__(1) __attribute__nonnull__(2); @@ -1053,6 +1066,11 @@ void Parrot_trace_eprintf(ARGIN(const char *s), ...) #define ASSERT_ARGS_Parrot_new_debug_seg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(cs)) +#define ASSERT_ARGS_Parrot_pf_create_default_segments \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(pf) \ + , PARROT_ASSERT_ARG(file_name)) #define ASSERT_ARGS_Parrot_pf_set_current_packfile \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ diff --git a/src/packfile/api.c b/src/packfile/api.c index fe19bcda56..6929273e5e 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -1812,7 +1812,7 @@ Parrot_pf_set_current_packfile(PARROT_INTERP, ARGIN(PackFile * const pf)) /* =item C +*file_name, int add, int set_def)> Creates the bytecode and constant segments for C. If C is true, the current packfile becomes the owner of these segments by adding the @@ -1826,14 +1826,42 @@ PARROT_EXPORT PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PackFile_ByteCode * -PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), int add) +PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), int add, int set_def) { ASSERT_ARGS(PF_create_default_segs) - PackFile * const pf = interp->initial_pf; + PackFile_ByteCode * const bc = Parrot_pf_create_default_segments(interp, + interp->initial_pf, file_name, add); + if (set_def) + interp->code = bc; + return bc; +} + +/* + +=item C + +Create the default seguments for the given packfile. Return the ByteCode +segment created. + +=cut + +*/ + +PARROT_EXPORT +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PackFile_ByteCode * +Parrot_pf_create_default_segments(PARROT_INTERP, ARGMOD(PackFile * const pf), + ARGIN(STRING * file_name), int add) +{ + ASSERT_ARGS(Parrot_pf_create_default_segments) PackFile_ByteCode * const cur_cs = (PackFile_ByteCode *)create_seg(interp, &pf->directory, PF_BYTEC_SEG, BYTE_CODE_SEGMENT_NAME, file_name, add); + PARROT_ASSERT(cur_cs); + cur_cs->const_table = (PackFile_ConstTable *)create_seg(interp, &pf->directory, PF_CONST_SEG, CONSTANT_SEGMENT_NAME, file_name, add); @@ -1844,6 +1872,7 @@ PF_create_default_segs(PARROT_INTERP, ARGIN(STRING *file_name), int add) } + /* =item C @@ -4392,7 +4421,8 @@ PackFile_append(PARROT_INTERP, ARGIN_NULLOK(PackFile * const pf)) if (pf) { if (!interp->code) { STRING * const name = CONST_STRING(interp, "dummy"); - interp->code = PF_create_default_segs(interp, name, 1); + interp->code = Parrot_pf_create_default_segments(interp, + interp->initial_pf, name, 1); PARROT_ASSERT(interp->code); } PackFile_add_segment(interp, &interp->initial_pf->directory, From 8a84768fd234909e0463b58a6a1c145222e9bd49 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 11:42:13 -0500 Subject: [PATCH 07/28] remove all instances of 'interp->code' from compilers/imcc/pbc.c. Replace it with the new accessor functions. Don't look it up in the various static functions, instead pass a reference. In reality, many of these need a reference to PackFile_ConstTable instead of PackFile_ByteCode instead. --- compilers/imcc/pbc.c | 246 ++++++++++++++++++++++++++----------------- 1 file changed, 148 insertions(+), 98 deletions(-) diff --git a/compilers/imcc/pbc.c b/compilers/imcc/pbc.c index 2b206cd3d8..e96381fcf5 100644 --- a/compilers/imcc/pbc.c +++ b/compilers/imcc/pbc.c @@ -52,14 +52,22 @@ TODO memory clean up /* HEADERIZER BEGIN: static */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ -static void add_1_const(PARROT_INTERP, ARGMOD(SymReg *r)) +static void add_1_const(PARROT_INTERP, + ARGMOD(SymReg *r), + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) __attribute__nonnull__(2) - FUNC_MODIFIES(*r); + __attribute__nonnull__(3) + FUNC_MODIFIES(*r) + FUNC_MODIFIES(* bc); PARROT_WARN_UNUSED_RESULT -static int add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf)) - __attribute__nonnull__(1); +static int add_const_num(PARROT_INTERP, + ARGIN_NULLOK(const char *buf), + ARGMOD(PackFile_ByteCode * bc)) + __attribute__nonnull__(1) + __attribute__nonnull__(3) + FUNC_MODIFIES(* bc); PARROT_IGNORABLE_RESULT static int /*@alt void@*/ @@ -72,32 +80,46 @@ add_const_pmc_sub(PARROT_INTERP, FUNC_MODIFIES(*r); PARROT_WARN_UNUSED_RESULT -static int add_const_str(PARROT_INTERP, ARGIN(STRING *s)) +static int add_const_str(PARROT_INTERP, + ARGIN(STRING *s), + ARGIN(PackFile_ByteCode * const bc)) __attribute__nonnull__(1) - __attribute__nonnull__(2); + __attribute__nonnull__(2) + __attribute__nonnull__(3); static int add_const_table_pmc(PARROT_INTERP, ARGIN(PMC *pmc)) __attribute__nonnull__(1) __attribute__nonnull__(2); -static opcode_t build_key(PARROT_INTERP, ARGIN(SymReg *key_reg)) +static opcode_t build_key(PARROT_INTERP, + ARGIN(SymReg *key_reg), + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) - __attribute__nonnull__(2); + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(* bc); -static void constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit)) +static void constant_folding(PARROT_INTERP, + ARGIN(const IMC_Unit *unit), + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) - __attribute__nonnull__(2); + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(* bc); PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static PMC* create_lexinfo(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(PMC *sub_pmc), - int need_lex) + int need_lex, + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) __attribute__nonnull__(2) __attribute__nonnull__(3) - FUNC_MODIFIES(*unit); + __attribute__nonnull__(5) + FUNC_MODIFIES(*unit) + FUNC_MODIFIES(* bc); PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL @@ -142,9 +164,12 @@ static size_t get_code_size(PARROT_INTERP, FUNC_MODIFIES(*src_lines); PARROT_WARN_UNUSED_RESULT -static int get_old_size(PARROT_INTERP, ARGOUT(int *ins_line)) +static int get_old_size(PARROT_INTERP, + ARGIN(PackFile_ByteCode * bc), + ARGOUT(int *ins_line)) __attribute__nonnull__(1) __attribute__nonnull__(2) + __attribute__nonnull__(3) FUNC_MODIFIES(*ins_line); static void imcc_globals_destroy(PARROT_INTERP, @@ -170,9 +195,13 @@ static void make_pmc_const(PARROT_INTERP, ARGMOD(SymReg *r)) PARROT_CANNOT_RETURN_NULL PARROT_MALLOC -static PMC* mk_multi_sig(PARROT_INTERP, ARGIN(const SymReg *r)) +static PMC* mk_multi_sig(PARROT_INTERP, + ARGIN(const SymReg *r), + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) - __attribute__nonnull__(2); + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(* bc); static void store_fixup(PARROT_INTERP, ARGIN(const SymReg *r), @@ -190,35 +219,44 @@ static void store_sub_size(PARROT_INTERP, size_t size, size_t ins_line) static void verify_signature(PARROT_INTERP, ARGIN(const Instruction *ins), - ARGIN(opcode_t *pc)) + ARGIN(opcode_t *pc), + ARGMOD(PackFile_ByteCode * bc)) __attribute__nonnull__(1) __attribute__nonnull__(2) - __attribute__nonnull__(3); + __attribute__nonnull__(3) + __attribute__nonnull__(4) + FUNC_MODIFIES(* bc); #define ASSERT_ARGS_add_1_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(r)) + , PARROT_ASSERT_ARG(r) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_add_const_num __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp)) + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_add_const_pmc_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(r)) #define ASSERT_ARGS_add_const_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s)) + , PARROT_ASSERT_ARG(s) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_add_const_table_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(pmc)) #define ASSERT_ARGS_build_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(key_reg)) + , PARROT_ASSERT_ARG(key_reg) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_constant_folding __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(unit)) + , PARROT_ASSERT_ARG(unit) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_create_lexinfo __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(unit) \ - , PARROT_ASSERT_ARG(sub_pmc)) + , PARROT_ASSERT_ARG(sub_pmc) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_find_global_label __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(name) \ @@ -240,6 +278,7 @@ static void verify_signature(PARROT_INTERP, , PARROT_ASSERT_ARG(src_lines)) #define ASSERT_ARGS_get_old_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(bc) \ , PARROT_ASSERT_ARG(ins_line)) #define ASSERT_ARGS_imcc_globals_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp)) @@ -256,7 +295,8 @@ static void verify_signature(PARROT_INTERP, , PARROT_ASSERT_ARG(r)) #define ASSERT_ARGS_mk_multi_sig __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(r)) + , PARROT_ASSERT_ARG(r) \ + , PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_store_fixup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(r)) @@ -268,7 +308,8 @@ static void verify_signature(PARROT_INTERP, #define ASSERT_ARGS_verify_signature __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(ins) \ - , PARROT_ASSERT_ARG(pc)) + , PARROT_ASSERT_ARG(pc) \ + , PARROT_ASSERT_ARG(bc)) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: static */ @@ -433,7 +474,8 @@ make_new_sub(PARROT_INTERP, ARGIN(IMC_Unit *unit)) /* -=item C +=item C Get the size/line of bytecode in ops to this point. @@ -443,14 +485,14 @@ Get the size/line of bytecode in ops to this point. PARROT_WARN_UNUSED_RESULT static int -get_old_size(PARROT_INTERP, ARGOUT(int *ins_line)) +get_old_size(PARROT_INTERP, ARGIN(PackFile_ByteCode * bc), ARGOUT(int *ins_line)) { ASSERT_ARGS(get_old_size) size_t size = 0; *ins_line = 0; - if (IMCC_INFO(interp)->globals->cs && interp->code->base.data) { + if (IMCC_INFO(interp)->globals->cs && bc->base.data) { const subs_t *s; for (s = IMCC_INFO(interp)->globals->cs->subs; s; s = s->prev) { size += s->size; @@ -615,8 +657,7 @@ void imcc_pbc_add_libdep(PARROT_INTERP, ARGIN(STRING *libname)) { ASSERT_ARGS(imcc_pbc_add_libdep) - - PackFile_ByteCode *bc = interp->code; + PackFile_ByteCode * const bc = Parrot_pf_get_current_code_segment(interp); size_t i; /* bail out early if compiling to text format */ @@ -651,9 +692,9 @@ none exists. static opcode_t bytecode_map_op(PARROT_INTERP, op_info_t *info) { - op_lib_t *lib = info->lib; - op_func_t op_func = OP_INFO_OPFUNC(info); - PackFile_ByteCode *bc = interp->code; + op_lib_t *lib = info->lib; + op_func_t op_func = OP_INFO_OPFUNC(info); + PackFile_ByteCode * const bc = Parrot_pf_get_current_code_segment(interp); PackFile_ByteCode_OpMappingEntry *om; opcode_t i; @@ -805,6 +846,7 @@ fixup_globals(PARROT_INTERP) subs_t *s; int jumppc = 0; op_lib_t *core_ops = PARROT_GET_CORE_OPLIB(interp); + PackFile_ByteCode * const bc = Parrot_pf_get_current_code_segment(interp); for (s = IMCC_INFO(interp)->globals->cs->first; s; s = s->next) { const SymHash * const hsh = &s->fixup; @@ -863,12 +905,13 @@ fixup_globals(PARROT_INTERP) op_info_t *op = &core_ops->op_info_table[PARROT_OP_find_sub_not_null_p_sc]; PARROT_ASSERT(op); - interp->code->base.data[addr] = bytecode_map_op(interp, op); + bc->base.data[addr] = bytecode_map_op(interp, op); if (nam->color < 0) - nam->color = add_const_str(interp, IMCC_string_from_reg(interp, nam)); + nam->color = add_const_str(interp, + IMCC_string_from_reg(interp, nam), bc); - interp->code->base.data[addr+2] = nam->color; + bc->base.data[addr+2] = nam->color; IMCC_debug(interp, DEBUG_PBC_FIXUP, "fixup const PMC" @@ -884,7 +927,7 @@ fixup_globals(PARROT_INTERP) "couldn't find sub 2 '%s'\n", fixup->name); } - interp->code->base.data[addr+fixup->offset] = pmc_const; + bc->base.data[addr+fixup->offset] = pmc_const; IMCC_debug(interp, DEBUG_PBC_FIXUP, "fixup const PMC" " sub '%s' const nr: %d\n", fixup->name, pmc_const); @@ -1006,7 +1049,8 @@ IMCC_string_from__STRINGC(PARROT_INTERP, ARGIN(char *buf)) /* -=item C +=item C Adds a constant string to constant_table. @@ -1016,11 +1060,10 @@ Adds a constant string to constant_table. PARROT_WARN_UNUSED_RESULT static int -add_const_str(PARROT_INTERP, ARGIN(STRING *s)) +add_const_str(PARROT_INTERP, ARGIN(STRING *s), ARGIN(PackFile_ByteCode * const bc)) { ASSERT_ARGS(add_const_str) - - PackFile_ConstTable *ct = interp->code->const_table; + PackFile_ConstTable * const ct = bc->const_table; int i = PackFile_ConstTable_rlookup_str(interp, ct, s); if (i >= 0) @@ -1056,7 +1099,8 @@ add_const_str(PARROT_INTERP, ARGIN(STRING *s)) /* -=item C +=item C Adds a constant num to constant_table. @@ -1066,10 +1110,10 @@ Adds a constant num to constant_table. PARROT_WARN_UNUSED_RESULT static int -add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf)) +add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(add_const_num) - PackFile_ConstTable *ct = interp->code->const_table; + PackFile_ConstTable *ct = bc->const_table; STRING * const s = Parrot_str_new(interp, buf, 0); if (!ct->num.constants) @@ -1088,7 +1132,8 @@ add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf)) /* -=item C +=item C Creates and returns a multi-signature PMC given a SymReg. @@ -1099,7 +1144,7 @@ Creates and returns a multi-signature PMC given a SymReg. PARROT_CANNOT_RETURN_NULL PARROT_MALLOC static PMC* -mk_multi_sig(PARROT_INTERP, ARGIN(const SymReg *r)) +mk_multi_sig(PARROT_INTERP, ARGIN(const SymReg *r), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(mk_multi_sig) PackFile_ConstTable *ct; @@ -1113,7 +1158,7 @@ mk_multi_sig(PARROT_INTERP, ARGIN(const SymReg *r)) return Parrot_pmc_new(interp, enum_class_FixedIntegerArray); multi_sig = Parrot_pmc_new_init_int(interp, enum_class_FixedPMCArray, n); - ct = interp->code->const_table; + ct = bc->const_table; for (i = 0; i < n; ++i) { /* multi[i] can be a Key too - @@ -1150,7 +1195,7 @@ typedef void (*decl_func_t)(Interp *, PMC *, STRING *, INTVAL); /* =item C +int need_lex, PackFile_ByteCode * bc)> Creates and returns a new LexInfo PMC for all lexicals in the given sub in the current compilation unit. @@ -1163,12 +1208,12 @@ PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static PMC* create_lexinfo(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(PMC *sub_pmc), - int need_lex) + int need_lex, ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(create_lexinfo) PMC *lex_info = NULL; SymHash *hsh = &unit->hash; - PackFile_ConstTable *ct = interp->code->const_table; + PackFile_ConstTable *ct = bc->const_table; const INTVAL lex_info_id = Parrot_hll_get_ctx_HLL_type(interp, enum_class_LexInfo); unsigned int i; @@ -1314,8 +1359,8 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) PMC *ns_pmc; PMC *sub_pmc; Parrot_Sub_attributes *sub; - - PackFile_ConstTable * const ct = interp->code->const_table; + PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp); + PackFile_ConstTable * const ct = interp_code->const_table; IMC_Unit * const unit = IMCC_INFO(interp)->globals->cs->subs->unit; @@ -1388,7 +1433,7 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) PObj_get_FLAGS(sub_pmc) |= (r->pcc_sub->pragma & SUB_FLAG_PF_MASK); Sub_comp_get_FLAGS(sub) |= (r->pcc_sub->pragma & SUB_COMP_FLAG_MASK); - r->color = add_const_str(interp, IMCC_string_from_reg(interp, r)); + r->color = add_const_str(interp, IMCC_string_from_reg(interp, r), interp_code); sub->name = ct->str.constants[r->color]; /* If the unit has no subid, set the subid to match the name. */ @@ -1403,7 +1448,7 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) /* create string constant for it. */ unit->subid->color = add_const_str(interp, - IMCC_string_from_reg(interp, unit->subid)); + IMCC_string_from_reg(interp, unit->subid), interp_code); } sub->subid = ct->str.constants[unit->subid->color]; @@ -1436,13 +1481,13 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) sub->n_regs_used[i] = unit->n_regs_used[i]; sub->lex_info = create_lexinfo(interp, unit, sub_pmc, - r->pcc_sub->pragma & P_NEED_LEX); + r->pcc_sub->pragma & P_NEED_LEX, interp_code); sub->outer_sub = find_outer(interp, unit); sub->vtable_index = -1; /* check if it's declared multi */ if (r->pcc_sub->nmulti) - sub->multi_signature = mk_multi_sig(interp, r); + sub->multi_signature = mk_multi_sig(interp, r, interp_code); else sub->multi_signature = NULL; @@ -1507,7 +1552,7 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) for (i = 0; i < n; i++) { int unused = add_const_str(interp, - VTABLE_get_string_keyed_int(interp, strings, i)); + VTABLE_get_string_keyed_int(interp, strings, i), interp_code); } } @@ -1535,10 +1580,10 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) if (r->pcc_sub->pragma & P_MAIN && !IMCC_INFO(interp)->seen_main) { IMCC_INFO(interp)->seen_main = 1; - interp->code->main_sub = k; + interp_code->main_sub = k; } - else if (interp->code->main_sub < 0) { - interp->code->main_sub = k; + else if (interp_code->main_sub < 0) { + interp_code->main_sub = k; } return k; @@ -1548,7 +1593,8 @@ add_const_pmc_sub(PARROT_INTERP, ARGMOD(SymReg *r), size_t offs, size_t end) /* -=item C +=item C Builds a Key PMC from the given SymReg. @@ -1561,11 +1607,11 @@ the key, which gets cached in the globals.keys. */ static opcode_t -build_key(PARROT_INTERP, ARGIN(SymReg *key_reg)) +build_key(PARROT_INTERP, ARGIN(SymReg *key_reg), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(build_key) - PackFile_ConstTable *ct = interp->code->const_table; + PackFile_ConstTable *ct = bc->const_table; SymReg *reg = key_reg->set == 'K' ? key_reg->nextkey : key_reg; PMC *head = NULL; PMC *tail = NULL; @@ -1856,7 +1902,8 @@ make_pmc_const(PARROT_INTERP, ARGMOD(SymReg *r)) /* -=item C +=item C Adds a constant SymReg to the constant table, depending on its type. @@ -1865,7 +1912,7 @@ Adds a constant SymReg to the constant table, depending on its type. */ static void -add_1_const(PARROT_INTERP, ARGMOD(SymReg *r)) +add_1_const(PARROT_INTERP, ARGMOD(SymReg *r), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(add_1_const) if (r->color >= 0) @@ -1881,10 +1928,10 @@ add_1_const(PARROT_INTERP, ARGMOD(SymReg *r)) case 'S': if (r->type & VT_CONSTP) r = r->reg; - r->color = add_const_str(interp, IMCC_string_from_reg(interp, r)); + r->color = add_const_str(interp, IMCC_string_from_reg(interp, r), bc); break; case 'N': - r->color = add_const_num(interp, r->name); + r->color = add_const_num(interp, r->name, bc); break; case 'K': { @@ -1892,8 +1939,8 @@ add_1_const(PARROT_INTERP, ARGMOD(SymReg *r)) for (r = r->nextkey; r; r = r->nextkey) if (r->type & (VTCONST|VT_CONSTP)) - add_1_const(interp, r); - build_key(interp, key); + add_1_const(interp, r, bc); + build_key(interp, key, bc); } break; case 'P': @@ -1913,7 +1960,8 @@ add_1_const(PARROT_INTERP, ARGMOD(SymReg *r)) /* -=item C +=item C Stores a constant's idx for later reuse. @@ -1922,7 +1970,7 @@ Stores a constant's idx for later reuse. */ static void -constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit)) +constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(constant_folding) const SymHash *hsh = &IMCC_INFO(interp)->ghash; @@ -1935,7 +1983,7 @@ constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit)) /* normally constants are in ghash ... */ for (r = hsh->data[i]; r; r = r->next) { if (r->type & (VTCONST|VT_CONSTP)) - add_1_const(interp, r); + add_1_const(interp, r, bc); if (r->usage & U_LEXICAL) { SymReg *n = r->reg; @@ -1943,7 +1991,7 @@ constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit)) /* r->reg is a chain of names for the same lex sym */ while (n) { /* lex_name */ - add_1_const(interp, n); + add_1_const(interp, n, bc); n = n->reg; } } @@ -1959,13 +2007,13 @@ constant_folding(PARROT_INTERP, ARGIN(const IMC_Unit *unit)) /* normally constants are in ghash ... */ for (r = hsh->data[i]; r; r = r->next) { if (r->type & VTCONST) - add_1_const(interp, r); + add_1_const(interp, r, bc); } } /* and finally, there may be an outer Sub */ if (unit->outer) - add_1_const(interp, unit->outer); + add_1_const(interp, unit->outer, bc); } @@ -2054,7 +2102,7 @@ e_pbc_end_sub(PARROT_INTERP, SHIM(void *param), ARGIN(IMC_Unit *unit)) /* =item C +opcode_t *pc, PackFile_ByteCode * bc)> Checks if any get_ argument contains constants and fills in type bits for argument types and constants, if missing. @@ -2064,11 +2112,12 @@ argument types and constants, if missing. */ static void -verify_signature(PARROT_INTERP, ARGIN(const Instruction *ins), ARGIN(opcode_t *pc)) +verify_signature(PARROT_INTERP, ARGIN(const Instruction *ins), + ARGIN(opcode_t *pc), ARGMOD(PackFile_ByteCode * bc)) { ASSERT_ARGS(verify_signature) PMC *changed_sig = NULL; - PMC * const sig_arr = interp->code->const_table->pmc.constants[pc[-1]]; + PMC * const sig_arr = bc->const_table->pmc.constants[pc[-1]]; op_lib_t *core_ops = PARROT_GET_CORE_OPLIB(interp); int needed = 0; int no_consts = (ins->op == &core_ops->op_info_table[PARROT_OP_get_results_pc] @@ -2150,11 +2199,12 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), int ok = 0; int i; op_lib_t *core_ops = PARROT_GET_CORE_OPLIB(interp); + PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp); /* first instruction, do initialisation ... */ if (ins == unit->instructions) { size_t ins_size, seg_size; - const size_t old_size = get_old_size(interp, + const size_t old_size = get_old_size(interp, interp_code, &IMCC_INFO(interp)->ins_line); const size_t code_size = get_code_size(interp, unit, &ins_size); const size_t bytes = (old_size + code_size) * sizeof (opcode_t); @@ -2162,25 +2212,25 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), IMCC_debug(interp, DEBUG_PBC, "code_size(ops) %d old_size %d\n", code_size, old_size); - constant_folding(interp, unit); + constant_folding(interp, unit, interp_code); store_sub_size(interp, code_size, ins_size); /* allocate code */ - interp->code->base.data = (opcode_t *) - mem_sys_realloc(interp->code->base.data, bytes); + interp_code->base.data = (opcode_t *) + mem_sys_realloc(interp_code->base.data, bytes); /* reallocating this removes its mmaped-ness; needs encapsulation */ - interp->code->base.pf->is_mmap_ped = 0; + interp_code->base.pf->is_mmap_ped = 0; - interp->code->base.size = old_size + code_size; + interp_code->base.size = old_size + code_size; - IMCC_INFO(interp)->pc = (opcode_t *)interp->code->base.data + old_size; + IMCC_INFO(interp)->pc = (opcode_t *)interp_code->base.data + old_size; IMCC_INFO(interp)->npc = 0; /* FIXME length and multiple subs */ seg_size = (size_t)IMCC_INFO(interp)->ins_line + ins_size + 1; IMCC_INFO(interp)->debug_seg = - Parrot_new_debug_seg(interp, interp->code, seg_size); + Parrot_new_debug_seg(interp, interp_code, seg_size); Parrot_debug_add_mapping(interp, IMCC_INFO(interp)->debug_seg, old_size, unit->file); @@ -2213,20 +2263,20 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), int annotation_type; /* Add annotations seg if we're missing one. */ - if (!interp->code->annotations) { + if (!interp_code->annotations) { /* Create segment. "_ANN" is added to the name */ - STRING *name = Parrot_sprintf_c(interp, "%Ss_ANN", interp->code->base.name); - int add = interp->code->base.dir ? 1 : 0; - PackFile_Directory * const dir = add ? interp->code->base.dir : + STRING *name = Parrot_sprintf_c(interp, "%Ss_ANN", interp_code->base.name); + int add = interp_code->base.dir ? 1 : 0; + PackFile_Directory * const dir = add ? interp_code->base.dir : &interp->initial_pf->directory; - interp->code->annotations = (PackFile_Annotations *) + interp_code->annotations = (PackFile_Annotations *) PackFile_Segment_new_seg(interp, dir, PF_ANNOTATIONS_SEG, name, 1); - interp->code->annotations->code = interp->code; + interp_code->annotations->code = interp_code; /* Create initial group. */ - PackFile_Annotations_add_group(interp, interp->code->annotations, - IMCC_INFO(interp)->pc - interp->code->base.data); + PackFile_Annotations_add_group(interp, interp_code->annotations, + IMCC_INFO(interp)->pc - interp_code->base.data); } /* Add annotation. */ @@ -2244,8 +2294,8 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), IMCC_fatal(interp, 1, "e_pbc_emit:" "invalid type for annotation value\n"); } - PackFile_Annotations_add_entry(interp, interp->code->annotations, - IMCC_INFO(interp)->pc - interp->code->base.data, + PackFile_Annotations_add_entry(interp, interp_code->annotations, + IMCC_INFO(interp)->pc - interp_code->base.data, ins->symregs[0]->color, annotation_type, ins->symregs[1]->color); } else if (ins->opname && *ins->opname) { @@ -2321,7 +2371,7 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), *(IMCC_INFO(interp)->pc)++ = r->color; } else { - *(IMCC_INFO(interp)->pc)++ = build_key(interp, r); + *(IMCC_INFO(interp)->pc)++ = build_key(interp, r, interp_code); } IMCC_debug(interp, DEBUG_PBC, " %d", IMCC_INFO(interp)->pc[-1]); @@ -2339,7 +2389,7 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), /* TODO get rid of verify_signature - PIR call sigs are already * fixed, but PASM still needs it */ - verify_signature(interp, ins, IMCC_INFO(interp)->pc); + verify_signature(interp, ins, IMCC_INFO(interp)->pc, interp_code); /* emit var_args part */ for (; i < ins->opsize - 1; ++i) { From c8464139ba1843468b5def30e04c966e652892aa Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 11:50:41 -0500 Subject: [PATCH 08/28] remove all instances of interp->code from compilers/imcc/parser_util.c. Replace with accessor functions --- compilers/imcc/parser_util.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 090fbb5db7..5a7376c819 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -813,13 +813,13 @@ imcc_compile_file(PARROT_INTERP, ARGIN(const char *fullname), ARGOUT(STRING **error_message)) { ASSERT_ARGS(imcc_compile_file) - PackFile_ByteCode * const cs_save = interp->code; - PackFile_ByteCode *cs = NULL; - struct _imc_info_t *imc_info = NULL; - const char *ext; - FILE *fp; - STRING *fs; - PMC *newcontext; + PackFile_ByteCode * const cs_save = Parrot_pf_get_current_code_segment(interp); + PackFile_ByteCode *cs = NULL; + struct _imc_info_t *imc_info = NULL; + const char *ext; + FILE *fp; + STRING *fs; + PMC *newcontext; /* need at least 3 regs for compilation of constant math e.g. * add_i_ic_ic - see also IMCC_subst_constants() */ @@ -896,7 +896,7 @@ imcc_compile_file(PARROT_INTERP, ARGIN(const char *fullname), fclose(fp); if (!IMCC_INFO(interp)->error_code) - cs = interp->code; + cs = Parrot_pf_get_current_code_segment(interp); else *error_message = IMCC_INFO(interp)->error_message; From c8856ceacbcde897b28bdf348fac96b132123215 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 12:50:29 -0500 Subject: [PATCH 09/28] remove instance of interp->initial_pf from compilers/imcc/pbc.c --- compilers/imcc/pbc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compilers/imcc/pbc.c b/compilers/imcc/pbc.c index e96381fcf5..f94359d9ec 100644 --- a/compilers/imcc/pbc.c +++ b/compilers/imcc/pbc.c @@ -2199,6 +2199,7 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), int ok = 0; int i; op_lib_t *core_ops = PARROT_GET_CORE_OPLIB(interp); + PackFile * const interp_pf = Parrot_pf_get_current_packfile(interp); PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp); /* first instruction, do initialisation ... */ @@ -2268,7 +2269,7 @@ e_pbc_emit(PARROT_INTERP, SHIM(void *param), ARGIN(const IMC_Unit *unit), STRING *name = Parrot_sprintf_c(interp, "%Ss_ANN", interp_code->base.name); int add = interp_code->base.dir ? 1 : 0; PackFile_Directory * const dir = add ? interp_code->base.dir : - &interp->initial_pf->directory; + &interp_pf->directory; interp_code->annotations = (PackFile_Annotations *) PackFile_Segment_new_seg(interp, dir, PF_ANNOTATIONS_SEG, name, 1); From ff5035fb9108c813e341f1007c179f90c6d071a0 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Thu, 13 Jan 2011 19:47:11 -0500 Subject: [PATCH 10/28] rename a variable to be less confusing --- compilers/imcc/parser_util.c | 10 +++++----- src/packfile/api.c | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 5a7376c819..1b5015b62c 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -533,7 +533,7 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, */ STRING *name; PackFile_ByteCode *old_cs, *new_cs; - PMC *sub = NULL; + PMC *eval_pmc = NULL; struct _imc_info_t *imc_info = NULL; struct parser_state_t *next; void *yyscanner; @@ -613,8 +613,8 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, * * TODO if a sub was denoted :main return that instead */ - sub = Parrot_pmc_new(interp, enum_class_Eval); - PMC_get_sub(interp, sub, sub_data); + eval_pmc = Parrot_pmc_new(interp, enum_class_Eval); + PMC_get_sub(interp, eval_pmc, sub_data); sub_data->seg = new_cs; sub_data->start_offs = 0; sub_data->end_offs = new_cs->base.size; @@ -648,13 +648,13 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, /* Now run any :load/:init subs. */ if (!*error_message) - PackFile_fixup_subs(interp, PBC_MAIN, sub); + PackFile_fixup_subs(interp, PBC_MAIN, eval_pmc); /* restore old byte_code, */ if (old_cs) (void)Parrot_switch_to_cs(interp, old_cs, 0); - return sub; + return eval_pmc; } /* diff --git a/src/packfile/api.c b/src/packfile/api.c index 6929273e5e..6a5c33d993 100644 --- a/src/packfile/api.c +++ b/src/packfile/api.c @@ -943,13 +943,11 @@ do_sub_pragmas(PARROT_INTERP, ARGIN(PackFile_ByteCode *self), if (((PObj_get_FLAGS(sub_pmc) & SUB_FLAG_PF_MASK) || (Sub_comp_get_FLAGS(sub) & SUB_COMP_FLAG_MASK)) && sub_pragma(interp, action, sub_pmc)) { - PMC * const result = do_1_sub_pragma(interp, sub_pmc, - action); + PMC * const result = do_1_sub_pragma(interp, sub_pmc, action); /* replace Sub PMC with computation results */ - if (action == PBC_IMMEDIATE && !PMC_IS_NULL(result)) { + if (action == PBC_IMMEDIATE && !PMC_IS_NULL(result)) ct->pmc.constants[i] = result; - } } } } From 50acdfb4de33760e893e5387f9610d5cceb82f40 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 07:52:27 -0500 Subject: [PATCH 11/28] remove unused function imcc_run_pbc --- compilers/imcc/main.c | 25 ------------------------- include/parrot/imcc.h | 1 - 2 files changed, 26 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index b817904d27..cd7ffdb3ee 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -451,31 +451,6 @@ imcc_get_optimization_description(const PARROT_INTERP, int opt_level, ARGMOD(cha /* -=item C - -Write out or run Parrot bytecode. - -=cut - -*/ - -void -imcc_run_pbc(PARROT_INTERP, ARGIN_NULLOK(const char *output_file), - int argc, ARGIN(const char **argv)) -{ - /* ASSERT_ARGS(imcc_run_pbc) */ - - IMCC_info(interp, 1, "Running...\n"); - - /* runs :init functions */ - PackFile_fixup_subs(interp, PBC_MAIN, NULL); - - Parrot_runcode(interp, argc, argv); -} - -/* - =item C Output packed bytecode file. diff --git a/include/parrot/imcc.h b/include/parrot/imcc.h index 44dcafa2b9..68282bc6ae 100644 --- a/include/parrot/imcc.h +++ b/include/parrot/imcc.h @@ -6,7 +6,6 @@ #define PARROT_IMCC_H_GUARD PARROT_EXPORT int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv, ARGOUT(PMC **pbcpmc)); -PARROT_EXPORT void imcc_run_pbc(PARROT_INTERP, const char *outputfile, int argc, const char **argv); #endif /* PARROT_IMCC_H_GUARD */ From 4357d749cfaddee006260b9d5d3177e11adb7992 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 09:05:15 -0500 Subject: [PATCH 12/28] remove unused function imcc_run_pbc --- compilers/imcc/main.c | 25 ------------------------- include/parrot/imcc.h | 1 - 2 files changed, 26 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index b817904d27..cd7ffdb3ee 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -451,31 +451,6 @@ imcc_get_optimization_description(const PARROT_INTERP, int opt_level, ARGMOD(cha /* -=item C - -Write out or run Parrot bytecode. - -=cut - -*/ - -void -imcc_run_pbc(PARROT_INTERP, ARGIN_NULLOK(const char *output_file), - int argc, ARGIN(const char **argv)) -{ - /* ASSERT_ARGS(imcc_run_pbc) */ - - IMCC_info(interp, 1, "Running...\n"); - - /* runs :init functions */ - PackFile_fixup_subs(interp, PBC_MAIN, NULL); - - Parrot_runcode(interp, argc, argv); -} - -/* - =item C Output packed bytecode file. diff --git a/include/parrot/imcc.h b/include/parrot/imcc.h index 44dcafa2b9..68282bc6ae 100644 --- a/include/parrot/imcc.h +++ b/include/parrot/imcc.h @@ -6,7 +6,6 @@ #define PARROT_IMCC_H_GUARD PARROT_EXPORT int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv, ARGOUT(PMC **pbcpmc)); -PARROT_EXPORT void imcc_run_pbc(PARROT_INTERP, const char *outputfile, int argc, const char **argv); #endif /* PARROT_IMCC_H_GUARD */ From c68e224154e0f468d74ea2ed8c697096393352c3 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 09:24:33 -0500 Subject: [PATCH 13/28] imcc_run is now static because it's only used in compilers/imcc/main.c. With that, we can get rid of include/parrot/imcc.h entirely. Good riddance. --- MANIFEST | 1 - compilers/imcc/Rules.in | 1 - compilers/imcc/main.c | 23 +++++++++++++++++++---- include/parrot/api.h | 3 +-- include/parrot/imcc.h | 17 ----------------- 5 files changed, 20 insertions(+), 25 deletions(-) delete mode 100644 include/parrot/imcc.h diff --git a/MANIFEST b/MANIFEST index 9f32b791e9..a44fd026f1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -949,7 +949,6 @@ include/parrot/global_setup.h [main]include include/parrot/hash.h [main]include include/parrot/hll.h [main]include include/parrot/imageio.h [main]include -include/parrot/imcc.h [main]include include/parrot/interpreter.h [main]include include/parrot/io.h [main]include include/parrot/io_portable.h [main]include diff --git a/compilers/imcc/Rules.in b/compilers/imcc/Rules.in index 0171073922..cd3507cfc3 100644 --- a/compilers/imcc/Rules.in +++ b/compilers/imcc/Rules.in @@ -154,7 +154,6 @@ compilers/imcc/main$(O) : \ compilers/imcc/symreg.h \ compilers/imcc/unit.h \ $(INC_DIR)/embed.h \ - $(INC_DIR)/imcc.h \ $(INC_DIR)/oplib/ops.h \ $(INC_DIR)/runcore_api.h \ $(INC_DIR)/api.h \ diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index cd7ffdb3ee..5de3898a3e 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -31,7 +31,6 @@ IMCC helpers. #include "imc.h" #include "parrot/embed.h" #include "parrot/longopt.h" -#include "parrot/imcc.h" #include "parrot/runcore_api.h" #include "pmc/pmc_callcontext.h" #include "pbc.h" @@ -82,6 +81,17 @@ static void imcc_parseflags(PARROT_INTERP, __attribute__nonnull__(1) __attribute__nonnull__(3); +static int imcc_run(PARROT_INTERP, + ARGIN(const char *sourcefile), + int argc, + ARGIN(const char **argv), + ARGOUT(PMC **pbcpmc)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(4) + __attribute__nonnull__(5) + FUNC_MODIFIES(*pbcpmc); + static void imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file)) __attribute__nonnull__(1) __attribute__nonnull__(2); @@ -114,6 +124,11 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void); #define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(argv)) +#define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(sourcefile) \ + , PARROT_ASSERT_ARG(argv) \ + , PARROT_ASSERT_ARG(pbcpmc)) #define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(output_file)) @@ -651,8 +666,8 @@ imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(const char *sourcefile), int argc, /* -=item C +=item C Entry point of IMCC, as invoked by Parrot's main function. Compile source code (if required), write bytecode file (if required) @@ -662,7 +677,7 @@ and run. This function always returns 0. */ -int +static int imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, ARGIN(const char **argv), ARGOUT(PMC **pbcpmc)) { diff --git a/include/parrot/api.h b/include/parrot/api.h index 28908d03b4..0caaa1043f 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -726,8 +726,7 @@ Parrot_Int Parrot_api_pmc_wrap_string_array( /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: src/embed/pmc.c */ -/* Forward declaration because IMCC is still part of libparrot, but we don't - want to include parrot/imcc.h */ +/* Forward declaration because IMCC is still part of libparrot */ PARROT_API int diff --git a/include/parrot/imcc.h b/include/parrot/imcc.h deleted file mode 100644 index 68282bc6ae..0000000000 --- a/include/parrot/imcc.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2007-2010, Parrot Foundation. - */ - -#ifndef PARROT_IMCC_H_GUARD -#define PARROT_IMCC_H_GUARD - -PARROT_EXPORT int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv, ARGOUT(PMC **pbcpmc)); - -#endif /* PARROT_IMCC_H_GUARD */ - -/* - * Local variables: - * c-file-style: "parrot" - * End: - * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : - */ From 2471580b7316eb4289d0012a8aa927077d65aecd Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 10:50:20 -0500 Subject: [PATCH 14/28] remove the field interp->output_file. Instead, we let IMCC parse that option internally for now and not burden the interp with that information --- compilers/imcc/main.c | 21 +++++++++++---------- frontend/parrot/main.c | 10 ++-------- include/parrot/api.h | 6 ------ include/parrot/interpreter.h | 2 -- src/embed/api.c | 26 -------------------------- 5 files changed, 13 insertions(+), 52 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 5de3898a3e..fdd5f59eb4 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -75,7 +75,7 @@ static void imcc_get_optimization_description( __attribute__nonnull__(3) FUNC_MODIFIES(*opt_desc); -static void imcc_parseflags(PARROT_INTERP, +static char * imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) __attribute__nonnull__(1) @@ -226,7 +226,8 @@ Parrot_cmd_options(void) /* -=item C +=item C Parse flags ans set approptiate state(s) @@ -234,11 +235,12 @@ Parse flags ans set approptiate state(s) */ -static void +static char * imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) { ASSERT_ARGS(imcc_parseflags) struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; + char * output_file = NULL; /* default state: run pbc */ SET_STATE_RUN_PBC(interp); @@ -283,14 +285,14 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) break; case 'o': UNSET_STATE_RUN_PBC(interp); - interp->output_file = opt.opt_arg; + output_file = opt.opt_arg; break; case OPT_PBC_OUTPUT: UNSET_STATE_RUN_PBC(interp); SET_STATE_WRITE_PBC(interp); - if (!interp->output_file) - interp->output_file = "-"; + if (!output_file) + output_file = "-"; break; case 'O': @@ -317,6 +319,7 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) break; } } + return output_file; } /* @@ -481,7 +484,7 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file)) size_t size; opcode_t *packed; FILE *fp; - PackFile_ByteCode * interp_code = Parrot_pf_get_current_code_segment(interp); + PackFile_ByteCode * const interp_code = Parrot_pf_get_current_code_segment(interp); IMCC_info(interp, 1, "Writing %s\n", output_file); @@ -682,11 +685,9 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, ARGIN(const char **argv), ARGOUT(PMC **pbcpmc)) { yyscan_t yyscanner; - const char * const output_file = interp->output_file; PackFile * pf_raw = NULL; *pbcpmc = PMCNULL; - - imcc_parseflags(interp, argc, argv); + const char * output_file = imcc_parseflags(interp, argc, argv); /* PMCs in IMCC_INFO won't get marked */ Parrot_block_GC_mark(interp); diff --git a/frontend/parrot/main.c b/frontend/parrot/main.c index 588c07b2a9..3bf4b8c949 100644 --- a/frontend/parrot/main.c +++ b/frontend/parrot/main.c @@ -460,14 +460,14 @@ Parrot_cmd_options(void) { 'X', 'X', OPTION_required_FLAG, { "--dynext" } }, { '\0', OPT_DESTROY_FLAG, (OPTION_flags)0, { "--leak-test", "--destroy-at-end" } }, + { 'o', 'o', OPTION_required_FLAG, { "--output" } }, + { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } }, { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } }, { 'a', 'a', (OPTION_flags)0, { "--pasm" } }, { 'c', 'c', (OPTION_flags)0, { "--pbc" } }, { 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } }, { '\0', OPT_HELP_DEBUG, (OPTION_flags)0, { "--help-debug" } }, { 'h', 'h', (OPTION_flags)0, { "--help" } }, - { 'o', 'o', OPTION_required_FLAG, { "--output" } }, - { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } }, { 'r', 'r', (OPTION_flags)0, { "--run-pbc" } }, { '\0', OPT_RUNTIME_PREFIX, (OPTION_flags)0, { "--runtime-prefix" } }, { 't', 't', OPTION_optional_FLAG, { "--trace" } }, @@ -716,12 +716,6 @@ parseflags(Parrot_PMC interp, /* result = Parrot_api_set_warnings(interp, PARROT_WARNINGS_ALL_FLAG); */ result = Parrot_api_set_warnings(interp, 0xFFFF); break; - case 'o': - result = Parrot_api_set_output_file(interp, opt.opt_arg); - break; - case OPT_PBC_OUTPUT: - result = Parrot_api_set_output_file(interp, NULL); - break; default: /* languages handle their arguments later (after being initialized) */ break; diff --git a/include/parrot/api.h b/include/parrot/api.h index 0caaa1043f..56ce076663 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -206,11 +206,6 @@ Parrot_Int Parrot_api_set_executable_name( ARGIN(const char * name)) __attribute__nonnull__(2); -PARROT_API -Parrot_Int Parrot_api_set_output_file( - Parrot_PMC interp_pmc, - ARGIN_NULLOK(const char * filename)); - PARROT_API Parrot_Int Parrot_api_set_runcore( Parrot_PMC interp_pmc, @@ -283,7 +278,6 @@ Parrot_Int Parrot_api_wrap_imcc_hack( #define ASSERT_ARGS_Parrot_api_set_executable_name \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(name)) -#define ASSERT_ARGS_Parrot_api_set_output_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_set_runcore __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(corename)) #define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) diff --git a/include/parrot/interpreter.h b/include/parrot/interpreter.h index 9cd324e303..903409edaf 100644 --- a/include/parrot/interpreter.h +++ b/include/parrot/interpreter.h @@ -207,8 +207,6 @@ struct parrot_interp_t { struct _imc_info_t *imc_info; /* imcc data */ Hash *op_hash; /* mapping from op names to op_info_t */ - const char *output_file; /* where to write output */ - PDB_t *pdb; /* debug /trace system */ PMC *dynamic_env; /* Dynamic environment stack */ diff --git a/src/embed/api.c b/src/embed/api.c index 98e9014e22..76796043ac 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -519,32 +519,6 @@ Parrot_api_set_warnings(Parrot_PMC interp_pmc, Parrot_Int flags) /* -=item C - -Sets the C's output file name specified by C. This function -returns a true value if this call is successful and false value otherwise. - -=cut - -*/ - -PARROT_API -Parrot_Int -Parrot_api_set_output_file(Parrot_PMC interp_pmc, - ARGIN_NULLOK(const char * filename)) -{ - ASSERT_ARGS(Parrot_api_set_output_file) - EMBED_API_CALLIN(interp_pmc, interp) - if (!filename && !interp->output_file) - interp->output_file = "-"; - else - interp->output_file = filename; - EMBED_API_CALLOUT(interp_pmc, interp) -} - -/* - =item C From d4cdba7072576fb0090c6803b45dc9d9a31cfce1 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 14:12:21 -0500 Subject: [PATCH 15/28] remove .pbc loading logic from imcc_run, and move it into the parrot.exe frontend. While I'm there, change argument parsing so we put parsed flag values into a struct, and make a few other cleanups and changes --- compilers/imcc/main.c | 89 ++++++++++++++------------------------- frontend/parrot/main.c | 94 ++++++++++++++++++++++++++++-------------- src/embed/api.c | 2 +- 3 files changed, 97 insertions(+), 88 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index fdd5f59eb4..7cf8b9f445 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -53,12 +53,10 @@ static PackFile * compile_to_bytecode(PARROT_INTERP, __attribute__nonnull__(2) __attribute__nonnull__(4); -static void determine_input_file_type(PARROT_INTERP, - ARGIN(const char * const sourcefile), - ARGIN(yyscan_t yyscanner)) +static FILE* determine_input_file_type(PARROT_INTERP, + ARGIN(const char * const sourcefile)) __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3); + __attribute__nonnull__(2); static void determine_output_file_type(PARROT_INTERP, ARGIN(const char *output_file)) @@ -83,13 +81,12 @@ static char * imcc_parseflags(PARROT_INTERP, static int imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), - int argc, - ARGIN(const char **argv), + ARGIN(const char *output_file), ARGOUT(PMC **pbcpmc)) __attribute__nonnull__(1) __attribute__nonnull__(2) + __attribute__nonnull__(3) __attribute__nonnull__(4) - __attribute__nonnull__(5) FUNC_MODIFIES(*pbcpmc); static void imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file)) @@ -111,8 +108,7 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void); , PARROT_ASSERT_ARG(yyscanner)) #define ASSERT_ARGS_determine_input_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(sourcefile) \ - , PARROT_ASSERT_ARG(yyscanner)) + , PARROT_ASSERT_ARG(sourcefile)) #define ASSERT_ARGS_determine_output_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(output_file)) @@ -127,7 +123,7 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void); #define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(sourcefile) \ - , PARROT_ASSERT_ARG(argv) \ + , PARROT_ASSERT_ARG(output_file) \ , PARROT_ASSERT_ARG(pbcpmc)) #define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ @@ -266,14 +262,6 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) case 'a': SET_STATE_PASM_FILE(interp); break; - case 'r': - if (STATE_RUN_PBC(interp)) - SET_STATE_RUN_FROM_FILE(interp); - SET_STATE_RUN_PBC(interp); - break; - case 'c': - SET_STATE_LOAD_PBC(interp); - break; case 'v': IMCC_INFO(interp)->verbose++; break; @@ -509,46 +497,28 @@ imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file)) /* -=item C +=item C -Read in the source and determine whether it's Parrot bytecode or PASM +Determine whether the sourcefile is a .pir or .pasm file. Sets the appropriate +flags and returns a C to the opened file. =cut */ -static void -determine_input_file_type(PARROT_INTERP, ARGIN(const char * const sourcefile), - ARGIN(yyscan_t yyscanner)) +static FILE* +determine_input_file_type(PARROT_INTERP, ARGIN(const char * const sourcefile)) { ASSERT_ARGS(determine_input_file_type) - /* Read in the source and check the file extension for the input type; - a file extension .pbc means it's parrot bytecode; - a file extension .pasm means it's parrot assembly (PASM); - otherwise, it's assumed to be PIR. - */ - if (STREQ(sourcefile, "-")) { - imc_yyin_set(stdin, yyscanner); - } + if (STREQ(sourcefile, "-")) + return stdin; else { - const char * const ext = strrchr(sourcefile, '.'); - - if (ext && (STREQ(ext, ".pbc"))) { /* a PBC file */ - SET_STATE_LOAD_PBC(interp); - UNSET_STATE_WRITE_PBC(interp); - } - else if (!STATE_LOAD_PBC(interp)) { - if (!(imc_yyin_set(fopen(sourcefile, "r"), yyscanner))) { - IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR, - "Error reading source file %s.\n", - sourcefile); - } - - if (ext && STREQ(ext, ".pasm")) - SET_STATE_PASM_FILE(interp); - } + const char * ext = strrchr(sourcefile, '.'); + if (ext && STREQ(ext, ".pasm")) + SET_STATE_PASM_FILE(interp); + return fopen(sourcefile, "r"); } } @@ -664,13 +634,14 @@ imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(const char *sourcefile), int argc, ARGIN(const char **argv), ARGOUT(PMC **pbcpmc)) { Interp * interp = (Interp *)VTABLE_get_pointer(NULL, interp_pmc); - return imcc_run(interp, sourcefile, argc, argv, pbcpmc); + const char * output_file = imcc_parseflags(interp, argc, argv); + return imcc_run(interp, sourcefile, output_file, pbcpmc); } /* -=item C +=item C Entry point of IMCC, as invoked by Parrot's main function. Compile source code (if required), write bytecode file (if required) @@ -681,13 +652,12 @@ and run. This function always returns 0. */ static int -imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, - ARGIN(const char **argv), ARGOUT(PMC **pbcpmc)) +imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), + ARGIN(const char *output_file), ARGOUT(PMC **pbcpmc)) { yyscan_t yyscanner; PackFile * pf_raw = NULL; *pbcpmc = PMCNULL; - const char * output_file = imcc_parseflags(interp, argc, argv); /* PMCs in IMCC_INFO won't get marked */ Parrot_block_GC_mark(interp); @@ -698,8 +668,13 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc, /* Figure out what kind of source file we have -- if we have one */ if (!sourcefile || !*sourcefile) IMCC_fatal_standalone(interp, 1, "main: No source file specified.\n"); - else - determine_input_file_type(interp, sourcefile, yyscanner); + else { + FILE * const in_file = determine_input_file_type(interp, sourcefile); + if (!imc_yyin_set(in_file, yyscanner)) + IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR, + "Error reading source file %s.\n", + sourcefile); + } if (STATE_PRE_PROCESS(interp)) { do_pre_process(interp, yyscanner); diff --git a/frontend/parrot/main.c b/frontend/parrot/main.c index 3bf4b8c949..b30e7b0744 100644 --- a/frontend/parrot/main.c +++ b/frontend/parrot/main.c @@ -24,6 +24,14 @@ Start Parrot #include "parrot/longopt.h" #include "parrot/api.h" +struct init_args_t { + const char *run_core_name; + const char *sourcefile; + Parrot_Int trace; + Parrot_Int execute_packfile; + Parrot_Int have_pbc_file; +}; + extern int Parrot_set_config_hash(Parrot_PMC interp_pmc); /* HEADERIZER HFILE: none */ @@ -62,17 +70,14 @@ static const char * parseflags( ARGIN(const char *argv[]), ARGOUT(int *pgm_argc), ARGOUT(const char ***pgm_argv), - ARGMOD(const char **core), - ARGMOD(Parrot_Int *trace)) + ARGMOD(struct init_args_t * args)) __attribute__nonnull__(3) __attribute__nonnull__(4) __attribute__nonnull__(5) __attribute__nonnull__(6) - __attribute__nonnull__(7) FUNC_MODIFIES(*pgm_argc) FUNC_MODIFIES(*pgm_argv) - FUNC_MODIFIES(*core) - FUNC_MODIFIES(*trace); + FUNC_MODIFIES(* args); static void parseflags_minimal( ARGMOD(Parrot_Init_Args * initargs), @@ -110,8 +115,7 @@ static void usage(ARGMOD(FILE *fp)) PARROT_ASSERT_ARG(argv) \ , PARROT_ASSERT_ARG(pgm_argc) \ , PARROT_ASSERT_ARG(pgm_argv) \ - , PARROT_ASSERT_ARG(core) \ - , PARROT_ASSERT_ARG(trace)) + , PARROT_ASSERT_ARG(args)) #define ASSERT_ARGS_parseflags_minimal __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(initargs) \ , PARROT_ASSERT_ARG(argv)) @@ -123,6 +127,8 @@ static void usage(ARGMOD(FILE *fp)) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: static */ + + /* =item C @@ -137,17 +143,14 @@ int main(int argc, const char *argv[]) { int stacktop; - const char *sourcefile; Parrot_PMC interp; Parrot_PMC bytecodepmc; Parrot_PMC argsarray; int status; int pir_argc; const char **pir_argv; - const char *core = "slow"; - int run_pbc = 0; Parrot_Init_Args *initargs; - Parrot_Int trace = 0; + struct init_args_t parsed_flags; GET_INIT_STRUCT(initargs); /* internationalization setup */ @@ -166,15 +169,23 @@ main(int argc, const char *argv[]) } /* Parse flags */ - sourcefile = parseflags(interp, argc, argv, &pir_argc, &pir_argv, &core, &trace); - if (!Parrot_api_set_runcore(interp, core, trace)) + parseflags(interp, argc, argv, &pir_argc, &pir_argv, &parsed_flags); + if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace)) show_last_error_and_exit(interp); - if (!Parrot_api_wrap_imcc_hack( - interp, sourcefile, argc, argv, &bytecodepmc, &run_pbc, imcc_run_api)) - show_last_error_and_exit(interp); + if (parsed_flags.have_pbc_file) { + if (!Parrot_api_load_bytecode_file(interp, parsed_flags.sourcefile, + &bytecodepmc)) + show_last_error_and_exit(interp); + } + else { + if (!Parrot_api_wrap_imcc_hack(interp, parsed_flags.sourcefile, argc, argv, + &bytecodepmc, &parsed_flags.execute_packfile, + imcc_run_api)) + show_last_error_and_exit(interp); + } - if (run_pbc) { + if (parsed_flags.execute_packfile) { if (!Parrot_api_pmc_wrap_string_array(interp, pir_argc, pir_argv, &argsarray)) show_last_error_and_exit(interp); if (!Parrot_api_run_bytecode(interp, bytecodepmc, argsarray)) @@ -436,6 +447,8 @@ Set up the const struct declaration for cmd_options */ + + /* TODO: Weed out the options that are not used by this executable */ PARROT_WARN_UNUSED_RESULT @@ -603,8 +616,7 @@ parseflags_minimal(ARGMOD(Parrot_Init_Args * initargs), int argc, ARGIN(const ch /* =item C +*argv[], int *pgm_argc, const char ***pgm_argv, struct init_args_t * args)> Parse Parrot's command line for options and set appropriate flags. @@ -614,15 +626,18 @@ Parse Parrot's command line for options and set appropriate flags. PARROT_CAN_RETURN_NULL static const char * -parseflags(Parrot_PMC interp, - int argc, ARGIN(const char *argv[]), +parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]), ARGOUT(int *pgm_argc), ARGOUT(const char ***pgm_argv), - ARGMOD(const char **core), ARGMOD(Parrot_Int *trace)) + ARGMOD(struct init_args_t * args)) { ASSERT_ARGS(parseflags) struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; int status; int result = 1; + args->run_core_name = "slow"; + args->execute_packfile = 1; + args->have_pbc_file = 0; + args->trace = 0; if (argc == 1) { usage(stderr); @@ -632,7 +647,7 @@ parseflags(Parrot_PMC interp, while ((status = longopt_get(argc, argv, Parrot_cmd_options(), &opt)) > 0) { switch (opt.opt_id) { case 'R': - *core = opt.opt_arg; + args->run_core_name = opt.opt_arg; break; case 'g': /* Handled in parseflags_minimal */ @@ -645,18 +660,18 @@ parseflags(Parrot_PMC interp, const unsigned long _temp = strtoul(opt.opt_arg, NULL, 16); /* const Parrot_trace_flags _temp_flag = (Parrot_trace_flags)_temp; */ const Parrot_Int _temp_flag = _temp; - *trace = _temp_flag; + args->trace = _temp_flag; } else - *trace = 0x01; + args->trace = 0x01; /* *trace = PARROT_TRACE_OPS_FLAG; */ break; case 'D': if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) - Parrot_api_debug_flag(interp, strtoul(opt.opt_arg, NULL, 16), 1); + result = Parrot_api_debug_flag(interp, strtoul(opt.opt_arg, NULL, 16), 1); else /* Parrot_api_debug_flag(interp, PARROT_MEM_STAT_DEBUG_FLAG, 1); */ - Parrot_api_debug_flag(interp, 0x01, 1); + result = Parrot_api_debug_flag(interp, 0x01, 1); break; case '.': /* Give Windows Parrot hackers an opportunity to @@ -681,11 +696,25 @@ parseflags(Parrot_PMC interp, Parrot_api_get_runtime_path(interp, &runtimepath); Parrot_api_string_export_ascii(interp, runtimepath, &runtimepath_c); fprintf(stdout, "%s", runtimepath_c); + Parrot_api_string_free_exported_ascii(interp, runtimepath_c); exit(EXIT_SUCCESS); } case 'V': Parrot_version(); break; + case 'o': + args->execute_packfile = 0; + /* IMCC is going to read this option too, and handle it. */ + /* TODO: Move this logic out of IMCC. IMCC should return a + packfile and we can write it out to a file ourselves. */ + break; + case 'r': + args->execute_packfile = 1; + /* TODO: What else do we need to do for -r? We need to write the + packfile out to a file first, then open and execute it? */ + break; + case 'c': + args->have_pbc_file = 1; case OPT_GC_DEBUG: /* @@ -697,11 +726,11 @@ parseflags(Parrot_PMC interp, #endif */ /* Parrot_api_flag(interp, PARROT_GC_DEBUG_FLAG, 1); */ - Parrot_api_flag(interp, 0x10, 1); + result = Parrot_api_flag(interp, 0x10, 1); break; case OPT_DESTROY_FLAG: /* Parrot_api_flag(interp, PARROT_DESTROY_FLAG, 1); */ - Parrot_api_flag(interp, 0x200, 1); + result = Parrot_api_flag(interp, 0x200, 1); break; case 'I': result = Parrot_api_add_include_search_path(interp, opt.opt_arg); @@ -744,7 +773,12 @@ parseflags(Parrot_PMC interp, *pgm_argc = argc - opt.opt_index; *pgm_argv = argv + opt.opt_index; - return (*pgm_argv)[0]; + args->sourcefile = (*pgm_argv)[0]; + { + const char * ext = strrchr(args->sourcefile, '.'); + if (ext && !strcmp(ext, ".pbc")) + args->have_pbc_file = 1; + } } /* diff --git a/src/embed/api.c b/src/embed/api.c index 76796043ac..e893b95080 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -317,7 +317,7 @@ returns a true value if this call is successful and false value otherwise. */ /* TODO: This only works with the inital bytecode. After this we should use - Parrot_append_bytecode or something similar */ + Parrot_append_bytecode or something similar */ PARROT_API Parrot_Int From 31792fae89dcff165d9572b0475f4147c3831c2c Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 17:45:55 -0500 Subject: [PATCH 16/28] Add a new API function to serialize a packfile PMC into a format suitable for writing a .pbc file. This code stolen in part from compilers/imcc/main.c:imcc_write_pbc --- include/parrot/api.h | 11 +++++++++++ src/embed/api.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/parrot/api.h b/include/parrot/api.h index 28908d03b4..899bc6987b 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -189,6 +189,14 @@ Parrot_Int Parrot_api_run_bytecode( Parrot_PMC pbc, Parrot_PMC mainargs); +PARROT_API +Parrot_Int Parrot_api_serialize_bytecode_pmc( + Parrot_PMC interp_pmc, + Parrot_PMC pbc, + ARGOUT(Parrot_String * bc)) + __attribute__nonnull__(3) + FUNC_MODIFIES(* bc); + PARROT_API Parrot_Int Parrot_api_set_compiler( Parrot_PMC interp_pmc, @@ -277,6 +285,9 @@ Parrot_Int Parrot_api_wrap_imcc_hack( #define ASSERT_ARGS_Parrot_api_ready_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(main_sub)) #define ASSERT_ARGS_Parrot_api_run_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_serialize_bytecode_pmc \ + __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(bc)) #define ASSERT_ARGS_Parrot_api_set_compiler __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_set_configuration_hash \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) diff --git a/src/embed/api.c b/src/embed/api.c index 98e9014e22..9d92bcaac0 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -495,6 +495,39 @@ Parrot_api_disassemble_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc, /* +=item C + +Serialize a packfile PMC into a sequence of bytes suitable for writing out +to a .pbc file + +=cut + +*/ + +PARROT_API +Parrot_Int +Parrot_api_serialize_bytecode_pmc(Parrot_PMC interp_pmc, Parrot_PMC pbc, + ARGOUT(Parrot_String * bc)) +{ + ASSERT_ARGS(Parrot_api_serialize_bytecode_pmc) + EMBED_API_CALLIN(interp_pmc, interp) + PackFile * const pf = (PackFile *)VTABLE_get_pointer(interp, pbc); + if (!pf) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL, + "Could not get packfile."); + else { + const Parrot_Int size = PackFile_pack_size(interp, pf) * sizeof (opcode_t); + opcode_t * const packed = (opcode_t*) mem_sys_allocate(size); + PackFile_pack(interp, pf, packed); + *bc = Parrot_str_new_init(interp, (const char *)packed, size, + Parrot_binary_encoding_ptr, 0); + } + EMBED_API_CALLOUT(interp_pmc, interp) +} + +/* + =item C From 68f82869525efa6bd0e870606cc3fc1fe525b33b Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Fri, 14 Jan 2011 17:56:19 -0500 Subject: [PATCH 17/28] stub out a test for the new API function --- t/src/embed/api.t | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/t/src/embed/api.t b/t/src/embed/api.t index c6a4a05ec6..5ab23d093d 100644 --- a/t/src/embed/api.t +++ b/t/src/embed/api.t @@ -7,6 +7,7 @@ use lib qw( . lib ../lib ../../lib ); use Test::More; use Parrot::Test; use File::Spec::Functions; +use Parrot::Test::Util 'create_tempfile'; plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/); @@ -129,6 +130,43 @@ True Done OUTPUT +my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); +my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); +open PIR_FILE, $temp_pir, ">"; +print PIR_FILE <<'PIR_CODE'; +.sub main :mainargv + say "executed" +.end +PIR_CODE + +c_output_is( <<"CODE", << 'OUTPUT', "Parrot_api_serialize_bytecode_pmc" ); +#include +#include + +#include "parrot/api.h" + +void fail(const char *msg); + +void fail(const char *msg) +{ + fprintf(stderr, "failed: %s\n", msg); + exit(EXIT_FAILURE); +} + +int main(void) { + Parrot_PMC interp; + Parrot_PMC bytecode + Parrot_Int run_pbc; + Parrot_String pbc; + + const char *argv[] = {"$temp_pir"}; + Parrot_api_make_interpreter(NULL, 0, initargs, &inter); + + Parrot_api_wrap_imcc_hack(interp, sourcefile, 1, argv, &bytecode, &run_pbc, imcc_run_api); + Parrot_api_serialize_bytecode_pmc(interp, bytecode, &pbc); + // TODO: Write out to a file +} + # Local Variables: # mode: cperl # cperl-indent-level: 4 From ca855f2ca1ae58f90c3d6336e0b18fda13ecd200 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 09:10:18 -0500 Subject: [PATCH 18/28] implement the test for Parrot_api_serialize_bytecode_pmc. Fix some ARG modifiers to allow nulls, since we have logic in there to handle nulls --- compilers/imcc/main.c | 20 +++++++-------- include/parrot/api.h | 4 +-- src/embed/api.c | 2 +- t/src/embed/api.t | 59 +++++++++++++++++++++---------------------- 4 files changed, 40 insertions(+), 45 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 7cf8b9f445..6175cabcdc 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -75,17 +75,15 @@ static void imcc_get_optimization_description( static char * imcc_parseflags(PARROT_INTERP, int argc, - ARGIN(const char **argv)) - __attribute__nonnull__(1) - __attribute__nonnull__(3); + ARGIN_NULLOK(const char **argv)) + __attribute__nonnull__(1); static int imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), - ARGIN(const char *output_file), + ARGIN_NULLOK(const char *output_file), ARGOUT(PMC **pbcpmc)) __attribute__nonnull__(1) __attribute__nonnull__(2) - __attribute__nonnull__(3) __attribute__nonnull__(4) FUNC_MODIFIES(*pbcpmc); @@ -118,12 +116,10 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void); __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(opt_desc)) #define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(argv)) + PARROT_ASSERT_ARG(interp)) #define ASSERT_ARGS_imcc_run __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(sourcefile) \ - , PARROT_ASSERT_ARG(output_file) \ , PARROT_ASSERT_ARG(pbcpmc)) #define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ @@ -232,7 +228,7 @@ Parse flags ans set approptiate state(s) */ static char * -imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) +imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv)) { ASSERT_ARGS(imcc_parseflags) struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; @@ -240,6 +236,8 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv)) /* default state: run pbc */ SET_STATE_RUN_PBC(interp); + if (!argv) + return NULL; while (longopt_get(argc, argv, Parrot_cmd_options(), &opt) > 0) { switch (opt.opt_id) { @@ -631,7 +629,7 @@ PMC interpreter. PARROT_API int imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(const char *sourcefile), int argc, - ARGIN(const char **argv), ARGOUT(PMC **pbcpmc)) + ARGIN_NULLOK(const char **argv), ARGOUT(PMC **pbcpmc)) { Interp * interp = (Interp *)VTABLE_get_pointer(NULL, interp_pmc); const char * output_file = imcc_parseflags(interp, argc, argv); @@ -653,7 +651,7 @@ and run. This function always returns 0. static int imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), - ARGIN(const char *output_file), ARGOUT(PMC **pbcpmc)) + ARGIN_NULLOK(const char *output_file), ARGOUT(PMC **pbcpmc)) { yyscan_t yyscanner; PackFile * pf_raw = NULL; diff --git a/include/parrot/api.h b/include/parrot/api.h index bfdce64ee7..c80751fd86 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -229,12 +229,11 @@ Parrot_Int Parrot_api_wrap_imcc_hack( Parrot_PMC interp_pmc, ARGIN(const char * sourcefile), int argc, - ARGIN(const char **argv), + ARGIN_NULLOK(const char **argv), ARGMOD(Parrot_PMC* bytecodepmc), ARGOUT(int *result), imcc_hack_func_t func) __attribute__nonnull__(2) - __attribute__nonnull__(4) __attribute__nonnull__(5) __attribute__nonnull__(6) FUNC_MODIFIES(* bytecodepmc) @@ -294,7 +293,6 @@ Parrot_Int Parrot_api_wrap_imcc_hack( #define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_wrap_imcc_hack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(sourcefile) \ - , PARROT_ASSERT_ARG(argv) \ , PARROT_ASSERT_ARG(bytecodepmc) \ , PARROT_ASSERT_ARG(result)) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ diff --git a/src/embed/api.c b/src/embed/api.c index d8ba3e8366..14d9d56591 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -732,7 +732,7 @@ otherwise. PARROT_API Parrot_Int Parrot_api_wrap_imcc_hack(Parrot_PMC interp_pmc, ARGIN(const char * sourcefile), - int argc, ARGIN(const char **argv), ARGMOD(Parrot_PMC* bytecodepmc), + int argc, ARGIN_NULLOK(const char **argv), ARGMOD(Parrot_PMC* bytecodepmc), ARGOUT(int *result), imcc_hack_func_t func) { ASSERT_ARGS(Parrot_api_wrap_imcc_hack) diff --git a/t/src/embed/api.t b/t/src/embed/api.t index 5ab23d093d..5cfdef64f1 100644 --- a/t/src/embed/api.t +++ b/t/src/embed/api.t @@ -11,7 +11,7 @@ use Parrot::Test::Util 'create_tempfile'; plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/); -plan tests => 1; +plan tests => 2; =head1 NAME @@ -93,14 +93,6 @@ c_output_is(linedirective(__LINE__) . <<'CODE', <<'OUTPUT', "get set compiler" ) #include "parrot/api.h" -void fail(const char *msg); - -void fail(const char *msg) -{ - fprintf(stderr, "failed: %s\n", msg); - exit(EXIT_FAILURE); -} - int main(int argc, const char **argv) { char * c_outstr = NULL; @@ -130,11 +122,12 @@ True Done OUTPUT -my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); -my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); -open PIR_FILE, $temp_pir, ">"; +my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 ); +my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 ); +open PIR_FILE, ">", $temp_pir; print PIR_FILE <<'PIR_CODE'; -.sub main :mainargv +.sub main :main + .param pmc args say "executed" .end PIR_CODE @@ -145,27 +138,33 @@ c_output_is( <<"CODE", << 'OUTPUT', "Parrot_api_serialize_bytecode_pmc" ); #include "parrot/api.h" -void fail(const char *msg); - -void fail(const char *msg) -{ - fprintf(stderr, "failed: %s\n", msg); - exit(EXIT_FAILURE); -} - int main(void) { Parrot_PMC interp; - Parrot_PMC bytecode + Parrot_PMC bytecode; Parrot_Int run_pbc; - Parrot_String pbc; - - const char *argv[] = {"$temp_pir"}; - Parrot_api_make_interpreter(NULL, 0, initargs, &inter); - - Parrot_api_wrap_imcc_hack(interp, sourcefile, 1, argv, &bytecode, &run_pbc, imcc_run_api); - Parrot_api_serialize_bytecode_pmc(interp, bytecode, &pbc); - // TODO: Write out to a file + Parrot_String pbc_s; + Parrot_Int length; + char * pbc_c; + FILE * file; + + Parrot_api_make_interpreter(NULL, 0, NULL, &interp); + + /* Step 1: Take the PIR, and compile it to PBC. Write to file */ + Parrot_api_wrap_imcc_hack(interp, "$temp_pir", 0, NULL, &bytecode, &run_pbc, imcc_run_api); + Parrot_api_serialize_bytecode_pmc(interp, bytecode, &pbc_s); + Parrot_api_string_export_ascii(interp, pbc_s, &pbc_c); + Parrot_api_string_byte_length(interp, pbc_s, &length); + file = fopen("$temp_pbc", "w"); + fwrite(pbc_c, length, 1, file); + fclose(file); + + /* Step 2: Now load in the PIR and execute it */ + Parrot_api_load_bytecode_file(interp, "$temp_pbc", &bytecode); + Parrot_api_run_bytecode(interp, bytecode, NULL); } +CODE +executed +OUTPUT # Local Variables: # mode: cperl From bd67e176b144ebb6e9e9e5d9cab7dddec0f6feae Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 09:17:35 -0500 Subject: [PATCH 19/28] add temporary .c files to .gitignore. Also, unlike temporary files used by tests --- .gitignore | 1 + t/src/embed/api.t | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 182c4b5f07..27284bac15 100644 --- a/.gitignore +++ b/.gitignore @@ -443,6 +443,7 @@ /t/src/*_* /t/src/*.gcov /t/src/*.gcdada +/t/src/embed/*.c /t/stress/*.out /t/stress/*.pasm /t/stress/*.pbc diff --git a/t/src/embed/api.t b/t/src/embed/api.t index 5cfdef64f1..8661531fd7 100644 --- a/t/src/embed/api.t +++ b/t/src/embed/api.t @@ -122,8 +122,8 @@ True Done OUTPUT -my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 ); -my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 0 ); +my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); +my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 ); open PIR_FILE, ">", $temp_pir; print PIR_FILE <<'PIR_CODE'; .sub main :main From 255a8d8f91e77a38eee79fe17a9b3e7b5ebd53e0 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 09:44:41 -0500 Subject: [PATCH 20/28] move -G commandline argument parsing from IMCC into the frontend --- compilers/imcc/imc.h | 1 - compilers/imcc/main.c | 14 -------------- frontend/parrot/main.c | 10 ++++++++++ include/parrot/api.h | 4 ++++ src/embed/api.c | 28 +++++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/compilers/imcc/imc.h b/compilers/imcc/imc.h index d65a1aa56c..62b7a887f9 100644 --- a/compilers/imcc/imc.h +++ b/compilers/imcc/imc.h @@ -548,7 +548,6 @@ typedef struct _imc_info_t { int emitter; int error_code; /* The Error code. */ int expect_pasm; - int gc_off; int imcc_warn; int in_pod; int ins_line; diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 6175cabcdc..757ea902fc 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -250,13 +250,8 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv)) } break; case 'w': - /* FIXME It's not best way to set warnings... */ - Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG); IMCC_INFO(interp)->imcc_warn = 1; break; - case 'G': - IMCC_INFO(interp)->gc_off = 1; - break; case 'a': SET_STATE_PASM_FILE(interp); break; @@ -657,10 +652,6 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), PackFile * pf_raw = NULL; *pbcpmc = PMCNULL; - /* PMCs in IMCC_INFO won't get marked */ - Parrot_block_GC_mark(interp); - Parrot_block_GC_sweep(interp); - yylex_init_extra(interp, &yyscanner); /* Figure out what kind of source file we have -- if we have one */ @@ -734,11 +725,6 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), else PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG); - if (!IMCC_INFO(interp)->gc_off) { - Parrot_unblock_GC_mark(interp); - Parrot_unblock_GC_sweep(interp); - } - yylex_destroy(yyscanner); if (pf_raw) { diff --git a/frontend/parrot/main.c b/frontend/parrot/main.c index b30e7b0744..1f02546b8b 100644 --- a/frontend/parrot/main.c +++ b/frontend/parrot/main.c @@ -30,6 +30,7 @@ struct init_args_t { Parrot_Int trace; Parrot_Int execute_packfile; Parrot_Int have_pbc_file; + Parrot_Int turn_gc_off; }; extern int Parrot_set_config_hash(Parrot_PMC interp_pmc); @@ -177,12 +178,17 @@ main(int argc, const char *argv[]) if (!Parrot_api_load_bytecode_file(interp, parsed_flags.sourcefile, &bytecodepmc)) show_last_error_and_exit(interp); + if (parsed_flags.turn_gc_off) + Parrot_api_toggle_gc(interp, 0); } else { + Parrot_api_toggle_gc(interp, 0); if (!Parrot_api_wrap_imcc_hack(interp, parsed_flags.sourcefile, argc, argv, &bytecodepmc, &parsed_flags.execute_packfile, imcc_run_api)) show_last_error_and_exit(interp); + if (!parsed_flags.turn_gc_off) + Parrot_api_toggle_gc(interp, 1); } if (parsed_flags.execute_packfile) { @@ -638,6 +644,7 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]), args->execute_packfile = 1; args->have_pbc_file = 0; args->trace = 0; + args->turn_gc_off = 0; if (argc == 1) { usage(stderr); @@ -652,6 +659,9 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]), case 'g': /* Handled in parseflags_minimal */ break; + case 'G': + args->turn_gc_off = 1; + break; case OPT_GC_THRESHOLD: /* handled in parseflags_minimal */ break; diff --git a/include/parrot/api.h b/include/parrot/api.h index c80751fd86..2542ff28b5 100644 --- a/include/parrot/api.h +++ b/include/parrot/api.h @@ -224,6 +224,9 @@ Parrot_Int Parrot_api_set_runcore( PARROT_API Parrot_Int Parrot_api_set_warnings(Parrot_PMC interp_pmc, Parrot_Int flags); +PARROT_API +Parrot_Int Parrot_api_toggle_gc(Parrot_PMC interp_pmc, Parrot_Int on); + PARROT_API Parrot_Int Parrot_api_wrap_imcc_hack( Parrot_PMC interp_pmc, @@ -291,6 +294,7 @@ Parrot_Int Parrot_api_wrap_imcc_hack( #define ASSERT_ARGS_Parrot_api_set_runcore __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(corename)) #define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) +#define ASSERT_ARGS_Parrot_api_toggle_gc __attribute__unused__ int _ASSERT_ARGS_CHECK = (0) #define ASSERT_ARGS_Parrot_api_wrap_imcc_hack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(sourcefile) \ , PARROT_ASSERT_ARG(bytecodepmc) \ diff --git a/src/embed/api.c b/src/embed/api.c index 14d9d56591..2d9c58af05 100644 --- a/src/embed/api.c +++ b/src/embed/api.c @@ -807,9 +807,35 @@ Parrot_api_set_compiler(Parrot_PMC interp_pmc, Parrot_String type, ASSERT_ARGS(Parrot_api_set_compiler) EMBED_API_CALLIN(interp_pmc, interp) Parrot_set_compiler(interp, type, compiler); - EMBED_API_CALLOUT(interp_pmc, interp); + EMBED_API_CALLOUT(interp_pmc, interp) } +/* + +=item C + +Turn Parrot's GC on or off. + +=cut + +*/ + +PARROT_API +Parrot_Int +Parrot_api_toggle_gc(Parrot_PMC interp_pmc, Parrot_Int on) +{ + ASSERT_ARGS(Parrot_api_toggle_gc) + EMBED_API_CALLIN(interp_pmc, interp) + if (on) { + Parrot_unblock_GC_mark(interp); + Parrot_unblock_GC_sweep(interp); + } + else { + Parrot_block_GC_mark(interp); + Parrot_block_GC_sweep(interp); + } + EMBED_API_CALLOUT(interp_pmc, interp) +} /* From 9c5ae86565cbb9d775963f1bc6f60863658577ac Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 09:54:49 -0500 Subject: [PATCH 21/28] remove -w argument processing from IMCC. It's handled in the frontend --- compilers/imcc/debug.c | 3 --- compilers/imcc/main.c | 9 --------- 2 files changed, 12 deletions(-) diff --git a/compilers/imcc/debug.c b/compilers/imcc/debug.c index 50ba439f1e..8465d4cb31 100644 --- a/compilers/imcc/debug.c +++ b/compilers/imcc/debug.c @@ -115,9 +115,6 @@ IMCC_warning(PARROT_INTERP, ARGIN(const char *fmt), ...) { ASSERT_ARGS(IMCC_warning) va_list ap; - if (IMCC_INFO(interp)->imcc_warn) - return; - va_start(ap, fmt); imcc_vfprintf(interp, Parrot_io_STDERR(interp), fmt, ap); va_end(ap); diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 757ea902fc..720d699f0e 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -249,9 +249,6 @@ imcc_parseflags(PARROT_INTERP, int argc, ARGIN_NULLOK(const char **argv)) IMCC_INFO(interp)->debug++; } break; - case 'w': - IMCC_INFO(interp)->imcc_warn = 1; - break; case 'a': SET_STATE_PASM_FILE(interp); break; @@ -719,12 +716,6 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), } } - /* tear down the compilation context */ - if (IMCC_INFO(interp)->imcc_warn) - PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG); - else - PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG); - yylex_destroy(yyscanner); if (pf_raw) { From 020e29232c9bd7b6c550859bb645d211cefafbbe Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 11:34:59 -0500 Subject: [PATCH 22/28] do not Parrot_destroy in IMCC --- compilers/imcc/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 720d699f0e..9653143dd1 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -664,7 +664,6 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), if (STATE_PRE_PROCESS(interp)) { do_pre_process(interp, yyscanner); - Parrot_destroy(interp); yylex_destroy(yyscanner); return 0; From 2442dea1ddcf6aaee136ca737a2aaaef2267210d Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 11:36:00 -0500 Subject: [PATCH 23/28] small cleanup --- compilers/imcc/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 9653143dd1..744c79aba2 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -724,10 +724,7 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), } /* should the bytecode be run */ - if (STATE_RUN_PBC(interp)) - return 1; - else - return 0; + return STATE_RUN_PBC(interp) ? 1 : 0; } /* From b523125f309efd953b6c359625c11ec76a90037d Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 11:41:32 -0500 Subject: [PATCH 24/28] remove two dead functions --- compilers/imcc/imclexer.c | 32 +++++++++++++++++---------- compilers/imcc/parser_util.c | 42 ------------------------------------ 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/compilers/imcc/imclexer.c b/compilers/imcc/imclexer.c index 1597e12c37..4d74630fd7 100644 --- a/compilers/imcc/imclexer.c +++ b/compilers/imcc/imclexer.c @@ -78,7 +78,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -109,6 +108,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -182,7 +183,15 @@ typedef void* yyscan_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -2478,7 +2487,7 @@ static int handle_identifier(PARROT_INTERP, YYSTYPE *valp, ARGIN(const char *id) -#line 2482 "compilers/imcc/imclexer.c" +#line 2491 "compilers/imcc/imclexer.c" #define INITIAL 0 #define emit 1 @@ -2573,10 +2582,6 @@ int yyget_lineno (yyscan_t yyscanner ); void yyset_lineno (int line_number ,yyscan_t yyscanner ); -int yyget_column (yyscan_t yyscanner ); - -void yyset_column (int column_no ,yyscan_t yyscanner ); - /* Macros after this point can all be overridden by user definitions in * section 1. */ @@ -2617,7 +2622,12 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -2636,7 +2646,7 @@ static int input (yyscan_t yyscanner ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - unsigned n; \ + size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -2741,7 +2751,7 @@ YY_DECL return 0; } -#line 2745 "compilers/imcc/imclexer.c" +#line 2755 "compilers/imcc/imclexer.c" if ( !yyg->yy_init ) { @@ -3920,7 +3930,7 @@ YY_RULE_SETUP #line 717 "compilers/imcc/imcc.l" ECHO; YY_BREAK -#line 3924 "compilers/imcc/imclexer.c" +#line 3934 "compilers/imcc/imclexer.c" case YY_STATE_EOF(pod): case YY_STATE_EOF(cmt1): case YY_STATE_EOF(cmt2): @@ -4709,8 +4719,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 1b5015b62c..fa9a9b3154 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -659,48 +659,6 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, /* -=item C - -Note: This function is provided for backward compatibility. This -function can go away in future. - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -imcc_compile_pasm(PARROT_INTERP, ARGIN(const char *s)) -{ - ASSERT_ARGS(imcc_compile_pasm) - STRING *error_message; - return imcc_compile(interp, s, 1, &error_message); -} - -/* - -=item C - -Note: This function is provided for backward compatibility. This -function can go away in future. - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -imcc_compile_pir(PARROT_INTERP, ARGIN(const char *s)) -{ - ASSERT_ARGS(imcc_compile_pir) - STRING *error_message; - return imcc_compile(interp, s, 0, &error_message); -} - -/* - =item C From b606d3defa0274dc1493b762f4051ad7f2c670f3 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 11:53:51 -0500 Subject: [PATCH 25/28] Add in some notes to tell where various IMCC call-in functions are being used. Consolidate the register_compilers function --- compilers/imcc/imc.h | 23 -- compilers/imcc/imcparser.c | 612 +++++++++++++++++------------------ compilers/imcc/imcparser.h | 11 +- compilers/imcc/parser_util.c | 37 +-- 4 files changed, 318 insertions(+), 365 deletions(-) diff --git a/compilers/imcc/imc.h b/compilers/imcc/imc.h index 62b7a887f9..f231db7060 100644 --- a/compilers/imcc/imc.h +++ b/compilers/imcc/imc.h @@ -219,12 +219,6 @@ PMC * imcc_compile(PARROT_INTERP, __attribute__nonnull__(4) FUNC_MODIFIES(*error_message); -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * imcc_compile_pasm(PARROT_INTERP, ARGIN(const char *s)) - __attribute__nonnull__(1) - __attribute__nonnull__(2); - PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) @@ -241,12 +235,6 @@ PMC * IMCC_compile_pasm_s(PARROT_INTERP, __attribute__nonnull__(3) FUNC_MODIFIES(*error_message); -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * imcc_compile_pir(PARROT_INTERP, ARGIN(const char *s)) - __attribute__nonnull__(1) - __attribute__nonnull__(2); - PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) @@ -312,9 +300,6 @@ void op_fullname( __attribute__nonnull__(3) FUNC_MODIFIES(*dest); -void register_compilers(PARROT_INTERP) - __attribute__nonnull__(1); - #define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(fullname) \ @@ -329,9 +314,6 @@ void register_compilers(PARROT_INTERP) PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(s) \ , PARROT_ASSERT_ARG(error_message)) -#define ASSERT_ARGS_imcc_compile_pasm __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s)) #define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(s)) @@ -339,9 +321,6 @@ void register_compilers(PARROT_INTERP) PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(s) \ , PARROT_ASSERT_ARG(error_message)) -#define ASSERT_ARGS_imcc_compile_pir __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s)) #define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(s)) @@ -369,8 +348,6 @@ void register_compilers(PARROT_INTERP) PARROT_ASSERT_ARG(dest) \ , PARROT_ASSERT_ARG(name) \ , PARROT_ASSERT_ARG(args)) -#define ASSERT_ARGS_register_compilers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp)) /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ /* HEADERIZER END: compilers/imcc/parser_util.c */ diff --git a/compilers/imcc/imcparser.c b/compilers/imcc/imcparser.c index 10ed851f85..2a692e9cf6 100644 --- a/compilers/imcc/imcparser.c +++ b/compilers/imcc/imcparser.c @@ -9,14 +9,13 @@ */ /* HEADERIZER HFILE: none */ /* HEADERIZER STOP */ -/* A Bison parser, made by GNU Bison 2.4.3. */ /* A Bison parser, made by GNU Bison 2.4.1. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -58,7 +57,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.4.1" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -1074,7 +1073,7 @@ do_loadlib(PARROT_INTERP, ARGIN(const char *lib)) /* Line 189 of yacc.c */ -#line 1065 "compilers/imcc/imcparser.c" +#line 1066 "compilers/imcc/imcparser.c" /* Enabling traces. */ #ifndef YYDEBUG @@ -1352,7 +1351,7 @@ typedef union YYSTYPE /* Line 214 of yacc.c */ -#line 1343 "compilers/imcc/imcparser.c" +#line 1344 "compilers/imcc/imcparser.c" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -1364,7 +1363,7 @@ typedef union YYSTYPE /* Line 264 of yacc.c */ -#line 1355 "compilers/imcc/imcparser.c" +#line 1356 "compilers/imcc/imcparser.c" #ifdef short # undef short @@ -1414,7 +1413,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS +# if YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -2344,18 +2343,9 @@ static const yytype_uint16 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. However, - YYFAIL appears to be in use. Nevertheless, it is formally deprecated - in Bison 2.4.2's NEWS entry, where a plan to phase it out is - discussed. */ + Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab -#if defined YYFAIL - /* This is here to suppress warnings from the GCC cpp's - -Wunused-macros. Normally we don't worry about that warning, but - some users do, and we want to make it easy for users to remove - YYFAIL uses, which will produce warnings from Bison 2.5. */ -#endif #define YYRECOVERING() (!!yyerrstatus) @@ -2412,7 +2402,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -3163,28 +3153,28 @@ YYSTYPE yylval; { case 2: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1087 "compilers/imcc/imcc.y" { if (yynerrs) YYABORT; (yyval.i) = 0; } break; case 5: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1096 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 6: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1097 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 7: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1099 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); @@ -3195,7 +3185,7 @@ YYSTYPE yylval; case 8: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1105 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); @@ -3206,42 +3196,42 @@ YYSTYPE yylval; case 9: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1110 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 10: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1111 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 11: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1112 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 12: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1113 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 13: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1117 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 14: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1119 "compilers/imcc/imcc.y" { (yyval.i) = 0; @@ -3252,7 +3242,7 @@ YYSTYPE yylval; case 15: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1128 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->line = atoi((yyvsp[(2) - (5)].s)); @@ -3263,7 +3253,7 @@ YYSTYPE yylval; case 16: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1134 "compilers/imcc/imcc.y" { /* set_filename() frees the STRINGC */ @@ -3273,7 +3263,7 @@ YYSTYPE yylval; case 17: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1142 "compilers/imcc/imcc.y" { /* We'll want to store an entry while emitting instructions, so just @@ -3286,7 +3276,7 @@ YYSTYPE yylval; case 18: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1154 "compilers/imcc/imcc.y" { STRING * const hll_name = Parrot_str_unescape(interp, (yyvsp[(2) - (2)].s) + 1, '"', NULL); @@ -3301,14 +3291,14 @@ YYSTYPE yylval; case 19: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1166 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 20: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1167 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 1); @@ -3319,14 +3309,14 @@ YYSTYPE yylval; case 21: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1175 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 22: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1176 "compilers/imcc/imcc.y" { (yyval.i) = mk_pmc_const_named(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (6)].s), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].s)); @@ -3338,49 +3328,49 @@ YYSTYPE yylval; case 27: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1194 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 28: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1195 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 29: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1196 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 30: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1197 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 31: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1198 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 34: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1203 "compilers/imcc/imcc.y" { clear_state(interp); } break; case 35: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1205 "compilers/imcc/imcc.y" { (yyval.i) = INS(interp, IMCC_INFO(interp)->cur_unit, @@ -3392,7 +3382,7 @@ YYSTYPE yylval; case 36: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1212 "compilers/imcc/imcc.y" { imc_close_unit(interp, IMCC_INFO(interp)->cur_unit); @@ -3402,7 +3392,7 @@ YYSTYPE yylval; case 37: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1217 "compilers/imcc/imcc.y" { (yyval.i) = iSUBROUTINE(interp, @@ -3415,7 +3405,7 @@ YYSTYPE yylval; case 38: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1225 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(2) - (2)].sr)); @@ -3424,7 +3414,7 @@ YYSTYPE yylval; case 39: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1229 "compilers/imcc/imcc.y" { char *name = mem_sys_strdup((yyvsp[(2) - (4)].s) + 1); @@ -3442,21 +3432,21 @@ YYSTYPE yylval; case 40: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1241 "compilers/imcc/imcc.y" { (yyval.i) = 0;} break; case 42: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1249 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_unit = imc_open_unit(interp, IMC_PASM); } break; case 43: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1252 "compilers/imcc/imcc.y" { /* if (optimizer_level & OPT_PASM) @@ -3469,7 +3459,7 @@ YYSTYPE yylval; case 46: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1268 "compilers/imcc/imcc.y" { int re_open = 0; @@ -3486,21 +3476,21 @@ YYSTYPE yylval; case 47: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1282 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); } break; case 48: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1283 "compilers/imcc/imcc.y" { (yyval.sr) = NULL; } break; case 49: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1287 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -3509,7 +3499,7 @@ YYSTYPE yylval; case 50: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1291 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -3520,14 +3510,14 @@ YYSTYPE yylval; case 51: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1299 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(1) - (1)].sr); } break; case 52: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1301 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(3) - (3)].sr); @@ -3537,7 +3527,7 @@ YYSTYPE yylval; case 53: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1309 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_unit = imc_open_unit(interp, IMC_PCCSUB); @@ -3546,7 +3536,7 @@ YYSTYPE yylval; case 54: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1313 "compilers/imcc/imcc.y" { iSUBROUTINE(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (3)].sr)); @@ -3555,7 +3545,7 @@ YYSTYPE yylval; case 55: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1317 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_call->pcc_sub->pragma = (yyvsp[(5) - (6)].t); @@ -3568,28 +3558,28 @@ YYSTYPE yylval; case 56: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1325 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 57: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1329 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 58: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1330 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 59: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1332 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -3604,21 +3594,21 @@ YYSTYPE yylval; case 60: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1344 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 61: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1344 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(3) - (3)].sr); IMCC_INFO(interp)->is_def = 0; } break; case 62: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1349 "compilers/imcc/imcc.y" { if ((yyvsp[(3) - (3)].t) & VT_OPT_FLAG && (yyvsp[(1) - (3)].t) != 'I') { @@ -3643,14 +3633,14 @@ YYSTYPE yylval; case 63: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1373 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 64: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1378 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3661,7 +3651,7 @@ YYSTYPE yylval; case 65: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1384 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3672,7 +3662,7 @@ YYSTYPE yylval; case 66: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1393 "compilers/imcc/imcc.y" { (yyval.t) = P_VTABLE; @@ -3683,7 +3673,7 @@ YYSTYPE yylval; case 67: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1399 "compilers/imcc/imcc.y" { (yyval.t) = P_VTABLE; @@ -3694,7 +3684,7 @@ YYSTYPE yylval; case 68: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1408 "compilers/imcc/imcc.y" { (yyval.t) = P_METHOD; @@ -3705,7 +3695,7 @@ YYSTYPE yylval; case 69: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1414 "compilers/imcc/imcc.y" { (yyval.t) = P_METHOD; @@ -3716,7 +3706,7 @@ YYSTYPE yylval; case 70: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1423 "compilers/imcc/imcc.y" { (yyval.t) = P_NSENTRY; @@ -3727,7 +3717,7 @@ YYSTYPE yylval; case 71: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1429 "compilers/imcc/imcc.y" { (yyval.t) = P_NSENTRY; @@ -3738,7 +3728,7 @@ YYSTYPE yylval; case 72: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1438 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3748,7 +3738,7 @@ YYSTYPE yylval; case 73: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1446 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3758,7 +3748,7 @@ YYSTYPE yylval; case 74: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1451 "compilers/imcc/imcc.y" { SymReg *r = mk_const(interp, (yyvsp[(3) - (4)].s), 'S'); @@ -3771,7 +3761,7 @@ YYSTYPE yylval; case 75: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1462 "compilers/imcc/imcc.y" { add_pcc_multi(interp, IMCC_INFO(interp)->cur_call, NULL); @@ -3780,7 +3770,7 @@ YYSTYPE yylval; case 76: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1466 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3790,7 +3780,7 @@ YYSTYPE yylval; case 77: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1471 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3800,35 +3790,35 @@ YYSTYPE yylval; case 78: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1478 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "INTVAL", 'S'); } break; case 79: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1479 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "FLOATVAL", 'S'); } break; case 80: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1480 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "PMC", 'S'); } break; case 81: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1481 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "STRING", 'S'); } break; case 82: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1483 "compilers/imcc/imcc.y" { SymReg *r; @@ -3844,7 +3834,7 @@ YYSTYPE yylval; case 83: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1494 "compilers/imcc/imcc.y" { SymReg *r; @@ -3860,14 +3850,14 @@ YYSTYPE yylval; case 84: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1504 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); } break; case 87: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1514 "compilers/imcc/imcc.y" { char name[128]; @@ -3894,112 +3884,112 @@ YYSTYPE yylval; case 88: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1540 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 89: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1544 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->label = 0; } break; case 90: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1545 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->label = 1; } break; case 91: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1549 "compilers/imcc/imcc.y" { (yyval.i) = NULL; } break; case 92: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1550 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->object = (yyvsp[(2) - (3)].sr); } break; case 93: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1554 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 95: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1559 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (1)].t); } break; case 96: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1560 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 97: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1564 "compilers/imcc/imcc.y" { (yyval.t) = P_LOAD; } break; case 98: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1565 "compilers/imcc/imcc.y" { (yyval.t) = P_INIT; } break; case 99: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1566 "compilers/imcc/imcc.y" { (yyval.t) = P_MAIN; } break; case 100: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1567 "compilers/imcc/imcc.y" { (yyval.t) = P_IMMEDIATE; } break; case 101: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1568 "compilers/imcc/imcc.y" { (yyval.t) = P_POSTCOMP; } break; case 102: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1569 "compilers/imcc/imcc.y" { (yyval.t) = P_ANON; } break; case 103: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1570 "compilers/imcc/imcc.y" { (yyval.t) = P_NEED_LEX; } break; case 111: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1582 "compilers/imcc/imcc.y" { add_pcc_sub(IMCC_INFO(interp)->cur_call, (yyvsp[(2) - (5)].sr)); @@ -4009,7 +3999,7 @@ YYSTYPE yylval; case 112: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1587 "compilers/imcc/imcc.y" { add_pcc_sub(IMCC_INFO(interp)->cur_call, (yyvsp[(2) - (3)].sr)); @@ -4018,14 +4008,14 @@ YYSTYPE yylval; case 113: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1593 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 114: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1594 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4040,21 +4030,21 @@ YYSTYPE yylval; case 115: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1606 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (2)].sr); } break; case 116: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1611 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 117: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1613 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4064,21 +4054,21 @@ YYSTYPE yylval; case 118: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1620 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 119: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1621 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 120: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1622 "compilers/imcc/imcc.y" { IdList * const l = (yyvsp[(4) - (4)].idlist); @@ -4092,84 +4082,84 @@ YYSTYPE yylval; case 121: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1633 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 122: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1634 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 123: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1638 "compilers/imcc/imcc.y" { (yyval.t) = VT_FLAT; } break; case 124: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1639 "compilers/imcc/imcc.y" { (yyval.t) = VT_OPTIONAL; } break; case 125: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1640 "compilers/imcc/imcc.y" { (yyval.t) = VT_OPT_FLAG; } break; case 126: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1641 "compilers/imcc/imcc.y" { (yyval.t) = VT_NAMED; } break; case 127: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1642 "compilers/imcc/imcc.y" { adv_named_set(interp, (yyvsp[(3) - (4)].s)); (yyval.t) = VT_NAMED; mem_sys_free((yyvsp[(3) - (4)].s)); } break; case 128: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1643 "compilers/imcc/imcc.y" { adv_named_set_u(interp, (yyvsp[(3) - (4)].s)); (yyval.t) = VT_NAMED; mem_sys_free((yyvsp[(3) - (4)].s)); } break; case 129: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1644 "compilers/imcc/imcc.y" { (yyval.t) = VT_CALL_SIG; } break; case 130: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1649 "compilers/imcc/imcc.y" { begin_return_or_yield(interp, 0); } break; case 131: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1651 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->asm_state = AsmDefault; } break; case 132: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1653 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->asm_state = AsmDefault; @@ -4179,28 +4169,28 @@ YYSTYPE yylval; case 133: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1660 "compilers/imcc/imcc.y" { begin_return_or_yield(interp, 1); } break; case 134: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1662 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->asm_state = AsmDefault; } break; case 135: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1666 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 136: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1668 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (2)].sr)) @@ -4210,7 +4200,7 @@ YYSTYPE yylval; case 137: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1673 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4220,14 +4210,14 @@ YYSTYPE yylval; case 138: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1680 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 139: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1682 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (2)].sr)) @@ -4237,7 +4227,7 @@ YYSTYPE yylval; case 140: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1687 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4247,21 +4237,21 @@ YYSTYPE yylval; case 141: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1694 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 142: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1698 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 143: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1703 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->asm_state == AsmDefault) @@ -4271,7 +4261,7 @@ YYSTYPE yylval; case 144: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1708 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->asm_state = AsmDefault; @@ -4281,28 +4271,28 @@ YYSTYPE yylval; case 145: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1715 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 146: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1716 "compilers/imcc/imcc.y" { (yyval.t) = 1; } break; case 147: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1720 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 148: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1722 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4317,7 +4307,7 @@ YYSTYPE yylval; case 149: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1732 "compilers/imcc/imcc.y" { SymReg * const name = mk_const(interp, (yyvsp[(1) - (3)].s), 'S'); @@ -4327,7 +4317,7 @@ YYSTYPE yylval; case 150: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1737 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4342,7 +4332,7 @@ YYSTYPE yylval; case 151: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1747 "compilers/imcc/imcc.y" { SymReg * const name = mk_const(interp, (yyvsp[(3) - (5)].s), 'S'); @@ -4352,63 +4342,63 @@ YYSTYPE yylval; case 154: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1768 "compilers/imcc/imcc.y" { clear_state(interp); } break; case 155: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1773 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (2)].i); } break; case 156: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1774 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 157: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1775 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 158: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1776 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 159: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1777 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 160: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1778 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 161: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1782 "compilers/imcc/imcc.y" { (yyval.i) = NULL; } break; case 165: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1793 "compilers/imcc/imcc.y" { Instruction * const i = iLABEL(interp, IMCC_INFO(interp)->cur_unit, mk_local_label(interp, (yyvsp[(1) - (1)].s))); @@ -4419,14 +4409,14 @@ YYSTYPE yylval; case 166: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1803 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (3)].i); } break; case 167: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1805 "compilers/imcc/imcc.y" { if (yynerrs >= PARROT_MAX_RECOVER_ERRORS) { @@ -4439,7 +4429,7 @@ YYSTYPE yylval; case 168: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1816 "compilers/imcc/imcc.y" { IdList* const l = (yyvsp[(1) - (1)].idlist); @@ -4450,7 +4440,7 @@ YYSTYPE yylval; case 169: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1823 "compilers/imcc/imcc.y" { IdList* const l = (yyvsp[(3) - (3)].idlist); @@ -4461,7 +4451,7 @@ YYSTYPE yylval; case 170: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1832 "compilers/imcc/imcc.y" { IdList* const l = mem_gc_allocate_n_zeroed_typed(interp, 1, IdList); @@ -4472,14 +4462,14 @@ YYSTYPE yylval; case 173: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1842 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 174: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1843 "compilers/imcc/imcc.y" { IdList *l = (yyvsp[(4) - (4)].idlist); @@ -4497,7 +4487,7 @@ YYSTYPE yylval; case 175: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1856 "compilers/imcc/imcc.y" { if ((yyvsp[(4) - (4)].sr)->set != 'P') { @@ -4519,7 +4509,7 @@ YYSTYPE yylval; case 176: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1873 "compilers/imcc/imcc.y" { if ((yyvsp[(4) - (4)].sr)->set != 'P') { @@ -4537,14 +4527,14 @@ YYSTYPE yylval; case 177: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1885 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 178: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1886 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 0); @@ -4555,14 +4545,14 @@ YYSTYPE yylval; case 180: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1893 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 181: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1894 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 1); @@ -4573,7 +4563,7 @@ YYSTYPE yylval; case 182: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1900 "compilers/imcc/imcc.y" { (yyval.i) = NULL; @@ -4584,7 +4574,7 @@ YYSTYPE yylval; case 183: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1906 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "branch", 1, (yyvsp[(2) - (2)].sr)); @@ -4593,7 +4583,7 @@ YYSTYPE yylval; case 184: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1910 "compilers/imcc/imcc.y" { (yyval.i) = INS(interp, @@ -4610,98 +4600,98 @@ YYSTYPE yylval; case 185: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1921 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(2) - (2)].sr)); } break; case 186: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1922 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 187: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1923 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 190: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1926 "compilers/imcc/imcc.y" { (yyval.i) = 0;} break; case 191: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1930 "compilers/imcc/imcc.y" { (yyval.t) = 'I'; } break; case 192: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1931 "compilers/imcc/imcc.y" { (yyval.t) = 'N'; } break; case 193: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1932 "compilers/imcc/imcc.y" { (yyval.t) = 'S'; } break; case 194: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1933 "compilers/imcc/imcc.y" { (yyval.t) = 'P'; } break; case 195: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1938 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "set", 2, (yyvsp[(1) - (3)].sr), (yyvsp[(3) - (3)].sr)); } break; case 196: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1940 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (4)].s), 2, (yyvsp[(1) - (4)].sr), (yyvsp[(4) - (4)].sr)); } break; case 197: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1942 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(4) - (5)].s), 3, (yyvsp[(1) - (5)].sr), (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); } break; case 198: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1944 "compilers/imcc/imcc.y" { (yyval.i) = iINDEXFETCH(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (6)].sr), (yyvsp[(3) - (6)].sr), (yyvsp[(5) - (6)].sr)); } break; case 199: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1946 "compilers/imcc/imcc.y" { (yyval.i) = iINDEXSET(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (6)].sr), (yyvsp[(3) - (6)].sr), (yyvsp[(6) - (6)].sr)); } break; case 200: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1949 "compilers/imcc/imcc.y" { add_pcc_result(interp, (yyvsp[(3) - (3)].i)->symregs[0], (yyvsp[(1) - (3)].sr)); @@ -4712,7 +4702,7 @@ YYSTYPE yylval; case 201: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1955 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -4721,7 +4711,7 @@ YYSTYPE yylval; case 202: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1959 "compilers/imcc/imcc.y" { IMCC_itcall_sub(interp, (yyvsp[(6) - (9)].sr)); @@ -4731,7 +4721,7 @@ YYSTYPE yylval; case 206: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1967 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(1) - (3)].sr)); @@ -4740,189 +4730,189 @@ YYSTYPE yylval; case 207: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1974 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"not"; } break; case 208: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1975 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bnot"; } break; case 209: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1976 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"neg"; } break; case 210: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1980 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"sub"; } break; case 211: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1981 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"add"; } break; case 212: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1982 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mul"; } break; case 213: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1983 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"div"; } break; case 214: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1984 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mod"; } break; case 215: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1985 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"fdiv"; } break; case 216: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1986 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"pow"; } break; case 217: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1987 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"concat"; } break; case 218: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1988 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"iseq"; } break; case 219: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1989 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isne"; } break; case 220: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1990 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isgt"; } break; case 221: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1991 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isge"; } break; case 222: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1992 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"islt"; } break; case 223: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1993 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isle"; } break; case 224: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1994 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shl"; } break; case 225: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1995 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shr"; } break; case 226: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1996 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lsr"; } break; case 227: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1997 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"and"; } break; case 228: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1998 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"or"; } break; case 229: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 1999 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"xor"; } break; case 230: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2000 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"band"; } break; case 231: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2001 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bor"; } break; case 232: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2002 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bxor"; } break; case 233: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2008 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -4933,21 +4923,21 @@ YYSTYPE yylval; case 234: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2013 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 235: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2020 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(2) - (3)].s), 2, (yyvsp[(1) - (3)].sr), (yyvsp[(3) - (3)].sr)); } break; case 236: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2022 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (3)].sr)->set == 'P') @@ -4959,91 +4949,91 @@ YYSTYPE yylval; case 237: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2031 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"add"; } break; case 238: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2032 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"sub"; } break; case 239: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2033 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mul"; } break; case 240: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2034 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"div"; } break; case 241: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2035 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mod"; } break; case 242: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2036 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"fdiv"; } break; case 243: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2037 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"band"; } break; case 244: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2038 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bor"; } break; case 245: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2039 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bxor"; } break; case 246: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2040 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shr"; } break; case 247: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2041 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shl"; } break; case 248: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2042 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lsr"; } break; case 249: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2048 "compilers/imcc/imcc.y" { (yyval.i) = func_ins(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (4)].sr), (yyvsp[(3) - (4)].s), @@ -5056,28 +5046,28 @@ YYSTYPE yylval; case 250: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2058 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 251: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2059 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_fromc(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 252: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2060 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_u(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 253: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2062 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); @@ -5088,7 +5078,7 @@ YYSTYPE yylval; case 254: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2068 "compilers/imcc/imcc.y" { /* disallow bareword method names; SREG name constants are fine */ @@ -5107,7 +5097,7 @@ YYSTYPE yylval; case 255: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2082 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); @@ -5118,7 +5108,7 @@ YYSTYPE yylval; case 256: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2088 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); @@ -5129,14 +5119,14 @@ YYSTYPE yylval; case 257: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2093 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); (yyval.sr) = (yyvsp[(3) - (3)].sr); } break; case 258: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2099 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -5146,21 +5136,21 @@ YYSTYPE yylval; case 259: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2103 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (5)].i); } break; case 260: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2107 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 261: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2109 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5175,7 +5165,7 @@ YYSTYPE yylval; case 262: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2119 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5190,7 +5180,7 @@ YYSTYPE yylval; case 263: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2129 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5202,7 +5192,7 @@ YYSTYPE yylval; case 264: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2136 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5212,7 +5202,7 @@ YYSTYPE yylval; case 265: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2141 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5224,70 +5214,70 @@ YYSTYPE yylval; case 266: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2150 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (2)].sr); (yyval.sr)->type |= (yyvsp[(2) - (2)].t); } break; case 267: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2154 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 268: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2155 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 269: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2159 "compilers/imcc/imcc.y" { (yyval.t) = VT_FLAT; } break; case 270: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2160 "compilers/imcc/imcc.y" { (yyval.t) = VT_NAMED; } break; case 271: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2161 "compilers/imcc/imcc.y" { (yyval.t) = VT_CALL_SIG; } break; case 272: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2163 "compilers/imcc/imcc.y" { adv_named_set_u(interp, (yyvsp[(3) - (4)].s)); mem_sys_free((yyvsp[(3) - (4)].s)); (yyval.t) = 0; } break; case 273: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2164 "compilers/imcc/imcc.y" { adv_named_set(interp, (yyvsp[(3) - (4)].s)); mem_sys_free((yyvsp[(3) - (4)].s)); (yyval.t) = 0; } break; case 274: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2168 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (2)].sr); (yyval.sr)->type |= (yyvsp[(2) - (2)].t); } break; case 275: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2173 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5302,7 +5292,7 @@ YYSTYPE yylval; case 276: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2183 "compilers/imcc/imcc.y" { add_pcc_named_result(interp, IMCC_INFO(interp)->cur_call, @@ -5313,7 +5303,7 @@ YYSTYPE yylval; case 277: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2189 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5328,7 +5318,7 @@ YYSTYPE yylval; case 278: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2199 "compilers/imcc/imcc.y" { add_pcc_named_result(interp, IMCC_INFO(interp)->cur_call, mk_const(interp, (yyvsp[(1) - (3)].s), 'S'), (yyvsp[(3) - (3)].sr)); @@ -5338,28 +5328,28 @@ YYSTYPE yylval; case 279: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2203 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 280: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2207 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 281: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2208 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 282: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2213 "compilers/imcc/imcc.y" { (yyval.i) =MK_I(interp, IMCC_INFO(interp)->cur_unit, inv_op((yyvsp[(3) - (6)].s)), 3, (yyvsp[(2) - (6)].sr), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].sr)); @@ -5368,7 +5358,7 @@ YYSTYPE yylval; case 283: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2217 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "unless_null", 2, (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); @@ -5377,7 +5367,7 @@ YYSTYPE yylval; case 284: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2221 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "unless", 2, (yyvsp[(2) - (4)].sr), (yyvsp[(4) - (4)].sr)); @@ -5386,7 +5376,7 @@ YYSTYPE yylval; case 285: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2228 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "if", 2, (yyvsp[(2) - (4)].sr), (yyvsp[(4) - (4)].sr)); @@ -5395,7 +5385,7 @@ YYSTYPE yylval; case 286: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2232 "compilers/imcc/imcc.y" { (yyval.i) =MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (6)].s), 3, (yyvsp[(2) - (6)].sr), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].sr)); @@ -5404,7 +5394,7 @@ YYSTYPE yylval; case 287: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2236 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "if_null", 2, (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); @@ -5413,91 +5403,91 @@ YYSTYPE yylval; case 288: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2242 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 289: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2243 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 290: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2247 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"eq"; } break; case 291: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2248 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"ne"; } break; case 292: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2249 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"gt"; } break; case 293: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2250 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"ge"; } break; case 294: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2251 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lt"; } break; case 295: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2252 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"le"; } break; case 298: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2261 "compilers/imcc/imcc.y" { (yyval.sr) = NULL; } break; case 299: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2262 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); } break; case 300: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2266 "compilers/imcc/imcc.y" { (yyval.sr) = IMCC_INFO(interp)->regs[0]; } break; case 302: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2271 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(1) - (1)].sr); } break; case 303: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2273 "compilers/imcc/imcc.y" { IMCC_INFO(interp) -> regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(1) - (4)].sr); @@ -5509,7 +5499,7 @@ YYSTYPE yylval; case 304: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2280 "compilers/imcc/imcc.y" { IMCC_INFO(interp) -> regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(2) - (3)].sr); @@ -5519,49 +5509,49 @@ YYSTYPE yylval; case 306: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2287 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_fromc(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 307: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2288 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_u(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 308: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2292 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 309: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2293 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 310: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2297 "compilers/imcc/imcc.y" { (yyval.sr) = mk_label_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 311: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2298 "compilers/imcc/imcc.y" { (yyval.sr) = mk_label_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 316: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2312 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -5570,7 +5560,7 @@ YYSTYPE yylval; case 317: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2316 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -5581,7 +5571,7 @@ YYSTYPE yylval; case 318: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2324 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -5590,7 +5580,7 @@ YYSTYPE yylval; case 319: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2328 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -5601,14 +5591,14 @@ YYSTYPE yylval; case 320: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2336 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(1) - (1)].sr); } break; case 321: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2338 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(3) - (3)].sr); @@ -5618,7 +5608,7 @@ YYSTYPE yylval; case 322: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2346 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); @@ -5627,78 +5617,78 @@ YYSTYPE yylval; case 323: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2352 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'I'); } break; case 324: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2353 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'N'); } break; case 325: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2354 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'S'); } break; case 326: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2355 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'P'); } break; case 327: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2356 "compilers/imcc/imcc.y" { (yyval.sr) = mk_pasm_reg(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 328: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2360 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'S'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 329: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2361 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'U'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 330: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2365 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'I'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 331: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2366 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'N'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 332: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 2367 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); } break; -/* Line 1464 of yacc.c */ -#line 5689 "compilers/imcc/imcparser.c" +/* Line 1455 of yacc.c */ +#line 5681 "compilers/imcc/imcparser.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -5909,7 +5899,7 @@ YYSTYPE yylval; -/* Line 1684 of yacc.c */ +/* Line 1675 of yacc.c */ #line 2373 "compilers/imcc/imcc.y" diff --git a/compilers/imcc/imcparser.h b/compilers/imcc/imcparser.h index ecc47d7e75..cd5f8b35d4 100644 --- a/compilers/imcc/imcparser.h +++ b/compilers/imcc/imcparser.h @@ -9,14 +9,13 @@ */ /* HEADERIZER HFILE: none */ /* HEADERIZER STOP */ -/* A Bison parser, made by GNU Bison 2.4.3. */ /* A Bison parser, made by GNU Bison 2.4.1. */ /* Skeleton interface for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -290,7 +289,7 @@ typedef union YYSTYPE { -/* Line 1685 of yacc.c */ +/* Line 1676 of yacc.c */ #line 993 "compilers/imcc/imcc.y" IdList * idlist; @@ -301,8 +300,8 @@ typedef union YYSTYPE -/* Line 1685 of yacc.c */ -#line 293 "compilers/imcc/imcparser.h" +/* Line 1676 of yacc.c */ +#line 294 "compilers/imcc/imcparser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index fa9a9b3154..596a38e4a2 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -664,6 +664,8 @@ imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, Compile PIR code from a C string. Returns errors in the provided. +Called only from src/embed.c:Parrot_compile_string(). + =cut */ @@ -685,6 +687,8 @@ IMCC_compile_pir_s(PARROT_INTERP, ARGIN(const char *s), Compile PASM code from a C string. Returns errors in the provided. +Called only from src/embed.c:Parrot_compile_string(). + =cut */ @@ -705,6 +709,8 @@ IMCC_compile_pasm_s(PARROT_INTERP, ARGIN(const char *s), Compile PASM code from a C string. Throws an exception upon errors. +Called only from the PASM compreg + =cut */ @@ -732,6 +738,8 @@ imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) Compile PIR code from a C string. Throws an exception upon errors. +Called only from the PIR compreg + =cut */ @@ -760,6 +768,8 @@ imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) Compile a file by filename (can be either PASM or IMCC code) +Called only from src/interp/inter_misc.c:Parrot_compile_file + =cut */ @@ -874,30 +884,6 @@ imcc_compile_file(PARROT_INTERP, ARGIN(const char *fullname), /* -=item C - -Register additional compilers with the interpreter - -=cut - -*/ - -void -register_compilers(PARROT_INTERP) -{ - ASSERT_ARGS(register_compilers) - Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex); - Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex); - - /* It looks like this isn't used anywhere yet */ - /* TODO: return a Eval PMC, instead of a packfile */ - /* Parrot_compreg(interp, - Parrot_str_new_constant(interp, "FILE"), - imcc_compile_file ); */ -} - -/* - =item C @@ -1103,7 +1089,8 @@ imcc_init(PARROT_INTERP) PARROT_ASSERT(IMCC_INFO(interp) != NULL); /* register PASM and PIR compilers to parrot core */ - register_compilers(interp); + Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex); + Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex); } /* From da323e3bbffd17600910dacbf795dea27a0694a9 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Sun, 16 Jan 2011 21:39:08 -0500 Subject: [PATCH 26/28] move call-in interface functions for IMCC into compilers/imcc/main.c from compilers/imcc/parser_util.c. This will allow for better side-by-side comparison, and eventually unify these into a second callpath --- compilers/imcc/imc.h | 193 +++++++------- compilers/imcc/main.c | 472 ++++++++++++++++++++++++++++++++++- compilers/imcc/parser_util.c | 467 ---------------------------------- 3 files changed, 578 insertions(+), 554 deletions(-) diff --git a/compilers/imcc/imc.h b/compilers/imcc/imc.h index f231db7060..920fd6ae8a 100644 --- a/compilers/imcc/imc.h +++ b/compilers/imcc/imc.h @@ -61,6 +61,114 @@ enum { #define N_ELEMENTS(x) (sizeof (x)/sizeof ((x)[0])) +/* HEADERIZER BEGIN: compilers/imcc/main.c */ +/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ + +PARROT_EXPORT +PARROT_CANNOT_RETURN_NULL +void * imcc_compile_file(PARROT_INTERP, + ARGIN(const char *fullname), + ARGOUT(STRING **error_message)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(*error_message); + +PARROT_EXPORT +int imcc_run_api( + ARGMOD(PMC * interp_pmc), + ARGIN(const char *sourcefile), + int argc, + ARGIN_NULLOK(const char **argv), + ARGOUT(PMC **pbcpmc)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(5) + FUNC_MODIFIES(* interp_pmc) + FUNC_MODIFIES(*pbcpmc); + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * imcc_compile(PARROT_INTERP, + ARGIN(const char *s), + int pasm_file, + ARGOUT(STRING **error_message)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(4) + FUNC_MODIFIES(*error_message); + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) + __attribute__nonnull__(1) + __attribute__nonnull__(2); + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * IMCC_compile_pasm_s(PARROT_INTERP, + ARGIN(const char *s), + ARGOUT(STRING **error_message)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(*error_message); + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) + __attribute__nonnull__(1) + __attribute__nonnull__(2); + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * IMCC_compile_pir_s(PARROT_INTERP, + ARGIN(const char *s), + ARGOUT(STRING **error_message)) + __attribute__nonnull__(1) + __attribute__nonnull__(2) + __attribute__nonnull__(3) + FUNC_MODIFIES(*error_message); + +void imcc_destroy(PARROT_INTERP) + __attribute__nonnull__(1); + +void imcc_init(PARROT_INTERP) + __attribute__nonnull__(1); + +#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(fullname) \ + , PARROT_ASSERT_ARG(error_message)) +#define ASSERT_ARGS_imcc_run_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp_pmc) \ + , PARROT_ASSERT_ARG(sourcefile) \ + , PARROT_ASSERT_ARG(pbcpmc)) +#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(s) \ + , PARROT_ASSERT_ARG(error_message)) +#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(s)) +#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(s) \ + , PARROT_ASSERT_ARG(error_message)) +#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(s)) +#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp) \ + , PARROT_ASSERT_ARG(s) \ + , PARROT_ASSERT_ARG(error_message)) +#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp)) +#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(interp)) +/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ +/* HEADERIZER END: compilers/imcc/main.c */ + /* HEADERIZER BEGIN: compilers/imcc/imcc.y */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ @@ -183,16 +291,6 @@ Instruction * INS_LABEL(PARROT_INTERP, /* HEADERIZER BEGIN: compilers/imcc/parser_util.c */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ -PARROT_EXPORT -PARROT_CANNOT_RETURN_NULL -void * imcc_compile_file(PARROT_INTERP, - ARGIN(const char *fullname), - ARGOUT(STRING **error_message)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3) - FUNC_MODIFIES(*error_message); - void check_op(PARROT_INTERP, ARGOUT(op_info_t **op_info), ARGOUT(char *fullname), @@ -208,55 +306,6 @@ void check_op(PARROT_INTERP, FUNC_MODIFIES(*op_info) FUNC_MODIFIES(*fullname); -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * imcc_compile(PARROT_INTERP, - ARGIN(const char *s), - int pasm_file, - ARGOUT(STRING **error_message)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(4) - FUNC_MODIFIES(*error_message); - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) - __attribute__nonnull__(1) - __attribute__nonnull__(2); - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * IMCC_compile_pasm_s(PARROT_INTERP, - ARGIN(const char *s), - ARGOUT(STRING **error_message)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3) - FUNC_MODIFIES(*error_message); - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) - __attribute__nonnull__(1) - __attribute__nonnull__(2); - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * IMCC_compile_pir_s(PARROT_INTERP, - ARGIN(const char *s), - ARGOUT(STRING **error_message)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(3) - FUNC_MODIFIES(*error_message); - -void imcc_destroy(PARROT_INTERP) - __attribute__nonnull__(1); - -void imcc_init(PARROT_INTERP) - __attribute__nonnull__(1); - PARROT_IGNORABLE_RESULT int /*@alt void@*/ imcc_vfprintf(PARROT_INTERP, @@ -300,38 +349,12 @@ void op_fullname( __attribute__nonnull__(3) FUNC_MODIFIES(*dest); -#define ASSERT_ARGS_imcc_compile_file __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(fullname) \ - , PARROT_ASSERT_ARG(error_message)) #define ASSERT_ARGS_check_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(op_info) \ , PARROT_ASSERT_ARG(fullname) \ , PARROT_ASSERT_ARG(name) \ , PARROT_ASSERT_ARG(r)) -#define ASSERT_ARGS_imcc_compile __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s) \ - , PARROT_ASSERT_ARG(error_message)) -#define ASSERT_ARGS_imcc_compile_pasm_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s)) -#define ASSERT_ARGS_IMCC_compile_pasm_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s) \ - , PARROT_ASSERT_ARG(error_message)) -#define ASSERT_ARGS_imcc_compile_pir_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s)) -#define ASSERT_ARGS_IMCC_compile_pir_s __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp) \ - , PARROT_ASSERT_ARG(s) \ - , PARROT_ASSERT_ARG(error_message)) -#define ASSERT_ARGS_imcc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp)) -#define ASSERT_ARGS_imcc_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(interp)) #define ASSERT_ARGS_imcc_vfprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(io) \ diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index 744c79aba2..bacc6f4f58 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -29,16 +29,23 @@ IMCC helpers. #include #include "imc.h" +#include "parrot/dynext.h" #include "parrot/embed.h" #include "parrot/longopt.h" #include "parrot/runcore_api.h" #include "pmc/pmc_callcontext.h" +#include "pmc/pmc_sub.h" #include "pbc.h" #include "parser.h" +#include "optimizer.h" extern int yydebug; -/* HEADERIZER HFILE: none */ +/* XXX non-reentrant */ +static Parrot_mutex eval_nr_lock; +static INTVAL eval_nr = 0; + +/* HEADERIZER HFILE: compilers/imcc/imc.h */ /* HEADERIZER BEGIN: static */ /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ @@ -66,6 +73,10 @@ static void determine_output_file_type(PARROT_INTERP, static void do_pre_process(PARROT_INTERP, yyscan_t yyscanner) __attribute__nonnull__(1); +static void imcc_destroy_macro_values(ARGMOD(void *value)) + __attribute__nonnull__(1) + FUNC_MODIFIES(*value); + static void imcc_get_optimization_description( const PARROT_INTERP, int opt_level, @@ -112,6 +123,8 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void); , PARROT_ASSERT_ARG(output_file)) #define ASSERT_ARGS_do_pre_process __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp)) +#define ASSERT_ARGS_imcc_destroy_macro_values __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ + PARROT_ASSERT_ARG(value)) #define ASSERT_ARGS_imcc_get_optimization_description \ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(opt_desc)) @@ -618,7 +631,7 @@ PMC interpreter. */ -PARROT_API +PARROT_EXPORT int imcc_run_api(ARGMOD(PMC * interp_pmc), ARGIN(const char *sourcefile), int argc, ARGIN_NULLOK(const char **argv), ARGOUT(PMC **pbcpmc)) @@ -727,6 +740,461 @@ imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), return STATE_RUN_PBC(interp) ? 1 : 0; } +/* + +=item C + +Compile a pasm or imcc string + +FIXME as we have separate constants, the old constants in ghash must be deleted. + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * +imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, + ARGOUT(STRING **error_message)) +{ + ASSERT_ARGS(imcc_compile) + /* imcc always compiles to interp->code + * XXX: This is EXTREMELY bad. IMCC should not write to interp->code + * save old cs, make new + */ + STRING *name; + PackFile_ByteCode *old_cs, *new_cs; + PMC *eval_pmc = NULL; + struct _imc_info_t *imc_info = NULL; + struct parser_state_t *next; + void *yyscanner; + PMC *ignored; + UINTVAL regs_used[4] = {3, 3, 3, 3}; + INTVAL eval_number; + + yylex_init_extra(interp, &yyscanner); + + /* we create not yet anchored PMCs - e.g. Subs: turn off GC */ + Parrot_block_GC_mark(interp); + + if (IMCC_INFO(interp)->last_unit) { + /* a reentrant compile */ + imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t); + imc_info->ghash = IMCC_INFO(interp)->ghash; + imc_info->prev = IMCC_INFO(interp); + IMCC_INFO(interp) = imc_info; + } + + ignored = Parrot_push_context(interp, regs_used); + UNUSED(ignored); + + if (eval_nr == 0) + MUTEX_INIT(eval_nr_lock); + + LOCK(eval_nr_lock); + eval_number = ++eval_nr; + UNLOCK(eval_nr_lock); + + name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number); + new_cs = PF_create_default_segs(interp, name, 0, 0); + old_cs = Parrot_switch_to_cs(interp, new_cs, 0); + + IMCC_INFO(interp)->cur_namespace = NULL; + + /* spit out the sourcefile */ + if (Interp_debug_TEST(interp, PARROT_EVAL_DEBUG_FLAG)) { + char *buf = Parrot_str_to_cstring(interp, name); + FILE * const fp = fopen(buf, "w"); + Parrot_str_free_cstring(buf); + if (fp) { + fputs(s, fp); + fclose(fp); + } + } + + IMCC_push_parser_state(interp); + next = IMCC_INFO(interp)->state->next; + + if (imc_info) + IMCC_INFO(interp)->state->next = NULL; + + IMCC_INFO(interp)->state->pasm_file = pasm_file; + IMCC_INFO(interp)->state->file = Parrot_str_to_cstring(interp, name); + IMCC_INFO(interp)->expect_pasm = 0; + + compile_string(interp, s, yyscanner); + + Parrot_pop_context(interp); + + /* + * compile_string NULLifies frames->next, so that yywrap + * doesn't try to continue compiling the previous buffer + * This OTOH prevents pop_parser-state -> + * + * set next here and pop + */ + IMCC_INFO(interp)->state->next = next; + IMCC_pop_parser_state(interp, yyscanner); + + if (!IMCC_INFO(interp)->error_code) { + Parrot_Sub_attributes *sub_data; + + /* + * create sub PMC + * + * TODO if a sub was denoted :main return that instead + */ + eval_pmc = Parrot_pmc_new(interp, enum_class_Eval); + PMC_get_sub(interp, eval_pmc, sub_data); + sub_data->seg = new_cs; + sub_data->start_offs = 0; + sub_data->end_offs = new_cs->base.size; + sub_data->name = name; + + *error_message = NULL; + } + else { + PackFile_Segment_destroy(interp, (PackFile_Segment *)new_cs); + *error_message = IMCC_INFO(interp)->error_message; + } + + if (imc_info) { + SymReg *ns = IMCC_INFO(interp)->cur_namespace; + IMCC_INFO(interp) = imc_info->prev; + mem_sys_free(imc_info); + imc_info = IMCC_INFO(interp); + IMCC_INFO(interp)->cur_unit = imc_info->last_unit; + + if (ns && ns != imc_info->cur_namespace) + free_sym(ns); + + IMCC_INFO(interp)->cur_namespace = imc_info->cur_namespace; + } + else + imc_cleanup(interp, yyscanner); + + Parrot_unblock_GC_mark(interp); + + yylex_destroy(yyscanner); + + /* Now run any :load/:init subs. */ + if (!*error_message) + PackFile_fixup_subs(interp, PBC_MAIN, eval_pmc); + + /* restore old byte_code, */ + if (old_cs) + (void)Parrot_switch_to_cs(interp, old_cs, 0); + + return eval_pmc; +} + +/* + +=item C + +Compile PIR code from a C string. Returns errors in the provided. + +Called only from src/embed.c:Parrot_compile_string(). + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * +IMCC_compile_pir_s(PARROT_INTERP, ARGIN(const char *s), + ARGOUT(STRING **error_message)) +{ + ASSERT_ARGS(IMCC_compile_pir_s) + return imcc_compile(interp, s, 0, error_message); +} + +/* + +=item C + +Compile PASM code from a C string. Returns errors in the provided. + +Called only from src/embed.c:Parrot_compile_string(). + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * +IMCC_compile_pasm_s(PARROT_INTERP, ARGIN(const char *s), + ARGOUT(STRING **error_message)) +{ + ASSERT_ARGS(IMCC_compile_pasm_s) + return imcc_compile(interp, s, 1, error_message); +} + +/* + +=item C + +Compile PASM code from a C string. Throws an exception upon errors. + +Called only from the PASM compreg + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * +imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) +{ + ASSERT_ARGS(imcc_compile_pasm_ex) + STRING *error_message; + + PMC * const sub = imcc_compile(interp, s, 1, &error_message); + + if (sub) + return sub; + + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss", + error_message); +} + +/* + +=item C + +Compile PIR code from a C string. Throws an exception upon errors. + +Called only from the PIR compreg + +=cut + +*/ + +PARROT_WARN_UNUSED_RESULT +PARROT_CANNOT_RETURN_NULL +PMC * +imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) +{ + ASSERT_ARGS(imcc_compile_pir_ex) + STRING *error_message; + PMC *sub; + + sub = imcc_compile(interp, s, 0, &error_message); + if (sub) + return sub; + + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss", + error_message); +} + +/* + +=item C + +Compile a file by filename (can be either PASM or IMCC code) + +Called only from src/interp/inter_misc.c:Parrot_compile_file + +=cut + +*/ + +PARROT_EXPORT +PARROT_CANNOT_RETURN_NULL +void * +imcc_compile_file(PARROT_INTERP, ARGIN(const char *fullname), + ARGOUT(STRING **error_message)) +{ + ASSERT_ARGS(imcc_compile_file) + PackFile_ByteCode * const cs_save = Parrot_pf_get_current_code_segment(interp); + PackFile_ByteCode *cs = NULL; + struct _imc_info_t *imc_info = NULL; + const char *ext; + FILE *fp; + STRING *fs; + PMC *newcontext; + + /* need at least 3 regs for compilation of constant math e.g. + * add_i_ic_ic - see also IMCC_subst_constants() */ + UINTVAL regs_used[4] = {3, 3, 3, 3}; + + if (IMCC_INFO(interp)->last_unit) { + /* a reentrant compile */ + imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t); + imc_info->prev = IMCC_INFO(interp); + imc_info->ghash = IMCC_INFO(interp)->ghash; + IMCC_INFO(interp) = imc_info; + } + + fs = Parrot_str_new_init(interp, fullname, strlen(fullname), + Parrot_default_encoding_ptr, 0); + + if (Parrot_stat_info_intval(interp, fs, STAT_ISDIR)) + Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR, + "imcc_compile_file: '%s' is a directory\n", fullname); + + fp = fopen(fullname, "r"); + if (!fp) + IMCC_fatal(interp, EXCEPTION_EXTERNAL_ERROR, + "imcc_compile_file: couldn't open '%s'\n", fullname); + + IMCC_push_parser_state(interp); + { + /* Store a copy, in order to know how to free it later */ + char *copyname = mem_sys_strdup(fullname); + IMCC_INFO(interp)->state->file = copyname; + ext = strrchr(copyname, '.'); + } + + /* start over; let the start of line rule increment this to 1 */ + IMCC_INFO(interp)->line = 0; + + /* + * the Parrot_str_compare() called from pmc_type() triggers GC + * which can destroy packfiles under construction + */ + Parrot_block_GC_mark(interp); + + /* Activate a new context and reset it to initial values */ + newcontext = Parrot_push_context(interp, regs_used); + Parrot_pcc_set_HLL(interp, newcontext, 0); + Parrot_pcc_set_sub(interp, newcontext, 0); + IMCC_INFO(interp)->cur_namespace = NULL; + interp->code = NULL; + + if (ext && STREQ(ext, ".pasm")) { + void *yyscanner; + yylex_init_extra(interp, &yyscanner); + + IMCC_INFO(interp)->state->pasm_file = 1; + /* see imcc.l */ + compile_file(interp, fp, yyscanner); + + yylex_destroy(yyscanner); + } + else { + void *yyscanner; + yylex_init_extra(interp, &yyscanner); + + IMCC_INFO(interp)->state->pasm_file = 0; + compile_file(interp, fp, yyscanner); + + yylex_destroy(yyscanner); + } + + Parrot_unblock_GC_mark(interp); + Parrot_pop_context(interp); + + imc_cleanup(interp, NULL); + fclose(fp); + + if (!IMCC_INFO(interp)->error_code) + cs = Parrot_pf_get_current_code_segment(interp); + else + *error_message = IMCC_INFO(interp)->error_message; + + if (cs_save) + (void)Parrot_switch_to_cs(interp, cs_save, 0); + + if (imc_info) { + IMCC_INFO(interp) = imc_info->prev; + if (imc_info->globals) + mem_sys_free(imc_info->globals); + + mem_sys_free(imc_info); + } + + return cs; +} + +/* + +=item C + +Initialize IMCC with Parrot by registering it as a PIR and PASM compiler. + +=cut + +*/ + +void +imcc_init(PARROT_INTERP) +{ + ASSERT_ARGS(imcc_init) + PARROT_ASSERT(IMCC_INFO(interp) != NULL); + + /* register PASM and PIR compilers to parrot core */ + Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex); + Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex); +} + +/* + +=item C + +Deallocate memory associated with IMCC. + +=cut + +*/ + +void +imcc_destroy(PARROT_INTERP) +{ + ASSERT_ARGS(imcc_destroy) + Hash * const macros = IMCC_INFO(interp)->macros; + + if (macros) + Parrot_hash_chash_destroy_values(interp, macros, imcc_destroy_macro_values); + + if (IMCC_INFO(interp)->globals) + mem_sys_free(IMCC_INFO(interp)->globals); + + mem_sys_free(IMCC_INFO(interp)); + IMCC_INFO(interp) = NULL; + + if (eval_nr != 0) + MUTEX_DESTROY(eval_nr_lock); +} + +/* + +=item C + +A callback for Parrot_hash_chash_destroy_values() to free all macro-allocated memory. + +=cut + +*/ + +static void +imcc_destroy_macro_values(ARGMOD(void *value)) +{ + ASSERT_ARGS(imcc_destroy_macro_values) + macro_t * const m = (macro_t *)value; + params_t * const params = &m->params; + + int i; + + for (i = 0; i < params->num_param; ++i) { + char * const name = params->name[i]; + if (name) + mem_sys_free(name); + } + + mem_sys_free(m->expansion); + mem_sys_free(m); +} + + /* =back diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 596a38e4a2..437eca2c20 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -57,10 +57,6 @@ static int change_op_arg_to_num(PARROT_INTERP, FUNC_MODIFIES(*unit) FUNC_MODIFIES(*r); -static void imcc_destroy_macro_values(ARGMOD(void *value)) - __attribute__nonnull__(1) - FUNC_MODIFIES(*value); - PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static op_info_t * try_find_op(PARROT_INTERP, @@ -104,8 +100,6 @@ static Instruction * var_arg_ins(PARROT_INTERP, PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(unit) \ , PARROT_ASSERT_ARG(r)) -#define ASSERT_ARGS_imcc_destroy_macro_values __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ - PARROT_ASSERT_ARG(value)) #define ASSERT_ARGS_try_find_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ PARROT_ASSERT_ARG(interp) \ , PARROT_ASSERT_ARG(unit) \ @@ -128,9 +122,6 @@ static Instruction * var_arg_ins(PARROT_INTERP, * absolutely global to prevent the files from being overwritten. * */ -/* XXX non-reentrant */ -static Parrot_mutex eval_nr_lock; -static INTVAL eval_nr = 0; /* @@ -505,382 +496,6 @@ INS(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name), } } -extern void* yy_scan_string(const char *); - -/* - -=item C - -Compile a pasm or imcc string - -FIXME as we have separate constants, the old constants in ghash must be deleted. - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -imcc_compile(PARROT_INTERP, ARGIN(const char *s), int pasm_file, - ARGOUT(STRING **error_message)) -{ - ASSERT_ARGS(imcc_compile) - /* imcc always compiles to interp->code - * XXX: This is EXTREMELY bad. IMCC should not write to interp->code - * save old cs, make new - */ - STRING *name; - PackFile_ByteCode *old_cs, *new_cs; - PMC *eval_pmc = NULL; - struct _imc_info_t *imc_info = NULL; - struct parser_state_t *next; - void *yyscanner; - PMC *ignored; - UINTVAL regs_used[4] = {3, 3, 3, 3}; - INTVAL eval_number; - - yylex_init_extra(interp, &yyscanner); - - /* we create not yet anchored PMCs - e.g. Subs: turn off GC */ - Parrot_block_GC_mark(interp); - - if (IMCC_INFO(interp)->last_unit) { - /* a reentrant compile */ - imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t); - imc_info->ghash = IMCC_INFO(interp)->ghash; - imc_info->prev = IMCC_INFO(interp); - IMCC_INFO(interp) = imc_info; - } - - ignored = Parrot_push_context(interp, regs_used); - UNUSED(ignored); - - if (eval_nr == 0) - MUTEX_INIT(eval_nr_lock); - - LOCK(eval_nr_lock); - eval_number = ++eval_nr; - UNLOCK(eval_nr_lock); - - name = Parrot_sprintf_c(interp, "EVAL_" INTVAL_FMT, eval_number); - new_cs = PF_create_default_segs(interp, name, 0, 0); - old_cs = Parrot_switch_to_cs(interp, new_cs, 0); - - IMCC_INFO(interp)->cur_namespace = NULL; - - /* spit out the sourcefile */ - if (Interp_debug_TEST(interp, PARROT_EVAL_DEBUG_FLAG)) { - char *buf = Parrot_str_to_cstring(interp, name); - FILE * const fp = fopen(buf, "w"); - Parrot_str_free_cstring(buf); - if (fp) { - fputs(s, fp); - fclose(fp); - } - } - - IMCC_push_parser_state(interp); - next = IMCC_INFO(interp)->state->next; - - if (imc_info) - IMCC_INFO(interp)->state->next = NULL; - - IMCC_INFO(interp)->state->pasm_file = pasm_file; - IMCC_INFO(interp)->state->file = Parrot_str_to_cstring(interp, name); - IMCC_INFO(interp)->expect_pasm = 0; - - compile_string(interp, s, yyscanner); - - Parrot_pop_context(interp); - - /* - * compile_string NULLifies frames->next, so that yywrap - * doesn't try to continue compiling the previous buffer - * This OTOH prevents pop_parser-state -> - * - * set next here and pop - */ - IMCC_INFO(interp)->state->next = next; - IMCC_pop_parser_state(interp, yyscanner); - - if (!IMCC_INFO(interp)->error_code) { - Parrot_Sub_attributes *sub_data; - - /* - * create sub PMC - * - * TODO if a sub was denoted :main return that instead - */ - eval_pmc = Parrot_pmc_new(interp, enum_class_Eval); - PMC_get_sub(interp, eval_pmc, sub_data); - sub_data->seg = new_cs; - sub_data->start_offs = 0; - sub_data->end_offs = new_cs->base.size; - sub_data->name = name; - - *error_message = NULL; - } - else { - PackFile_Segment_destroy(interp, (PackFile_Segment *)new_cs); - *error_message = IMCC_INFO(interp)->error_message; - } - - if (imc_info) { - SymReg *ns = IMCC_INFO(interp)->cur_namespace; - IMCC_INFO(interp) = imc_info->prev; - mem_sys_free(imc_info); - imc_info = IMCC_INFO(interp); - IMCC_INFO(interp)->cur_unit = imc_info->last_unit; - - if (ns && ns != imc_info->cur_namespace) - free_sym(ns); - - IMCC_INFO(interp)->cur_namespace = imc_info->cur_namespace; - } - else - imc_cleanup(interp, yyscanner); - - Parrot_unblock_GC_mark(interp); - - yylex_destroy(yyscanner); - - /* Now run any :load/:init subs. */ - if (!*error_message) - PackFile_fixup_subs(interp, PBC_MAIN, eval_pmc); - - /* restore old byte_code, */ - if (old_cs) - (void)Parrot_switch_to_cs(interp, old_cs, 0); - - return eval_pmc; -} - -/* - -=item C - -Compile PIR code from a C string. Returns errors in the provided. - -Called only from src/embed.c:Parrot_compile_string(). - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -IMCC_compile_pir_s(PARROT_INTERP, ARGIN(const char *s), - ARGOUT(STRING **error_message)) -{ - ASSERT_ARGS(IMCC_compile_pir_s) - return imcc_compile(interp, s, 0, error_message); -} - -/* - -=item C - -Compile PASM code from a C string. Returns errors in the provided. - -Called only from src/embed.c:Parrot_compile_string(). - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -IMCC_compile_pasm_s(PARROT_INTERP, ARGIN(const char *s), - ARGOUT(STRING **error_message)) -{ - ASSERT_ARGS(IMCC_compile_pasm_s) - return imcc_compile(interp, s, 1, error_message); -} - -/* - -=item C - -Compile PASM code from a C string. Throws an exception upon errors. - -Called only from the PASM compreg - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -imcc_compile_pasm_ex(PARROT_INTERP, ARGIN(const char *s)) -{ - ASSERT_ARGS(imcc_compile_pasm_ex) - STRING *error_message; - - PMC * const sub = imcc_compile(interp, s, 1, &error_message); - - if (sub) - return sub; - - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss", - error_message); -} - -/* - -=item C - -Compile PIR code from a C string. Throws an exception upon errors. - -Called only from the PIR compreg - -=cut - -*/ - -PARROT_WARN_UNUSED_RESULT -PARROT_CANNOT_RETURN_NULL -PMC * -imcc_compile_pir_ex(PARROT_INTERP, ARGIN(const char *s)) -{ - ASSERT_ARGS(imcc_compile_pir_ex) - STRING *error_message; - PMC *sub; - - sub = imcc_compile(interp, s, 0, &error_message); - if (sub) - return sub; - - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_SYNTAX_ERROR, "%Ss", - error_message); -} - -/* - -=item C - -Compile a file by filename (can be either PASM or IMCC code) - -Called only from src/interp/inter_misc.c:Parrot_compile_file - -=cut - -*/ - -PARROT_EXPORT -PARROT_CANNOT_RETURN_NULL -void * -imcc_compile_file(PARROT_INTERP, ARGIN(const char *fullname), - ARGOUT(STRING **error_message)) -{ - ASSERT_ARGS(imcc_compile_file) - PackFile_ByteCode * const cs_save = Parrot_pf_get_current_code_segment(interp); - PackFile_ByteCode *cs = NULL; - struct _imc_info_t *imc_info = NULL; - const char *ext; - FILE *fp; - STRING *fs; - PMC *newcontext; - - /* need at least 3 regs for compilation of constant math e.g. - * add_i_ic_ic - see also IMCC_subst_constants() */ - UINTVAL regs_used[4] = {3, 3, 3, 3}; - - if (IMCC_INFO(interp)->last_unit) { - /* a reentrant compile */ - imc_info = mem_gc_allocate_zeroed_typed(interp, imc_info_t); - imc_info->prev = IMCC_INFO(interp); - imc_info->ghash = IMCC_INFO(interp)->ghash; - IMCC_INFO(interp) = imc_info; - } - - fs = Parrot_str_new_init(interp, fullname, strlen(fullname), - Parrot_default_encoding_ptr, 0); - - if (Parrot_stat_info_intval(interp, fs, STAT_ISDIR)) - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR, - "imcc_compile_file: '%s' is a directory\n", fullname); - - fp = fopen(fullname, "r"); - if (!fp) - IMCC_fatal(interp, EXCEPTION_EXTERNAL_ERROR, - "imcc_compile_file: couldn't open '%s'\n", fullname); - - IMCC_push_parser_state(interp); - { - /* Store a copy, in order to know how to free it later */ - char *copyname = mem_sys_strdup(fullname); - IMCC_INFO(interp)->state->file = copyname; - ext = strrchr(copyname, '.'); - } - - /* start over; let the start of line rule increment this to 1 */ - IMCC_INFO(interp)->line = 0; - - /* - * the Parrot_str_compare() called from pmc_type() triggers GC - * which can destroy packfiles under construction - */ - Parrot_block_GC_mark(interp); - - /* Activate a new context and reset it to initial values */ - newcontext = Parrot_push_context(interp, regs_used); - Parrot_pcc_set_HLL(interp, newcontext, 0); - Parrot_pcc_set_sub(interp, newcontext, 0); - IMCC_INFO(interp)->cur_namespace = NULL; - interp->code = NULL; - - if (ext && STREQ(ext, ".pasm")) { - void *yyscanner; - yylex_init_extra(interp, &yyscanner); - - IMCC_INFO(interp)->state->pasm_file = 1; - /* see imcc.l */ - compile_file(interp, fp, yyscanner); - - yylex_destroy(yyscanner); - } - else { - void *yyscanner; - yylex_init_extra(interp, &yyscanner); - - IMCC_INFO(interp)->state->pasm_file = 0; - compile_file(interp, fp, yyscanner); - - yylex_destroy(yyscanner); - } - - Parrot_unblock_GC_mark(interp); - Parrot_pop_context(interp); - - imc_cleanup(interp, NULL); - fclose(fp); - - if (!IMCC_INFO(interp)->error_code) - cs = Parrot_pf_get_current_code_segment(interp); - else - *error_message = IMCC_INFO(interp)->error_message; - - if (cs_save) - (void)Parrot_switch_to_cs(interp, cs_save, 0); - - if (imc_info) { - IMCC_INFO(interp) = imc_info->prev; - if (imc_info->globals) - mem_sys_free(imc_info->globals); - - mem_sys_free(imc_info); - } - - return cs; -} /* @@ -1070,88 +685,6 @@ imcc_vfprintf(PARROT_INTERP, ARGMOD(PMC *io), ARGIN(const char *format), va_list return Parrot_io_putps(interp, io, Parrot_vsprintf_c(interp, format, ap)); } -/* Utility functions */ - -/* - -=item C - -Initialize IMCC with Parrot by registering it as a PIR and PASM compiler. - -=cut - -*/ - -void -imcc_init(PARROT_INTERP) -{ - ASSERT_ARGS(imcc_init) - PARROT_ASSERT(IMCC_INFO(interp) != NULL); - - /* register PASM and PIR compilers to parrot core */ - Parrot_compreg(interp, Parrot_str_new_constant(interp, "PASM"), imcc_compile_pasm_ex); - Parrot_compreg(interp, Parrot_str_new_constant(interp, "PIR"), imcc_compile_pir_ex); -} - -/* - -=item C - -A callback for Parrot_hash_chash_destroy_values() to free all macro-allocated memory. - -=cut - -*/ - -static void -imcc_destroy_macro_values(ARGMOD(void *value)) -{ - ASSERT_ARGS(imcc_destroy_macro_values) - macro_t * const m = (macro_t *)value; - params_t * const params = &m->params; - - int i; - - for (i = 0; i < params->num_param; ++i) { - char * const name = params->name[i]; - if (name) - mem_sys_free(name); - } - - mem_sys_free(m->expansion); - mem_sys_free(m); -} - - -/* - -=item C - -Deallocate memory associated with IMCC. - -=cut - -*/ - -void -imcc_destroy(PARROT_INTERP) -{ - ASSERT_ARGS(imcc_destroy) - Hash * const macros = IMCC_INFO(interp)->macros; - - if (macros) - Parrot_hash_chash_destroy_values(interp, macros, imcc_destroy_macro_values); - - if (IMCC_INFO(interp)->globals) - mem_sys_free(IMCC_INFO(interp)->globals); - - mem_sys_free(IMCC_INFO(interp)); - IMCC_INFO(interp) = NULL; - - if (eval_nr != 0) - MUTEX_DESTROY(eval_nr_lock); -} - /* =back From 592b8ce31d2d9937039e95ebb779c5ea032d1eb6 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Tue, 18 Jan 2011 12:08:45 -0500 Subject: [PATCH 27/28] remove old vestige of IMCC -w handling. We do all that in the frontend now --- compilers/imcc/main.c | 1 - compilers/imcc/parser_util.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/compilers/imcc/main.c b/compilers/imcc/main.c index bacc6f4f58..92c894f169 100644 --- a/compilers/imcc/main.c +++ b/compilers/imcc/main.c @@ -29,7 +29,6 @@ IMCC helpers. #include #include "imc.h" -#include "parrot/dynext.h" #include "parrot/embed.h" #include "parrot/longopt.h" #include "parrot/runcore_api.h" diff --git a/compilers/imcc/parser_util.c b/compilers/imcc/parser_util.c index 437eca2c20..ec0d9c4918 100644 --- a/compilers/imcc/parser_util.c +++ b/compilers/imcc/parser_util.c @@ -447,10 +447,6 @@ INS(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name), if (STREQ(name, "end") || STREQ(name, "ret")) { ins->type |= ITBRANCH | IF_goto; } - else if (STREQ(name, "warningson")) { - /* emit a debug seg, if this op is seen */ - PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG); - } else if (STREQ(name, "yield")) { if (!IMCC_INFO(interp)->cur_unit->instructions->symregs[0]) IMCC_fataly(interp, EXCEPTION_SYNTAX_ERROR, From b347b0c9c19023ec136d8f63e6346869e626eb87 Mon Sep 17 00:00:00 2001 From: Whiteknight Date: Tue, 18 Jan 2011 12:20:34 -0500 Subject: [PATCH 28/28] add rules for checkdepend, though it still fails and I can't figure out why --- compilers/imcc/Rules.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compilers/imcc/Rules.in b/compilers/imcc/Rules.in index cd3507cfc3..4f0de49786 100644 --- a/compilers/imcc/Rules.in +++ b/compilers/imcc/Rules.in @@ -158,6 +158,8 @@ compilers/imcc/main$(O) : \ $(INC_DIR)/runcore_api.h \ $(INC_DIR)/api.h \ $(INC_DIR)/longopt.h \ + include/pmc/pmc_sub.h \ + include/pmc/pmc_callcontext.h \ $(PARROT_H_HEADERS) ## SUFFIX OVERRIDE - Warnings (This is generated code)