diff --git a/interp.c b/interp.c index c35cec4..76ec667 100644 --- a/interp.c +++ b/interp.c @@ -61,7 +61,7 @@ value_t run_interpreter(value_t lambda, value_t argv) register_state(&state, lambda, argv); - /* Keep going until something attempts to tail-call END_PROGRAM, the original 'k', indicating completion. */ + /* Keep going until we reach END_PROGRAM, "called" by "exit" builtin. */ while (state.lambda.value != END_PROGRAM) { state.ntransients = 0; @@ -146,6 +146,8 @@ value_t run_interpreter(value_t lambda, value_t argv) static value_t vector_ref(value_t v, fixnum_t idx) { vector_t *vec = get_vector(v); + if (!((idx >= 0) && (idx < vec->size))) + fprintf(stderr, "idx=%d, vec->size=%d\n", (int)idx, (int)vec->size); release_assert((idx >= 0) && (idx < vec->size)); return vec->elements[idx]; } @@ -160,6 +162,13 @@ static uint8_t byte_string_ref(value_t v, fixnum_t idx) static value_t struct_ref(value_t v, fixnum_t idx) { struct_t *s = get_struct(v); + if (!((idx >= 0) && (idx < s->nslots))) + { + fprintf(stderr, "idx=%d; nslots=%d;\n", + (int)idx, (int)s->nslots); + fprint_value(stderr, v); + fputc('\n', stderr); + } release_assert((idx >= 0) && (idx < s->nslots)); return s->slots[idx]; } @@ -629,7 +638,7 @@ static void register_state(interp_state_t *state, value_t lambda, value_t argv) register_gc_root(&state->kw_args, NIL); register_gc_root(&state->kw_vals, NIL); register_gc_root(&state->ctx, FALSE_VALUE); - register_gc_root(&state->k, END_PROGRAM); + register_gc_root(&state->k, lookup_builtin(BI_EXIT)); register_gc_root(&state->globals, UNDEFINED); register_gc_root(&state->instances, UNDEFINED);