klisp

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

commit 645aec933b06050afb442fe23f33cd0066555eef
parent 777279fcc84604834942c681f7a3eda44101b913
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri, 29 Apr 2011 20:42:23 -0300

Added tv_sym_equal (and refactored all comparison of symbols to use it) in preparation for source code info in symbols. Also some light refactoring in eq2p (switch instead of if/else if cascade).

Diffstat:
Msrc/kenvironment.c | 3++-
Msrc/kgeqp.h | 14+++++++++++---
Msrc/kobject.h | 4++++
3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/kenvironment.c b/src/kenvironment.c @@ -97,7 +97,8 @@ TValue kfind_local_binding(klisp_State *K, TValue bindings, TValue sym) while(!ttisnil(bindings)) { TValue first = kcar(bindings); TValue first_sym = kcar(first); - if (tv_equal(sym, first_sym)) + /* symbols can't be compared with tv_equal! */ + if (tv_sym_equal(sym, first_sym)) return first; bindings = kcdr(bindings); } diff --git a/src/kgeqp.h b/src/kgeqp.h @@ -30,22 +30,30 @@ inline bool eq2p(klisp_State *K, TValue obj1, TValue obj2) { bool res = (tv_equal(obj1, obj2)); if (!res && (ttype(obj1) == ttype(obj2))) { - if (ttisapplicative(obj1)) { + switch (ttype(obj1)) { + case K_TSYMBOL: + /* symbols can't be compared with tv_equal! */ + res = tv_sym_equal(obj1, obj2); + break; + case K_TAPPLICATIVE: while(ttisapplicative(obj1) && ttisapplicative(obj2)) { obj1 = kunwrap(obj1); obj2 = kunwrap(obj2); } res = (tv_equal(obj1, obj2)); - } else if (ttisbigint(obj1)) { + break; + case K_TBIGINT: /* it's important to know that it can't be the case that obj1 is bigint and obj is some other type and (eq? obj1 obj2) */ res = kbigint_eqp(obj1, obj2); - } else if (ttisbigrat(obj1)) { + break; + case K_TBIGRAT: /* it's important to know that it can't be the case that obj1 is bigrat and obj is some other type and (eq? obj1 obj2) */ res = kbigrat_eqp(K, obj1, obj2); + break; } /* immutable strings are interned so are covered already */ } return res; diff --git a/src/kobject.h b/src/kobject.h @@ -739,6 +739,10 @@ bool kis_output_port(TValue o); /* Macro to test the most basic equality on TValues */ #define tv_equal(tv1_, tv2_) ((tv1_).raw == (tv2_).raw) +/* Symbols could be eq? but not tv_equal? because of source info */ +#define tv_sym_equal(sym1_, sym2_) \ + (tv_equal(tv2sym(sym1_)->str, tv2sym(sym2_)->str)) + /* ** for internal debug only */