iris

small scheme interpreter
git clone git://git.2f30.org/iris
Log | Files | Refs | LICENSE

commit 1f730e0a33a4821070b539c6ccfecbbbd47eb18f
parent a253fe487b61b0f734d8e4d38fcbbcbe2afd7f76
Author: sin <sin@2f30.org>
Date:   Fri, 16 May 2014 12:56:05 +0100

Simplify evaluation of builtins and procedures

Diffstat:
Mparser.c | 23+++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/parser.c b/parser.c @@ -531,27 +531,22 @@ eval(struct object *o) } /* evaluate identifiers */ if (o->type == OIdentifier) { - for (i = 0; i < LEN(builtins); i++) - if (strcmp(o->d.i.s, builtins[i].name) == 0) - return error("cannot eval builtin in this context"); otmp = lookupsym(o->d.i.s); if (!otmp) return error("unbound identifier"); return otmp; } - /* evaluate builtins */ - for (i = 0; i < LEN(builtins); i++) { - otmp = builtins[i].fn(o); - if (otmp) - return otmp; - } - /* evalute primitive procedures */ + /* evaluate builtins and procedures */ if (o->type == OPair) { otmp = lookupsym(car(o)->d.i.s); - if (otmp && otmp->type == OProc) { - for (i = 0; i < LEN(procs); i++) - if (strcmp(otmp->d.proc.name, procs[i].name) == 0) - return procs[i].fn(o); + if (otmp) { + if (otmp->type == OIdentifier) { + for (i = 0; i < LEN(builtins); i++) + if (strcmp(otmp->d.i.s, builtins[i].name) == 0) + return builtins[i].fn(o); + } else if (otmp->type == OProc) { + return otmp->d.proc.fn(o); + } } } return error("cannot eval object");