Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some accessors for interp->initial_pf and interp->code to the pac…

…kfile 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
  • Loading branch information...
commit fc0f759060202a29ee43952bc236cd11c8ce95f0 1 parent 9d9cd51
@Whiteknight Whiteknight authored
View
6 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);
}
}
View
22 include/parrot/packfile.h
@@ -878,6 +878,12 @@ PackFile_Debug * Parrot_new_debug_seg(PARROT_INTERP,
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
PackFile_ByteCode * Parrot_switch_to_cs(PARROT_INTERP,
@@ -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. */
View
12 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;
View
30 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);
View
59 src/packfile/api.c
@@ -1752,6 +1752,62 @@ create_seg(PARROT_INTERP, ARGMOD(PackFile_Directory *dir), pack_file_types t,
return seg;
}
+/*
+
+=item C<PackFile * Parrot_pf_get_current_packfile(PARROT_INTERP)>
+
+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<PackFile_ByteCode * Parrot_pf_get_current_code_segment(PARROT_INTERP)>
+
+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<void Parrot_pf_set_current_packfile(PARROT_INTERP, PackFile * const pf)>
+
+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<static PackFile * PackFile_append(PARROT_INTERP, PackFile * const
-pf)>
+=item C<static PackFile * PackFile_append(PARROT_INTERP, PackFile * const pf)>
Reads and appends a PBC it to the current directory. Fixes up sub addresses in
newly loaded bytecode and runs C<:load> subs.

0 comments on commit fc0f759

Please sign in to comment.
Something went wrong with that request. Please try again.