iris

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

commit e38ba1671e2e236be50fb34144205c5b878520a1
parent 9203c225caabde0fed36559be6700f812bde76b0
Author: sin <sin@2f30.org>
Date:   Mon, 19 May 2014 14:41:46 +0100

No need to define evalplus() recursively

Diffstat:
Mparser.c | 35++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/parser.c b/parser.c @@ -677,29 +677,30 @@ evalnull(struct object *o) } static struct object * -doplus(struct object *o, struct object *n) -{ - struct object *arg; - - if (!car(o)) - return n; - arg = eval(car(o)); - if (arg->type == OError) - return arg; - if (arg->type != OInteger) - return error("expected integer"); - n->d.n.v += arg->d.n.v; - return doplus(cdr(o), n); -} - -static struct object * evalplus(struct object *o) { + struct object *arg, *args; + struct object *n; + if (o->type != OPair) return NULL; if (car(o)->type != OIdentifier) return NULL; - return doplus(cdr(o), integer(0)); + args = cdr(o); + n = integer(0); + while (args) { + arg = car(args); + if (!arg) + return n; + arg = eval(arg); + if (arg->type == OError) + return arg; + if (arg->type != OInteger) + return error("expected integer"); + n->d.n.v += arg->d.n.v; + args = cdr(args); + } + return n; } static struct object *