commit ebf719abacbeb9b70e5e587a0069c4bacb94aea9 parent 71de3f58655049cb67d770903c334c984147a9ce Author: sin <sin@2f30.org> Date: Fri, 16 May 2014 13:26:39 +0100 Be consistent and use a switch statement in eval() Diffstat:
M | parser.c | | | 29 | ++++++++++++++--------------- |
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/parser.c b/parser.c @@ -541,7 +541,6 @@ eval(struct object *o) size_t i; struct object *tmp; - /* self-evaluating objects */ switch (o->type) { case OError: case OEof: @@ -549,27 +548,27 @@ eval(struct object *o) case OInteger: case OCharacter: case OString: + /* self-evaluating objects */ return o; - } - /* evaluate identifiers */ - if (o->type == OIdentifier) { + case OIdentifier: + /* evaluate identifiers */ tmp = lookupsym(o->d.i.name); if (!tmp) return error("unbound identifier"); return tmp; - } - /* evaluate builtins and procedures */ - if (o->type == OPair) { + case OPair: + /* evaluate builtins and procedures */ tmp = lookupsym(car(o)->d.i.name); - if (tmp) { - if (tmp->type == OIdentifier) { - for (i = 0; i < LEN(builtins); i++) - if (strcmp(tmp->d.i.name, builtins[i].name) == 0) - return builtins[i].fn(o); - } else if (tmp->type == OProc) { - return tmp->d.proc.fn(o); - } + if (!tmp) + break; + if (tmp->type == OIdentifier) { + for (i = 0; i < LEN(builtins); i++) + if (strcmp(tmp->d.i.name, builtins[i].name) == 0) + return builtins[i].fn(o); + } else if (tmp->type == OProc) { + return tmp->d.proc.fn(o); } + break; } return error("cannot eval object"); }