tisp

Unnamed repository; edit this file 'description' to name the repository.
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 8ae197462d5ad56470b72cebfedd8a9e3c9e5938
parent adc5c4e7b834c456ffaabec1ad1e4758d9592dd4
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 15 Mar 2018 23:43:34 -0700

Use recursion instead of a loop for eval

Diffstat:
tisp.c | 17++---------------
1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -424,7 +424,7 @@ eval_pair(Hash env, Val v) } static Val -tisp_trampoline(Hash env, Val v, int *continu) +tisp_eval(Hash env, Val v) { Val f, args; switch (v->t) { @@ -433,24 +433,20 @@ tisp_trampoline(Hash env, Val v, int *continu) case INTEGER: case RATIONAL: case STRING: - *continu = 0; return v; case SYMBOL: - *continu = 0; return hash_get(env, v->v.s); case PAIR: f = tisp_eval(env, car(v)); args = eval_pair(env, cdr(v)); switch (f->t) { case PRIMITIVE: - *continu = 0; return (*f->v.pr)(env, args); case FUNCTION: /* tail call into the function body with the extended env */ hash_extend(env, f->v.f.args, args); hash_merge(env, f->v.f.env); - *continu = 1; - return f->v.f.body; + return tisp_eval(env, f->v.f.body); default: die(1, "%s: Attempt to eval non primitive", argv0); } @@ -459,15 +455,6 @@ tisp_trampoline(Hash env, Val v, int *continu) return v; } -static Val -tisp_eval(Hash env, Val v) -{ - int continu = 1; - while(continu) - v = tisp_trampoline(env, v, &continu); - return v; -} - /* TODO return str for error msgs? */ static void tisp_print(Val v)