From bcd6cd9dccd83e50b951503fba3557fe4eb1f6a5 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 3 Nov 2016 10:37:08 +0100 Subject: [PATCH] core: Factor-out assert_defined. * mes.c (assert_defined): New function. (set_env_x): Use it. (builtin_eval): Use it. --- mes.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/mes.c b/mes.c index 00a42150..d9f2607e 100644 --- a/mes.c +++ b/mes.c @@ -200,14 +200,7 @@ scm * set_env_x (scm *x, scm *e, scm *a) { cache_invalidate (x); - scm *p = assq (x, a); - if (p->type != PAIR) - { - fprintf (stderr, "set!: unbound variable:"); - display_ (stderr, x); - fprintf (stderr, "\n"); - assert (!"unbound variable"); - } + scm *p = assert_defined (assq (x, a)); return set_cdr_x (p, e); } @@ -340,6 +333,19 @@ assq_ref_cache (scm *x, scm *a) } #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 * 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 (e->type == SCM) return e; + if (e->type == SYMBOL) return assert_defined (assq_ref_cache (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) return e; 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) e = cadr (e);