tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 16c8d8df6b746c5fde58b273e9974d4502b74ec3
parent 589c5ffb82bca3d678abf5a6fee746db063b3411
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 20 Jun 2019 21:12:52 -0700

Print error file and line number in debug mode

Diffstat:
tisp.c | 2+-
tisp.h | 33++++++++++++++++++++++-----------
2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -795,7 +795,7 @@ tisp_print(FILE *f, Val v) putc(')', f); break; default: - fprintf(stderr, "tisp: could not print value type %s", type_str(v->t)); + fprintf(stderr, "tisp: could not print value type %s\n", type_str(v->t)); } } diff --git a/tisp.h b/tisp.h @@ -19,24 +19,35 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#define tsp_warnf(M, ...) do { \ - fprintf(stderr, "tisp:%d: error: " M "\n", \ - __LINE__, ##__VA_ARGS__); \ - return NULL; \ +#ifdef DEBUG +# define tsp_warnf(M, ...) do { \ + fprintf(stderr, "tisp:%s:%d: error: " M "\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ + return NULL; \ } while(0) -#define tsp_warn(M) do { \ - fprintf(stderr, "tisp:%d: error: " M "\n", \ - __LINE__); \ - return NULL; \ +# define tsp_warn(M) do { \ + fprintf(stderr, "tisp:%s:%d: error: " M "\n", __FILE__, __LINE__); \ + return NULL; \ } while(0) +#else +# define tsp_warnf(M, ...) do { \ + fprintf(stderr, "tisp: error: " M "\n", ##__VA_ARGS__); \ + return NULL; \ +} while(0) +# define tsp_warn(M) do { \ + fprintf(stderr, "tisp: error: " M "\n"); \ + return NULL; \ +} while(0) +#endif #define tsp_arg_num(ARGS, NAME, NARGS) do { \ if (list_len(ARGS) != NARGS && NARGS != -1) \ tsp_warnf("%s: expected %d argument%s, received %d", \ NAME, NARGS, NARGS > 1 ? "s" : "", list_len(ARGS)); \ } while(0) -#define tsp_arg_type(ARG, NAME, TYPE) do { \ - if (!(ARG->t & (TYPE))) \ - tsp_warnf(NAME ": expected %s, received %s", type_str(TYPE), type_str(ARG->t)); \ +#define tsp_arg_type(ARG, NAME, TYPE) do { \ + if (!(ARG->t & (TYPE))) \ + tsp_warnf(NAME ": expected %s, received %s", \ + type_str(TYPE), type_str(ARG->t)); \ } while(0) #define tsp_env_name_fn(NAME, FN) tisp_env_add(env, #NAME, mk_prim(prim_##FN))