Adding sexp_apply_no_err_handler utility and using in simplifier.

This commit is contained in:
Alex Shinn 2014-11-11 22:28:12 +09:00
parent 4d0daf5df4
commit c0b9a213c9
3 changed files with 23 additions and 1 deletions

View file

@ -1420,6 +1420,7 @@ SEXP_API sexp sexp_stack_trace_op (sexp ctx, sexp self, sexp_sint_t n, sexp out)
SEXP_API sexp sexp_apply (sexp context, sexp proc, sexp args);
SEXP_API sexp sexp_apply1 (sexp ctx, sexp f, sexp x);
SEXP_API sexp sexp_apply2 (sexp ctx, sexp f, sexp x, sexp y);
SEXP_API sexp sexp_apply_no_err_handler (sexp ctx, sexp proc, sexp args);
SEXP_API sexp sexp_make_trampoline (sexp ctx, sexp proc, sexp args);
SEXP_API sexp sexp_make_foreign (sexp ctx, const char *name, int num_args, int flags, sexp_proc1 f, sexp data);
SEXP_API void sexp_init(void);

View file

@ -51,7 +51,7 @@ static sexp simplify (sexp ctx, sexp ast, sexp init_substs, sexp lambda) {
tmp = sexp_make_vector(ctx2, 0, SEXP_VOID);
tmp = sexp_make_procedure(ctx2, SEXP_ZERO, SEXP_ZERO, res, tmp);
if (! sexp_exceptionp(tmp)) {
tmp = sexp_apply(ctx2, tmp, SEXP_NULL);
tmp = sexp_apply_no_err_handler(ctx2, tmp, SEXP_NULL);
if (! sexp_exceptionp(tmp))
app = sexp_make_lit(ctx2, tmp);
}

21
vm.c
View file

@ -2136,4 +2136,25 @@ sexp sexp_apply2 (sexp ctx, sexp f, sexp x, sexp y) {
return res;
}
sexp sexp_apply_no_err_handler (sexp ctx, sexp proc, sexp args) {
sexp res, err_cell;
sexp_gc_var2(handler, params);
sexp_gc_preserve2(ctx, handler, params);
#if SEXP_USE_GREEN_THREADS
params = sexp_context_params(ctx);
sexp_context_params(ctx) = SEXP_NULL;
#endif
err_cell = sexp_global(ctx, SEXP_G_ERR_HANDLER);
err_cell = sexp_opcodep(err_cell) ? sexp_opcode_data(err_cell) : SEXP_FALSE;
handler = sexp_pairp(err_cell) ? sexp_cdr(err_cell) : SEXP_FALSE;
if (sexp_pairp(err_cell)) sexp_cdr(err_cell) = SEXP_FALSE;
res = sexp_apply(ctx, proc, args);
if (sexp_pairp(err_cell)) sexp_cdr(err_cell) = handler;
#if SEXP_USE_GREEN_THREADS
sexp_context_params(ctx) = params;
#endif
sexp_gc_release2(ctx);
return res;
}
#endif