Use builtin exit function as initial continuation and add some debug info.

This commit is contained in:
Jesse D. McDonald 2012-07-06 10:53:07 -05:00
parent 8ba3fa0860
commit 4a98f4eb21
1 changed files with 11 additions and 2 deletions

View File

@ -61,7 +61,7 @@ value_t run_interpreter(value_t lambda, value_t argv)
register_state(&state, lambda, 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) while (state.lambda.value != END_PROGRAM)
{ {
state.ntransients = 0; 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) static value_t vector_ref(value_t v, fixnum_t idx)
{ {
vector_t *vec = get_vector(v); 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)); release_assert((idx >= 0) && (idx < vec->size));
return vec->elements[idx]; 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) static value_t struct_ref(value_t v, fixnum_t idx)
{ {
struct_t *s = get_struct(v); 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)); release_assert((idx >= 0) && (idx < s->nslots));
return s->slots[idx]; 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_args, NIL);
register_gc_root(&state->kw_vals, NIL); register_gc_root(&state->kw_vals, NIL);
register_gc_root(&state->ctx, FALSE_VALUE); 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->globals, UNDEFINED);
register_gc_root(&state->instances, UNDEFINED); register_gc_root(&state->instances, UNDEFINED);