tisp

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

commit cf5e98818f37f0bdafd10881d5538d80b8cd9ac7
parent 340fa4b70555fe29c3d0db26bdf58c2021cd7d79
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sun, 18 Oct 2020 00:16:16 -0700

Add max argument C macro for built-ins

Diffstat:
tib/io.c | 3+--
tisp.h | 5+++++
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tib/io.c b/tib/io.c @@ -64,8 +64,7 @@ static Val prim_read(Tsp st, Hash env, Val args) { char *file, *fname = NULL; /* read from stdin by default */ - if (list_len(args) > 1) - tsp_warnf("read: expected 0 or 1 argument, received %d", list_len(args)); + tsp_arg_max(args, "read", 1); if (list_len(args) == 1) { /* if file name given as string, read it */ tsp_arg_type(car(args), "read", TSP_STR); fname = car(args)->v.s; diff --git a/tisp.h b/tisp.h @@ -34,6 +34,11 @@ tsp_warnf("%s: expected at least %d argument%s, received %d", \ NAME, NARGS, NARGS > 1 ? "s" : "", list_len(ARGS)); \ } while(0) +#define tsp_arg_max(ARGS, NAME, NARGS) do { \ + if (list_len(ARGS) > NARGS) \ + tsp_warnf("%s: expected at no more than %d argument%s, received %d", \ + NAME, NARGS, NARGS > 1 ? "s" : "", list_len(ARGS)); \ +} while(0) #define tsp_arg_num(ARGS, NAME, NARGS) do { \ if (list_len(ARGS) != NARGS && NARGS != -1) \ tsp_warnf("%s: expected %d argument%s, received %d", \