tisp

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

commit 9878403b3312eb42f9a18b9cd15fb9badc49a410
parent 6a01925d467be41b6dbebc68dfd022b0955a7801
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 12 Oct 2019 19:02:32 -0700

Error primitive to print message and return error

Diffstat:
tisp.c | 20++++++++++++++++++++
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -1007,6 +1007,25 @@ prim_load(Env env, Val args) return env->none; } +/* display error message */ +static Val +prim_error(Env env, Val args) +{ + Val v; + if (!(v = tisp_eval_list(env, args))) + return NULL; + tsp_arg_min(v, "error", 2); + tsp_arg_type(car(v), "error", SYMBOL); + fprintf(stderr, "tisp: error: %s: ", car(v)->v.s); + for (v = cdr(v); !nilp(v); v = cdr(v)) + if (car(v)->t & STRING) /* don't print quotes around string */ + fprintf(stderr, "%s", car(v)->v.s); + else + tisp_print(stderr, car(v)); + fputc('\n', stderr); + return NULL; +} + /* list tisp version */ static Val prim_version(Env env, Val args) @@ -1053,6 +1072,7 @@ tisp_env_init(size_t cap) tsp_env_fn(macro); tsp_env_fn(define); tsp_env_fn(load); + tsp_env_fn(error); tsp_env_fn(version); env->strs = hash_new(cap, NULL);