klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit c5bfb6985d3c25035fd41d50aedf6eae799f3682
parent 4f47f6e74de8f5d6957f855727b66767cc672442
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 23 Mar 2011 03:24:30 -0300

Bugfix: previous bugfix to check type of lone operand in binary predicates broke the functionality... Refactored a little and fixed the bug.

Diffstat:
Msrc/kghelpers.c | 31++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/kghelpers.c b/src/kghelpers.c @@ -170,10 +170,7 @@ void ftyped_bpredp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) Keep going even if the result is false to catch errors in type */ - if (comps == -1) { - /* this case is here to simplify the guard of the while */ - kapply_cc(K, b2tv(true)); - } else if (comps == 0) { + if (comps == 0) { /* this case has to be here because otherwise there is no check for the type of the lone operand */ TValue first = kcar(tail); @@ -182,21 +179,21 @@ void ftyped_bpredp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) klispE_throw_extra(K, name, ": bad argument type"); return; } - } else { - while(comps--) { - TValue first = kcar(tail); - tail = kcdr(tail); /* tail only advances one place per iteration */ - TValue second = kcar(tail); - - if (!(*typep)(first) || !(*typep)(second)) { - /* TODO show expected type */ - klispE_throw_extra(K, name, ": bad argument type"); - return; - } - res &= (*predp)(first, second); + } + + while(comps-- > 0) { + TValue first = kcar(tail); + tail = kcdr(tail); /* tail only advances one place per iteration */ + TValue second = kcar(tail); + + if (!(*typep)(first) || !(*typep)(second)) { + /* TODO show expected type */ + klispE_throw_extra(K, name, ": bad argument type"); + return; } - kapply_cc(K, b2tv(res)); + res &= (*predp)(first, second); } + kapply_cc(K, b2tv(res)); } /* typed finite list. Structure error should be throw before type errors */