From 8d78717508e7f49a9af456197369d74352122b91 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 24 Aug 2015 22:06:13 -0700 Subject: Replace two-step initialization of args with macros. * args.h (args_init_list, args_init): Return the struct args * pointer. (args_decl_list, args_decl): New macros. * eval.c (apply, do_eval, expand_macro, op_dwim, op_catch, (mapcarl, lazy_mapcarl): Switch to new macros. * hash.c (hashl): Likewise. * lib.c (generic_funcall, lazy_appendl, maxl, minl, funcall, funcal1, funcall2, funcall3, funcall4, transpose, juxtv, do_and, do_or, do_iff, unique): Likewise. * match.c (h_fun, v_fun): Likewise. * stream.c (vformat): Likewise. * syslog.c (syslog_wrap): Likewise. --- args.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'args.h') diff --git a/args.h b/args.h index a9174699..efd49d61 100644 --- a/args.h +++ b/args.h @@ -40,18 +40,29 @@ typedef int arg_index; (coerce(struct args *, \ alloca(offsetof(struct args, arg) + (N)*sizeof (val)))) -INLINE void args_init_list(struct args *args, cnum argc, val list) +INLINE struct args *args_init_list(struct args *args, cnum argc, val list) { args->argc = argc; args->fill = 0; args->list = list; + return args; } -INLINE void args_init(struct args *args, cnum argc) +INLINE struct args *args_init(struct args *args, cnum argc) { - args_init_list(args, argc, nil); + return args_init_list(args, argc, nil); } +#define args_decl_list(NAME, N, L) \ + mem_t *NAME ## _mem = \ + coerce(mem_t *, \ + alloca(offsetof(struct args, arg) + (N)*sizeof (val))); \ + struct args *NAME = args_init_list(coerce(struct args *, \ + NAME ## _mem), N, L) + +#define args_decl(NAME, N) args_decl_list(NAME, N, nil) + + INLINE val args_add(struct args *args, val arg) { return args->arg[args->fill++] = arg; -- cgit v1.2.3