Permalink
Browse files

Add a new, temporary hack API for wrapping up IMCC so we can catch er…

…rors thrown from it. IMCC is not in libparrot, but acts like it is. Tweak some stuff for tests. We have a few tests failing because of bad error message formatting, but it all looks good to me so I don't understand the problem. All tests for functionality pass, including one TODO test passing in exit.t
  • Loading branch information...
1 parent 9d84c87 commit 5b6a239ac3a0cf872275327c0fd3e383dd1d5edf @Whiteknight Whiteknight committed Dec 4, 2010
Showing with 56 additions and 14 deletions.
  1. +1 −1 compilers/imcc/main.c
  2. +13 −0 include/parrot/api.h
  3. +8 −0 include/parrot/exit.h
  4. +2 −4 src/debug.c
  5. +8 −0 src/embed/api.c
  6. +3 −0 src/embed/embed_private.h
  7. +13 −0 src/exit.c
  8. +8 −9 src/main.c
View
@@ -623,7 +623,7 @@ compile_to_bytecode(PARROT_INTERP,
fprintf(stderr, "error:imcc:%s", error_str);
IMCC_print_inc(interp);
Parrot_str_free_cstring(error_str);
- Parrot_x_exit(interp, IMCC_FATAL_EXCEPTION);
+ Parrot_x_jump_out_error(interp, IMCC_FATAL_EXCEPTION);
}
imc_cleanup(interp, yyscanner);
View
@@ -14,6 +14,8 @@
#include "parrot/config.h"
#include "parrot/core_types.h"
+typedef int (*imcc_hack_func_t)(Parrot_PMC, const char *, int, const char **, Parrot_PMC*);
+
#define PARROT_API PARROT_EXPORT
/* having a modified version of PARROT_ASSERT which resolves as an integer
@@ -248,6 +250,16 @@ Parrot_Int Parrot_api_set_warnings(
__attribute__nonnull__(1)
FUNC_MODIFIES(*interp_pmc);
+PARROT_API
+Parrot_Int Parrot_api_wrap_imcc_hack(
+ Parrot_PMC interp_pmc,
+ const char * sourcefile,
+ int argc,
+ const char **argv,
+ Parrot_PMC* bytecodepmc,
+ int *result,
+ imcc_hack_func_t func);
+
#define ASSERT_ARGS_Parrot_api_add_dynext_search_path \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp_pmc) \
@@ -318,6 +330,7 @@ Parrot_Int Parrot_api_set_warnings(
PARROT_ASSERT_ARG(interp_pmc))
#define ASSERT_ARGS_Parrot_api_set_warnings __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp_pmc))
+#define ASSERT_ARGS_Parrot_api_wrap_imcc_hack __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/embed/api.c */
View
@@ -37,6 +37,12 @@ PARROT_COLD
void Parrot_x_jump_out(PARROT_INTERP, int status)
__attribute__nonnull__(1);
+PARROT_EXPORT
+PARROT_DOES_NOT_RETURN
+PARROT_COLD
+void Parrot_x_jump_out_error(PARROT_INTERP, int status)
+ __attribute__nonnull__(1);
+
PARROT_EXPORT
void Parrot_x_on_exit(PARROT_INTERP,
ARGIN(exit_handler_f function),
@@ -48,6 +54,8 @@ void Parrot_x_on_exit(PARROT_INTERP,
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_x_jump_out __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_x_jump_out_error __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_x_on_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(function))
View
@@ -128,10 +128,9 @@ static void no_such_register(PARROT_INTERP,
__attribute__nonnull__(1);
static STRING * PDB_get_continuation_backtrace(PARROT_INTERP,
- ARGMOD(PMC * sub),
+ ARGMOD_NULLOK(PMC * sub),
ARGMOD(PMC * ctx))
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(* sub)
FUNC_MODIFIES(* ctx);
@@ -175,7 +174,6 @@ static const char * skip_whitespace(ARGIN(const char *cmd))
#define ASSERT_ARGS_PDB_get_continuation_backtrace \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(sub) \
, PARROT_ASSERT_ARG(ctx))
#define ASSERT_ARGS_skip_whitespace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(cmd))
@@ -3324,7 +3322,7 @@ PDB_backtrace(PARROT_INTERP)
}
static STRING *
-PDB_get_continuation_backtrace(PARROT_INTERP, ARGMOD(PMC * sub), ARGMOD(PMC * ctx))
+PDB_get_continuation_backtrace(PARROT_INTERP, ARGMOD_NULLOK(PMC * sub), ARGMOD(PMC * ctx))
{
ASSERT_ARGS(PDB_get_continuation_backtrace)
STRING *str;
View
@@ -375,4 +375,12 @@ Parrot_api_set_configuration_hash(Parrot_PMC interp_pmc, Parrot_PMC confighash)
EMBED_API_CALLOUT(interp_pmc, interp);
}
+PARROT_API
+Parrot_Int
+Parrot_api_wrap_imcc_hack(Parrot_PMC interp_pmc, const char * sourcefile, int argc, const char **argv, Parrot_PMC* bytecodepmc, int *result, imcc_hack_func_t func)
+{
+ EMBED_API_CALLIN(interp_pmc, interp)
+ *result = func(interp_pmc, sourcefile, argc, argv, bytecodepmc);
+ EMBED_API_CALLOUT(interp_pmc, interp)
+}
@@ -5,6 +5,7 @@
#include "pmc/pmc_parrotinterpreter.h"
#define GET_RAW_INTERP(p) ((Parrot_ParrotInterpreter_attributes*)(p)->data)->interp;
+
#define EMBED_API_CALLIN(p, i) \
void * _oldtop; \
Parrot_jump_buff env; \
@@ -14,9 +15,11 @@
(i)->lo_var_ptr = &_oldtop; \
(i)->api_jmp_buf = &env; \
if (setjmp(env)) { \
+ (i)->api_jmp_buf = NULL; \
return !interp->exit_code; \
} else { \
{
+
#define EMBED_API_CALLOUT(p, i) \
} \
(i)->api_jmp_buf = NULL; \
View
@@ -74,6 +74,19 @@ Parrot_x_jump_out(PARROT_INTERP, int status)
exit(status);
}
+PARROT_EXPORT
+PARROT_DOES_NOT_RETURN
+PARROT_COLD
+void
+Parrot_x_jump_out_error(PARROT_INTERP, int status)
+{
+ ASSERT_ARGS(Parrot_x_jump_out_error)
+
+ interp->exit_code = status;
+ interp->final_exception = PMCNULL;
+ Parrot_x_jump_out(interp, status);
+}
+
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
View
@@ -124,6 +124,7 @@ main(int argc, const char *argv[])
int pir_argc;
const char **pir_argv;
const char *core = "slow";
+ int run_pbc = 0;
Parrot_Init_Args *initargs;
Parrot_Int trace = 0;
@@ -145,18 +146,17 @@ 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)) {
+ if (!Parrot_api_set_runcore(interp, core, 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 (imcc_run_api(interp, sourcefile, argc, argv, &bytecodepmc)) {
- if (!Parrot_api_build_argv_array(interp, pir_argc, pir_argv, &argsarray)) {
- fprintf(stderr, "PARROT VM: Could not load or run bytecode");
+ if (run_pbc) {
+ if (!Parrot_api_build_argv_array(interp, pir_argc, pir_argv, &argsarray))
show_last_error_and_exit(interp);
- }
- if (!Parrot_api_run_bytecode(interp, bytecodepmc, argsarray)) {
+ if (!Parrot_api_run_bytecode(interp, bytecodepmc, argsarray))
show_last_error_and_exit(interp);
- }
}
/* Clean-up after ourselves */
@@ -173,7 +173,6 @@ show_last_error_and_exit(Parrot_PMC interp)
if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) &&
Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {
- fprintf(stderr, "PARROT VM: Cannot recover\n");
exit(EXIT_FAILURE);
}

0 comments on commit 5b6a239

Please sign in to comment.