Skip to content

Commit

Permalink
WIP of stack more.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadd committed Nov 22, 2024
1 parent 27317bf commit b1eda2b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
45 changes: 42 additions & 3 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,55 @@ static bool in_heap_range(uintptr_t v)
if (v < sizeof(Header)) // cannot get Header*
return false;
const void *p = get_header(v);
return p >= heap && p < heap + init_size;
bool in = p >= heap && p < heap + init_size;
const uintptr_t d = 0x100;
if (!in && (p >= heap - d && p <= (heap + init_size + d)))
debug("ptr? %p", p);
return in;
}

static bool is_valueish(uintptr_t v)
{
return value_is_immediate(v) || v == Qnil || v % 8 == 0;
}

static bool is_valueish_in_heap(uintptr_t v)
{
ValueTag t = VALUE_TAG((Value) v);
switch (t) {
case TAG_PAIR: {
Pair *p = PAIR(v);
return is_valueish(p->car) && is_valueish(p->cdr);
}
case TAG_CLOSURE: {
Closure *p = CLOSURE(v);
return is_valueish(p->env) && is_valueish(p->params) &&
is_valueish(p->body);
}
case TAG_CONTINUATION: {
Continuation *p = CONTINUATION(v);
return is_valueish(p->call_stack) && is_valueish(p->retval);
}
case TAG_STR: {
String *p = STRING(v);
return (uintptr_t) p->body % 8U == 0;
}
case TAG_CFUNC:
case TAG_SYNTAX: {
Procedure *p = PROCEDURE(v);
return p->arity >= -1 && p->arity <= 7;
}
default:
return false;
}
}

static bool in_heap(uintptr_t v)
{
if (value_is_immediate(v) || v == Qnil ||
v % 8U != 0 || !in_heap_range(v))
return false;
ValueTag t = VALUE_TAG((Value) v);
return t >= TAG_PAIR && t <= TAG_SYNTAX; // need to be precise more?
return is_valueish_in_heap(v);
}

static void mark_maybe(uintptr_t v)
Expand Down
1 change: 1 addition & 0 deletions schaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ static Value iload(FILE *in, const char *filename)
dump_stack_trace();
return Qundef;
}
gc_add_root(&ast);
call_stack = Qnil;
Value ret = eval_body(&toplevel_environment, l);
call_stack_check_consistency();
Expand Down

0 comments on commit b1eda2b

Please sign in to comment.