klisp

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

commit 50b10a7b6c89e0d5c6ed2e327516e52e426fe1d3
parent c2ab661c0234a6b577195927ad33ac98067818b0
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 28 Feb 2012 01:43:30 -0300

Modified makefile so that the debug features can be controlled: asserts, debug symbols & optimization on/off can be toggled.  Various fixes (e.g. inline->static inline) to avoid warnings with different combinations of these flags. Added ignore rule for git folder (hggit).

Diffstat:
M.hgignore | 2++
MTODO | 3---
Msrc/Makefile | 15+++++++++++++--
Msrc/kapplicative.h | 2+-
Msrc/kgffi.c | 2+-
Msrc/kghelpers.c | 2+-
Msrc/kghelpers.h | 18+++++++++---------
Msrc/kgnumbers.c | 6+++---
Msrc/kgpair_mut.c | 2+-
Msrc/kinteger.h | 4++--
Msrc/klimits.h | 7+++----
Msrc/kpair.h | 8++++----
Msrc/kreal.c | 6+++---
Msrc/kstate.h | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/ktable.c | 2+-
Msrc/ktoken.h | 8++++----
16 files changed, 85 insertions(+), 76 deletions(-)

diff --git a/.hgignore b/.hgignore @@ -4,4 +4,6 @@ syntax: glob *.a klisp TAGS +.git + diff --git a/TODO b/TODO @@ -1,5 +1,4 @@ * Release 0.3 -** Documentation: ** Test *** Windows - build @@ -13,8 +12,6 @@ ** Fix *** Windows - delete-file problem in Windows (do GC and retry) -** Makefile - - Add a couple of flags to turn debug on/off * Release 0.4+ ** refactor: *** clean stand alone interpreter diff --git a/src/Makefile b/src/Makefile @@ -9,7 +9,8 @@ PLAT= none CC=gcc # TEMP for now put in debug symbols # TEMP for now only 32 bit binaries (see kobject.h) -CFLAGS=-O2 -g -std=c99 -Wall -m32 $(MYCFLAGS) +CFLAGS=$(if $(DEBUG_NO_OPT),-O0,-O2) $(if $(DEBUG_SYMBOLS),-g) -std=gnu99 -Wall \ +$(if $(DEBUG_ASSERTS),-DKUSE_ASSERTS=1 )-m32 $(MYCFLAGS) AR= ar rcu RANLIB= ranlib RM= rm -f @@ -21,6 +22,16 @@ USE_LIBFFI= MINGW_LIBFFI_CFLAGS = -I/usr/local/lib/libffi-3.0.10/include MINGW_LIBFFI_LDFLAGS = -L/usr/local/lib/ +# Set DEBUG_SYMBOLS=1 to save debug symbols +DEBUG_SYMBOLS= +# Set DEBUG_ASSERTS=1 to turn on runtime asserts +DEBUG_ASSERTS= +# Set DEBUG_NO_OPT=1 to turn off optimization +DEBUG_NO_OPT= +# Set DEBUG_ALL=1 to turn all debug modes (symbols, asserts, optimizations off) +# TODO +DEBUG_ALL= + MYCFLAGS= MYLDFLAGS= MYLIBS= @@ -108,7 +119,7 @@ mingw: #lisp_use_posix isn't used right now... posix: $(MAKE) all \ - "MYCFLAGS=-DKLISP_USE_POSIX -D_POSIX_SOURCE $(if $(USE_LIBFFI),-DKUSE_LIBFFI=1)" \ + "MYCFLAGS=-DKLISP_USE_POSIX -D_POSIX_SOURCE $(if $(USE_LIBFFI),-DKUSE_LIBFFI=1 )" \ "MYLIBS=$(if $(USE_LIBFFI), -rdynamic -ldl -lffi)" macosx: $(MAKE) all \ diff --git a/src/kapplicative.h b/src/kapplicative.h @@ -23,6 +23,6 @@ TValue kwrap(klisp_State *K, TValue underlying); krooted_tvs_pop(K__); \ (app); }) -inline TValue kunwrap(TValue app) { return (tv2app(app)->underlying); } +static inline TValue kunwrap(TValue app) { return (tv2app(app)->underlying); } #endif diff --git a/src/kgffi.c b/src/kgffi.c @@ -459,7 +459,7 @@ static ffi_codec_t *tv2ffi_codec(klisp_State *K, TValue v) return NULL; } -inline size_t align(size_t offset, size_t alignment) +static inline size_t align(size_t offset, size_t alignment) { assert(alignment > 0); return offset + (alignment - offset % alignment) % alignment; diff --git a/src/kghelpers.c b/src/kghelpers.c @@ -1142,7 +1142,7 @@ TValue copy_es_immutable_h(klisp_State *K, TValue obj, bool mut_flag) ** The stack should contain only pairs, sym_ls should be ** as above */ -inline void ptree_clear_all(klisp_State *K, TValue sym_ls) +static inline void ptree_clear_all(klisp_State *K, TValue sym_ls) { while(!ttisnil(sym_ls)) { TValue first = sym_ls; diff --git a/src/kghelpers.h b/src/kghelpers.h @@ -74,19 +74,19 @@ void enc_typep(klisp_State *K); bool kpositivep(TValue n); bool knegativep(TValue n); -inline bool kfast_zerop(TValue n) +static inline bool kfast_zerop(TValue n) { return (ttisfixint(n) && ivalue(n) == 0) || (ttisdouble(n) && dvalue(n) == 0.0); } -inline bool kfast_onep(TValue n) +static inline bool kfast_onep(TValue n) { return (ttisfixint(n) && ivalue(n) == 1) || (ttisdouble(n) && dvalue(n) == 1.0); } -inline TValue kneg_inf(TValue i) +static inline TValue kneg_inf(TValue i) { if (ttiseinf(i)) return tv_equal(i, KEPINF)? KEMINF : KEPINF; @@ -94,7 +94,7 @@ inline TValue kneg_inf(TValue i) return tv_equal(i, KIPINF)? KIMINF : KIPINF; } -inline bool knum_same_signp(klisp_State *K, TValue n1, TValue n2) +static inline bool knum_same_signp(klisp_State *K, TValue n1, TValue n2) { return kpositivep(n1) == kpositivep(n2); } @@ -434,12 +434,12 @@ TValue check_copy_guards(klisp_State *K, char *name, TValue obj); void guard_dynamic_extent(klisp_State *K); /* Some helpers for working with fixints (signed 32 bits) */ -inline int32_t kabs32(int32_t a) { return a < 0? -a : a; } -inline int64_t kabs64(int64_t a) { return a < 0? -a : a; } -inline int32_t kmin32(int32_t a, int32_t b) { return a < b? a : b; } -inline int32_t kmax32(int32_t a, int32_t b) { return a > b? a : b; } +static inline int32_t kabs32(int32_t a) { return a < 0? -a : a; } +static inline int64_t kabs64(int64_t a) { return a < 0? -a : a; } +static inline int32_t kmin32(int32_t a, int32_t b) { return a < b? a : b; } +static inline int32_t kmax32(int32_t a, int32_t b) { return a > b? a : b; } -inline int32_t kcheck32(klisp_State *K, char *msg, int64_t i) +static inline int32_t kcheck32(klisp_State *K, char *msg, int64_t i) { if (i > (int64_t) INT32_MAX || i < (int64_t) INT32_MIN) { klispE_throw_simple(K, msg); diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -49,7 +49,7 @@ /* MAYBE: change to return -1, 0, 1 to indicate which type is bigger, and return min & max in two extra pointers passed in. Change name to classify_types */ -inline int32_t max_ttype(TValue obj1, TValue obj2) +static inline int32_t max_ttype(TValue obj1, TValue obj2) { int32_t t1 = ttype(obj1); int32_t t2 = ttype(obj2); @@ -57,7 +57,7 @@ inline int32_t max_ttype(TValue obj1, TValue obj2) return (t1 > t2? t1 : t2); } -inline int32_t min_ttype(TValue obj1, TValue obj2) +static inline int32_t min_ttype(TValue obj1, TValue obj2) { int32_t t1 = ttype(obj1); int32_t t2 = ttype(obj2); @@ -2374,7 +2374,7 @@ void number_to_string(klisp_State *K) break; default: /* shouldn't happen */ - klisp_assert(0); + abort(); } TValue str = kstring_new_b(K, buf); diff --git a/src/kgpair_mut.c b/src/kgpair_mut.c @@ -227,7 +227,7 @@ void list_setB(klisp_State *K) } /* Helpers for append! */ -inline void appendB_clear_last_pairs(klisp_State *K, TValue ls) +static inline void appendB_clear_last_pairs(klisp_State *K, TValue ls) { UNUSED(K); while(ttispair(ls) && kis_marked(ls)) { diff --git a/src/kinteger.h b/src/kinteger.h @@ -16,13 +16,13 @@ #include "imath.h" /* Check to see if an int64_t fits in a int32_t */ -inline bool kfit_int32_t(int64_t n) { +static inline bool kfit_int32_t(int64_t n) { return (n >= (int64_t) INT32_MIN && n <= (int64_t) INT32_MAX); } /* This tries to convert a bigint to a fixint */ /* XXX this doesn't need K really */ -inline TValue kbigint_try_fixint(klisp_State *K, TValue n) +static inline TValue kbigint_try_fixint(klisp_State *K, TValue n) { UNUSED(K); Bigint *b = tv2bigint(n); diff --git a/src/klimits.h b/src/klimits.h @@ -14,11 +14,10 @@ #include <limits.h> #include <stddef.h> -/* this should be done outside of here, but for now */ +#ifdef KUSE_ASSERTS #include <assert.h> -/* turn on assertions for internal checking */ #define klisp_assert(c) (assert(c)) - +#endif #include "klisp.h" /* internal assertions for in-house debugging */ @@ -28,7 +27,7 @@ #else -#define klisp_assert(c) ((void)0) +#define klisp_assert(c) ((void)(c)) #define check_exp(c,e) (e) #endif diff --git a/src/kpair.h b/src/kpair.h @@ -61,13 +61,13 @@ static inline TValue kcdr(TValue p) #define kcdddar(p_) (kcdr(kcdr(kcdr(kcar(p_))))) #define kcddddr(p_) (kcdr(kcdr(kcdr(kcdr(p_))))) -inline void kset_car(TValue p, TValue v) +static inline void kset_car(TValue p, TValue v) { klisp_assert(kmutable_pairp(p)); tv2pair(p)->car = v; } -inline void kset_cdr(TValue p, TValue v) +static inline void kset_cdr(TValue p, TValue v) { klisp_assert(kmutable_pairp(p)); tv2pair(p)->cdr = v; @@ -75,7 +75,7 @@ inline void kset_cdr(TValue p, TValue v) /* These two are the same but can write immutable pairs, use with care */ -inline void kset_car_unsafe(klisp_State *K, TValue p, TValue v) +static inline void kset_car_unsafe(klisp_State *K, TValue p, TValue v) { klisp_assert(kpairp(p)); UNUSED(K); @@ -83,7 +83,7 @@ inline void kset_car_unsafe(klisp_State *K, TValue p, TValue v) tv2pair(p)->car = v; } -inline void kset_cdr_unsafe(klisp_State *K, TValue p, TValue v) +static inline void kset_cdr_unsafe(klisp_State *K, TValue p, TValue v) { klisp_assert(kpairp(p)); UNUSED(K); diff --git a/src/kreal.c b/src/kreal.c @@ -392,11 +392,11 @@ int32_t simple_fixup(klisp_State *K, Bigint *f, Bigint *p, Bigint *r, bool dtoa(klisp_State *K, double d, char *buf, int32_t upoint, int32_t *out_h, int32_t *out_k) { - assert(sizeof(mp_small) == 4); + klisp_assert(sizeof(mp_small) == 4); mp_result res; Bigint e, p, f; - assert(d > 0.0); + klisp_assert(d > 0.0); /* convert d to three bigints m: significand, e: exponent & p: precision */ /* d = m^(e-p) & m < 2^p */ @@ -527,7 +527,7 @@ bool dtoa(klisp_State *K, double d, char *buf, int32_t upoint, int32_t *out_h, } else if (high) { ++digit; } else { - assert(0); + klisp_assert(0); } /* double check in case there was an increment */ klisp_assert(digit >= 0 && digit <= 9); diff --git a/src/kstate.h b/src/kstate.h @@ -200,14 +200,14 @@ struct klisp_State { void ks_sshrink(klisp_State *K, int32_t new_top); void ks_sgrow(klisp_State *K, int32_t new_top); -inline void ks_spush(klisp_State *K, TValue obj); -inline TValue ks_spop(klisp_State *K); +static inline void ks_spush(klisp_State *K, TValue obj); +static inline TValue ks_spop(klisp_State *K); /* this is for DISCARDING stack pop (value isn't used, avoid warning) */ #define ks_sdpop(st_) (UNUSED(ks_spop(st_))) -inline void ks_sdiscardn(klisp_State *K, int32_t n); -inline TValue ks_sget(klisp_State *K); -inline void ks_sclear(klisp_State *K); -inline bool ks_sisempty(klisp_State *K); +static inline void ks_sdiscardn(klisp_State *K, int32_t n); +static inline TValue ks_sget(klisp_State *K); +static inline void ks_sclear(klisp_State *K); +static inline bool ks_sisempty(klisp_State *K); /* some stack manipulation macros */ #define ks_ssize(st_) ((st_)->ssize) @@ -215,7 +215,7 @@ inline bool ks_sisempty(klisp_State *K); #define ks_sbuf(st_) ((st_)->sbuf) #define ks_selem(st_, i_) ((ks_sbuf(st_))[i_]) -inline void ks_spush(klisp_State *K, TValue obj) +static inline void ks_spush(klisp_State *K, TValue obj) { ks_selem(K, ks_stop(K)) = obj; ++ks_stop(K); @@ -227,7 +227,7 @@ inline void ks_spush(klisp_State *K, TValue obj) } -inline TValue ks_spop(klisp_State *K) +static inline TValue ks_spop(klisp_State *K) { if (ks_ssize(K) != KS_ISSIZE && ks_stop(K)-1 < (ks_ssize(K) / 4)) ks_sshrink(K, ks_stop(K)-1); @@ -236,12 +236,12 @@ inline TValue ks_spop(klisp_State *K) return obj; } -inline TValue ks_sget(klisp_State *K) +static inline TValue ks_sget(klisp_State *K) { return ks_selem(K, ks_stop(K) - 1); } -inline void ks_sdiscardn(klisp_State *K, int32_t n) +static inline void ks_sdiscardn(klisp_State *K, int32_t n) { int32_t new_top = ks_stop(K) - n; ks_stop(K) = new_top; @@ -250,14 +250,14 @@ inline void ks_sdiscardn(klisp_State *K, int32_t n) return; } -inline void ks_sclear(klisp_State *K) +static inline void ks_sclear(klisp_State *K) { if (ks_ssize(K) != KS_ISSIZE) ks_sshrink(K, 0); ks_stop(K) = 0; } -inline bool ks_sisempty(klisp_State *K) +static inline bool ks_sisempty(klisp_State *K) { return ks_stop(K) == 0; } @@ -268,16 +268,16 @@ inline bool ks_sisempty(klisp_State *K) void ks_tbshrink(klisp_State *K, int32_t new_top); void ks_tbgrow(klisp_State *K, int32_t new_top); -inline void ks_tbadd(klisp_State *K, char ch); +static inline void ks_tbadd(klisp_State *K, char ch); #define ks_tbpush(K_, ch_) (ks_tbadd((K_), (ch_))) -inline char ks_tbget(klisp_State *K); -inline char ks_tbpop(klisp_State *K); +static inline char ks_tbget(klisp_State *K); +static inline char ks_tbpop(klisp_State *K); /* this is for DISCARDING stack pop (value isn't used, avoid warning) */ #define ks_tbdpop(st_) (UNUSED(ks_tbpop(st_))) -inline char *ks_tbget_buffer(klisp_State *K); -inline void ks_tbclear(klisp_State *K); -inline bool ks_tbisempty(klisp_State *K); +static inline char *ks_tbget_buffer(klisp_State *K); +static inline void ks_tbclear(klisp_State *K); +static inline bool ks_tbisempty(klisp_State *K); /* some buf manipulation macros */ #define ks_tbsize(st_) ((st_)->ktok_buffer_size) @@ -285,7 +285,7 @@ inline bool ks_tbisempty(klisp_State *K); #define ks_tbuf(st_) ((st_)->ktok_buffer) #define ks_tbelem(st_, i_) ((ks_tbuf(st_))[i_]) -inline void ks_tbadd(klisp_State *K, char ch) +static inline void ks_tbadd(klisp_State *K, char ch) { if (ks_tbidx(K) == ks_tbsize(K)) ks_tbgrow(K, ks_tbidx(K)+1); @@ -293,12 +293,12 @@ inline void ks_tbadd(klisp_State *K, char ch) ++ks_tbidx(K); } -inline char ks_tbget(klisp_State *K) +static inline char ks_tbget(klisp_State *K) { return ks_tbelem(K, ks_tbidx(K) - 1); } -inline char ks_tbpop(klisp_State *K) +static inline char ks_tbpop(klisp_State *K) { if (ks_tbsize(K) != KS_ITBSIZE && ks_tbidx(K)-1 < (ks_tbsize(K) / 4)) ks_tbshrink(K, ks_tbidx(K)-1); @@ -307,20 +307,20 @@ inline char ks_tbpop(klisp_State *K) return ch; } -inline char *ks_tbget_buffer(klisp_State *K) +static inline char *ks_tbget_buffer(klisp_State *K) { klisp_assert(ks_tbelem(K, ks_tbidx(K) - 1) == '\0'); return ks_tbuf(K); } -inline void ks_tbclear(klisp_State *K) +static inline void ks_tbclear(klisp_State *K) { if (ks_tbsize(K) != KS_ITBSIZE) ks_tbshrink(K, 0); ks_tbidx(K) = 0; } -inline bool ks_tbisempty(klisp_State *K) +static inline bool ks_tbisempty(klisp_State *K) { return ks_tbidx(K) == 0; } @@ -335,34 +335,34 @@ static inline void krooted_tvs_push(klisp_State *K, TValue tv) K->rooted_tvs_buf[K->rooted_tvs_top++] = tv; } -inline void krooted_tvs_pop(klisp_State *K) +static inline void krooted_tvs_pop(klisp_State *K) { klisp_assert(K->rooted_tvs_top > 0); --(K->rooted_tvs_top); } -inline void krooted_tvs_clear(klisp_State *K) { K->rooted_tvs_top = 0; } +static inline void krooted_tvs_clear(klisp_State *K) { K->rooted_tvs_top = 0; } -inline void krooted_vars_push(klisp_State *K, TValue *v) +static inline void krooted_vars_push(klisp_State *K, TValue *v) { klisp_assert(K->rooted_vars_top < GC_PROTECT_SIZE); K->rooted_vars_buf[K->rooted_vars_top++] = v; } -inline void krooted_vars_pop(klisp_State *K) +static inline void krooted_vars_pop(klisp_State *K) { klisp_assert(K->rooted_vars_top > 0); --(K->rooted_vars_top); } -inline void krooted_vars_clear(klisp_State *K) { K->rooted_vars_top = 0; } +static inline void krooted_vars_clear(klisp_State *K) { K->rooted_vars_top = 0; } /* ** Source code tracking ** MAYBE: add source code tracking to symbols */ #if KTRACK_SI -inline TValue kget_source_info(klisp_State *K, TValue obj) +static inline TValue kget_source_info(klisp_State *K, TValue obj) { UNUSED(K); klisp_assert(khas_si(obj)); @@ -371,7 +371,7 @@ inline TValue kget_source_info(klisp_State *K, TValue obj) return gc2pair(si); } -inline void kset_source_info(klisp_State *K, TValue obj, TValue si) +static inline void kset_source_info(klisp_State *K, TValue obj, TValue si) { UNUSED(K); klisp_assert(kcan_have_si(obj)); @@ -385,13 +385,13 @@ inline void kset_source_info(klisp_State *K, TValue obj, TValue si) } } -inline TValue ktry_get_si(klisp_State *K, TValue obj) +static inline TValue ktry_get_si(klisp_State *K, TValue obj) { UNUSED(K); return (khas_si(obj))? gc2pair(gcvalue(obj)->gch.si) : KNIL; } -inline TValue kget_csi(klisp_State *K) +static inline TValue kget_csi(klisp_State *K) { return K->next_si; } @@ -401,7 +401,7 @@ inline TValue kget_csi(klisp_State *K) ** Functions to manipulate the current continuation and calling ** operatives */ -inline void klispS_apply_cc(klisp_State *K, TValue val) +static inline void klispS_apply_cc(klisp_State *K, TValue val) { /* TODO write barriers */ @@ -423,21 +423,21 @@ inline void klispS_apply_cc(klisp_State *K, TValue val) #define kapply_cc(K_, val_) klispS_apply_cc((K_), (val_)); return -inline TValue klispS_get_cc(klisp_State *K) +static inline TValue klispS_get_cc(klisp_State *K) { return K->curr_cont; } #define kget_cc(K_) (klispS_get_cc(K_)) -inline void klispS_set_cc(klisp_State *K, TValue new_cont) +static inline void klispS_set_cc(klisp_State *K, TValue new_cont) { K->curr_cont = new_cont; } #define kset_cc(K_, c_) (klispS_set_cc(K_, c_)) -inline void klispS_tail_call_si(klisp_State *K, TValue top, TValue ptree, +static inline void klispS_tail_call_si(klisp_State *K, TValue top, TValue ptree, TValue env, TValue si) { /* TODO write barriers */ diff --git a/src/ktable.c b/src/ktable.c @@ -73,7 +73,7 @@ static const Node dummynode_ = { /* ** hash for klisp numbers */ -inline static Node *hashfixint (const Table *t, int32_t n) { +static inline Node *hashfixint (const Table *t, int32_t n) { return hashmod(t, (uint32_t) n); } diff --git a/src/ktoken.h b/src/ktoken.h @@ -29,8 +29,8 @@ void clear_shared_dict(klisp_State *K); /* These are used in peek-char, peek-u8, read-char & read-u8 */ int ktok_peekc_getc(klisp_State *K, bool peekp); -inline int ktok_getc(klisp_State *K) { return ktok_peekc_getc(K, false); } -inline int ktok_peekc(klisp_State *K) { return ktok_peekc_getc(K, true); } +static inline int ktok_getc(klisp_State *K) { return ktok_peekc_getc(K, false); } +static inline int ktok_peekc(klisp_State *K) { return ktok_peekc_getc(K, true); } /* needed by the repl */ void ktok_ignore_whitespace(klisp_State *K); @@ -65,14 +65,14 @@ extern kcharset ktok_subsequent, ktok_initial; kch_[KCHS_OCTANT(ch__)] & KCHS_BIT(ch__); }) -inline bool ktok_is_digit(char ch, int32_t radix) +static inline bool ktok_is_digit(char ch, int32_t radix) { ch = tolower(ch); return (ktok_is_numeric(ch) && (ch - '0') < radix) || (ktok_is_alphabetic(ch) && (10 + (ch - 'a')) < radix); } -inline int32_t ktok_digit_value(char ch) +static inline int32_t ktok_digit_value(char ch) { ch = tolower(ch); return (ch <= '9')? ch - '0' : 10 + (ch - 'a');