core: Factor-out assert_defined.
* mes.c (assert_defined): New function. (set_env_x): Use it. (builtin_eval): Use it.
This commit is contained in:
parent
97300ef6ae
commit
bcd6cd9dcc
34
mes.c
34
mes.c
|
@ -200,14 +200,7 @@ scm *
|
||||||
set_env_x (scm *x, scm *e, scm *a)
|
set_env_x (scm *x, scm *e, scm *a)
|
||||||
{
|
{
|
||||||
cache_invalidate (x);
|
cache_invalidate (x);
|
||||||
scm *p = assq (x, a);
|
scm *p = assert_defined (assq (x, a));
|
||||||
if (p->type != PAIR)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "set!: unbound variable:");
|
|
||||||
display_ (stderr, x);
|
|
||||||
fprintf (stderr, "\n");
|
|
||||||
assert (!"unbound variable");
|
|
||||||
}
|
|
||||||
return set_cdr_x (p, e);
|
return set_cdr_x (p, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +333,19 @@ assq_ref_cache (scm *x, scm *a)
|
||||||
}
|
}
|
||||||
#endif // ENV_CACHE
|
#endif // ENV_CACHE
|
||||||
|
|
||||||
|
scm *
|
||||||
|
assert_defined (scm *e)
|
||||||
|
{
|
||||||
|
if (e == &scm_undefined)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "eval: unbound variable:");
|
||||||
|
display_ (stderr, e);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
assert (!"unbound variable");
|
||||||
|
}
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
scm *
|
scm *
|
||||||
evlis_env (scm *m, scm *a)
|
evlis_env (scm *m, scm *a)
|
||||||
{
|
{
|
||||||
|
@ -397,22 +403,14 @@ builtin_eval (scm *e, scm *a)
|
||||||
{
|
{
|
||||||
if (builtin_p (e) == &scm_t) return e;
|
if (builtin_p (e) == &scm_t) return e;
|
||||||
if (e->type == SCM) return e;
|
if (e->type == SCM) return e;
|
||||||
|
if (e->type == SYMBOL) return assert_defined (assq_ref_cache (e, a));
|
||||||
|
|
||||||
e = expand_macro_env (e, a);
|
e = expand_macro_env (e, a);
|
||||||
|
|
||||||
if (e->type == SYMBOL) {
|
|
||||||
scm *y = assq_ref_cache (e, a);
|
|
||||||
if (y == &scm_undefined) {
|
|
||||||
fprintf (stderr, "eval: unbound variable:");
|
|
||||||
display_ (stderr, e);
|
|
||||||
fprintf (stderr, "\n");
|
|
||||||
assert (!"unbound variable");
|
|
||||||
}
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
else if (e->type != PAIR)
|
else if (e->type != PAIR)
|
||||||
return e;
|
return e;
|
||||||
else if (e->car->type != PAIR)
|
else if (e->car->type != PAIR)
|
||||||
|
if (e->type == SYMBOL) return assert_defined (assq_ref_cache (e, a));
|
||||||
{
|
{
|
||||||
if (e->car->type == STRING && string_to_symbol (e->car) == &symbol_noexpand)
|
if (e->car->type == STRING && string_to_symbol (e->car) == &symbol_noexpand)
|
||||||
e = cadr (e);
|
e = cadr (e);
|
||||||
|
|
Loading…
Reference in New Issue