klisp

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

commit 674f30ad4cd197f01689b48f9046dfb2956eb6f9
parent ce8bce5979e28ae3c2267834b4528d95177c7607
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu, 24 Mar 2011 20:47:14 -0300

Refactor: ftyped_bpredp now uses check_list.

Diffstat:
Msrc/kghelpers.c | 28+++++++---------------------
1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/src/kghelpers.c b/src/kghelpers.c @@ -130,28 +130,14 @@ void ftyped_bpredp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) /* check the ptree is a list first to allow the structure errors to take precedence over the type errors. */ - TValue tail = ptree; - int32_t pairs = 0; + int32_t cpairs; + int32_t pairs = check_list(K, name, true, ptree, &cpairs); - while(ttispair(tail) && kis_unmarked(tail)) { - pairs++; - kmark(tail); - tail = kcdr(tail); - } - unmark_list(K, ptree); - int32_t comps; - if (ttisnil(tail)) { - comps = pairs - 1; - } else if (ttispair(tail)) { - /* cyclical list require an extra comparison of the last - & first element of the cycle */ - comps = pairs; - } else { - klispE_throw_extra(K, name, ": expected list"); - return; - } + /* cyclical list require an extra comparison of the last + & first element of the cycle */ + int32_t comps = cpairs? pairs : pairs - 1; - tail = ptree; + TValue tail = ptree; bool res = true; /* check the type while checking the predicate. @@ -169,7 +155,7 @@ void ftyped_bpredp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) } } - while(comps-- > 0) { + while(comps-- > 0) { /* comps could be -1 if ptree is () */ TValue first = kcar(tail); tail = kcdr(tail); /* tail only advances one place per iteration */ TValue second = kcar(tail);