diff --git a/include/chibi/sexp.h b/include/chibi/sexp.h index 68290edf..bc8311fc 100755 --- a/include/chibi/sexp.h +++ b/include/chibi/sexp.h @@ -1346,6 +1346,7 @@ enum sexp_context_globals { SEXP_G_RESUMECC_BYTECODE, SEXP_G_FINAL_RESUMER, SEXP_G_STRICT_P, + SEXP_G_NO_TAIL_CALLS_P, #if SEXP_USE_FOLD_CASE_SYMS SEXP_G_FOLD_CASE_P, #endif diff --git a/main.c b/main.c index 9a34e370..54feeff4 100644 --- a/main.c +++ b/main.c @@ -473,6 +473,10 @@ sexp run_main (int argc, char **argv) { init_context(); sexp_global(ctx, SEXP_G_STRICT_P) = SEXP_TRUE; handle_noarg(); break; + case 'T': + init_context(); sexp_global(ctx, SEXP_G_NO_TAIL_CALLS_P) = SEXP_TRUE; + handle_noarg(); + break; case 't': mods_loaded = 1; load_init(1); diff --git a/sexp.c b/sexp.c index 6f939462..82d10c5e 100644 --- a/sexp.c +++ b/sexp.c @@ -434,6 +434,7 @@ void sexp_init_context_globals (sexp ctx) { sexp_global(ctx, SEXP_G_SYMBOLS) = sexp_make_vector(ctx, sexp_make_fixnum(SEXP_SYMBOL_TABLE_SIZE), SEXP_NULL); #endif sexp_global(ctx, SEXP_G_STRICT_P) = SEXP_FALSE; + sexp_global(ctx, SEXP_G_NO_TAIL_CALLS_P) = SEXP_FALSE; #if SEXP_USE_FOLD_CASE_SYMS sexp_global(ctx, SEXP_G_FOLD_CASE_P) = sexp_make_boolean(SEXP_DEFAULT_FOLD_CASE_SYMS); #endif diff --git a/vm.c b/vm.c index 6acdf3ee..a16af9b4 100644 --- a/vm.c +++ b/vm.c @@ -475,7 +475,7 @@ static void generate_general_app (sexp ctx, sexp app) { sexp_generate(ctx, 0, 0, 0, sexp_car(app)); /* maybe overwrite the current frame */ - sexp_emit(ctx, (tailp ? SEXP_OP_TAIL_CALL : SEXP_OP_CALL)); + sexp_emit(ctx, ((tailp && sexp_not(sexp_global(ctx, SEXP_G_NO_TAIL_CALLS_P))) ? SEXP_OP_TAIL_CALL : SEXP_OP_CALL)); sexp_emit_word(ctx, (sexp_uint_t)sexp_make_fixnum(len)); sexp_context_tailp(ctx) = (char)tailp;