summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-08-23 09:50:39 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-08-23 09:50:39 -0700
commit6d0af6ae2af0003716581ed23b486f26ac809e0c (patch)
treed7b87cfcbb89f31ba2bcd8ad99e524244d18443d /lib.h
parent115b8bc97f8d0d2ec8ed3cde46d8b567ea437e81 (diff)
downloadtxr-6d0af6ae2af0003716581ed23b486f26ac809e0c.tar.gz
txr-6d0af6ae2af0003716581ed23b486f26ac809e0c.tar.bz2
txr-6d0af6ae2af0003716581ed23b486f26ac809e0c.zip
Large scale conversion to new way of handling arguments.
Function arguments are now allocated on the stack using alloca, in conjunction with the struct alloc header structure. The generic_funcall and apply functions are refactored for this, as are most functions that take variadic arguments. * args.c (args_add_list, args_cons_list): Functions removed. (args_normalize, args_normalize_fill): New functions. (args_get_checked): Draw arguments from list when array runs out. (args_copy, args_copy_zap): New functions. * args.h (ARGS_MAX): Reduced to 32. (ARGS_MIN): New preprocessor symbol. (args_init): Call args_init_list. (args_add2, args_add3, args_add4): New inline functions. (args_more): Take into account list, which may hold additional arguments. (args_two_more): New inline function. (args_normalize, args_normalize_fill): Declared. (args_get_list): Normalize all arguments into one list and return it. (args_get_rest, args_at, args_atz): New inline functions. (args_get): Draw arguments from list when array runs out. (args_clear): New inline function. * arith.c (maskv): Convert to new args. * eval.c (APPLY_ARGS): Preprocessor symbol removed. (bind_args): Converted to accept struct args. (apply): Function reduced down to trivial adapter which converts a list of arguments to args, and calls the new generic_funcall. (applyv): New static function: struct args wrapper around apply_intrinsic. (iapply): Converted to struct args. (call): Static function removed. The call intrinsic function binding now goes directly to generic_funcall. (list_star_intrinsic, interp_fun): Converted to struct args. (op_catch): Adjustments for bind_args, which requires a struct args arglist. (me_op): Must use the new minl and maxl, since minv and maxv don't take lists any more. (mapcarv, mappendv, lazy_mapcarv, lazy_mappendv, mapdov, weavev, or_fun, and_fun, tf, nilf, do_retf, do_apf, do_ipf, callf, do_mapf, mapf): Converted. (mapcarl): New function, like the old mapcarv. (eval_init): call_f initialized from generic_funcall rather than call. apply registered to applyv rather than apply_intrinsic. Registrations for zip, hash_from_pairs, vec, alist-remove, alist-nremove, and throw similarly updated to new or renamed functions. * eval.h (interp_fun, mapcarv): Declarations updated. (mapcarl): Declard. * hash.c (hashv): Converted to struct args. (hashl): New function. (hash_construct): Use hashl, not hashv. (hash_from_pairs, hash_list, group_by): Converted. * hash.h (hashv, hash_construct, hash_from_pairs, hash_list, group_by): Declarations updated. (hashl): Declared. * lib.c (appendv, nconcv, lazy_appendv): Converted to struct args. (lazy_appendl): New function. (multi): Converted. (listv): New function. (nary_op, plusv, mulv, logandv, logiorv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv): Converted. (maxl, minl): New functions, like old maxv and minv. (exptv, gcdv, lcmv, lessv, greaterv, lequalv, gequalv): Converted. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n1ov, func_n2ov, func_n3ov): Converted. (generic_funcall): Converted to take struct args. (funcall, funcall1, funcall2, funcall4): Pass stack-allocated struct args as trailing arguments to variadic functions, and to generic_funcall. (do_curry_12_1_v): New struct-args-based static function, needed to implement curry_12_1_v now. (curry_12_1_v): Converted. (transposev): New function based on previous tranpose. (transpose): Now a wrapper for transposev. (do_chain, chainv, do_chand, chandv, do_juxt, juxtv, do_and, andv, do_or, orv, do_not, do_iff): Converted. (vectorv): New function. Implementation basis for vec intrinsic function. (alist_removev, alist_nremovev): New functions. (multi_sort): Switch from mapcarv to mapcarl. (unique): Converted. (uniq): Allocate struct args for calling unique. (obj_init): list_f function now based on new listv, rather than identity. * list.h (varg): New typedef. (struct func): All variadic function pointers converted to use struct args. (appendv, nconcv, lazy_appendv, multi, nary_op, plusv, minusv, mulv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv, exptv, gcdv, lcmv, logadnv, logiorv, maskv, lessv, greaterv, lequalv, gequalv, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n1ov, func_n2ov, func_n3ov, generic_funcall, chainv, chandv, juxtv, adnv, orv, unique): Declarations updated. (lazy_appendl, listv, maxl, minl, transposev, vectorv, alist_removev, alist_nremovev): Declared. * stream.c (make_catenated_stream_v): New function. (aformat): Renamed to formatv. The recognition of the nil and t streams (standard output and string) is done here now. (vformat): Follow rename of aformat to formatv. (formatv): Function removed. Nobody calls this anymore. (stream_init): make-catenated-stream re-registered to new make_catenated_stream_v function. * stream.h (formatv): Declaration updated. (make_catenated_v): Declared. * syslog.c (syslog_init): syslog registred to syslog_wrapv. (syslog_wrapv): New function based on syslog_wrap converted to struct args. (syslog_wrap): Now wrapper for syslog_wrapv. * syslog.h (syslog_wrapv): Declared. * unwind.h (uw_throwv): New function. (uw_throwfv, uw_errorfv): Converted to struct args. * unwind.h (uw_throwv): Declared. (uw_throwfv, uw_errorfv): Declarations updated.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h134
1 files changed, 72 insertions, 62 deletions
diff --git a/lib.h b/lib.h
index 646038a3..bcd92954 100644
--- a/lib.h
+++ b/lib.h
@@ -111,6 +111,8 @@ struct package {
val symhash;
};
+typedef struct args *varg;
+
struct func {
obj_common;
unsigned fixparam : 7; /* total non-variadic parameters */
@@ -134,19 +136,19 @@ struct func {
val (*n5)(val, val, val, val, val);
val (*n6)(val, val, val, val, val, val);
val (*n7)(val, val, val, val, val, val, val);
- val (*f0v)(val, val);
- val (*f1v)(val, val, val);
- val (*f2v)(val, val, val, val);
- val (*f3v)(val, val, val, val, val);
- val (*f4v)(val, val, val, val, val, val);
- val (*n0v)(val);
- val (*n1v)(val, val);
- val (*n2v)(val, val, val);
- val (*n3v)(val, val, val, val);
- val (*n4v)(val, val, val, val, val);
- val (*n5v)(val, val, val, val, val, val);
- val (*n6v)(val, val, val, val, val, val, val);
- val (*n7v)(val, val, val, val, val, val, val, val);
+ val (*f0v)(val, varg);
+ val (*f1v)(val, val, varg);
+ val (*f2v)(val, val, val, varg);
+ val (*f3v)(val, val, val, val, varg);
+ val (*f4v)(val, val, val, val, val, varg);
+ val (*n0v)(varg);
+ val (*n1v)(val, varg);
+ val (*n2v)(val, val, varg);
+ val (*n3v)(val, val, val, varg);
+ val (*n4v)(val, val, val, val, varg);
+ val (*n5v)(val, val, val, val, val, varg);
+ val (*n6v)(val, val, val, val, val, val, varg);
+ val (*n7v)(val, val, val, val, val, val, val, varg);
} f;
};
@@ -472,11 +474,12 @@ val nreverse(val in);
val reverse(val in);
val append2(val list1, val list2);
val nappend2(val list1, val list2);
-val appendv(val lists);
-val nconcv(val lists);
+val appendv(struct args *lists);
+val nconcv(struct args *lists);
val sub_list(val list, val from, val to);
val replace_list(val list, val items, val from, val to);
-val lazy_appendv(val lists);
+val lazy_appendl(val lists);
+val lazy_appendv(struct args *lists);
val ldiff(val list1, val list2);
val flatten(val list);
val lazy_flatten(val list);
@@ -508,7 +511,7 @@ val count_if(val pred, val list, val key);
val some_satisfy(val list, val pred, val key);
val all_satisfy(val list, val pred, val key);
val none_satisfy(val list, val pred, val key);
-val multi(val func, val lists);
+val multi(val func, struct args *lists);
val eql(val left, val right);
val equal(val left, val right);
mem_t *chk_malloc(size_t size);
@@ -523,6 +526,7 @@ val make_lazy_cons(val func);
val make_half_lazy_cons(val func, val car);
val lcons_fun(val lcons);
val list(val first, ...); /* terminated by nao */
+val listv(struct args *);
val consp(val obj);
val lconsp(val obj);
val atom(val obj);
@@ -542,15 +546,15 @@ val bignump(val num);
val floatp(val num);
val integerp(val num);
val numberp(val num);
-val nary_op(val (*cfunc)(val, val), val args, val emptyval);
+val nary_op(val (*cfunc)(val, val), struct args *args, val emptyval);
val plus(val anum, val bnum);
-val plusv(val nlist);
+val plusv(struct args *);
val minus(val anum, val bnum);
-val minusv(val minuend, val nlist);
+val minusv(val minuend, struct args *nlist);
val neg(val num);
val abso(val num);
val mul(val anum, val bnum);
-val mulv(val nlist);
+val mulv(struct args *);
val trunc(val anum, val bnum);
val mod(val anum, val bnum);
val trunc_rem(val anum, val bnum);
@@ -573,26 +577,28 @@ val lt(val anum, val bnum);
val ge(val anum, val bnum);
val le(val anum, val bnum);
val numeq(val anum, val bnum);
-val gtv(val first, val rest);
-val ltv(val first, val rest);
-val gev(val first, val rest);
-val lev(val first, val rest);
-val numeqv(val first, val rest);
-val numneqv(val list);
+val gtv(val first, struct args *rest);
+val ltv(val first, struct args *rest);
+val gev(val first, struct args *rest);
+val lev(val first, struct args *rest);
+val numeqv(val first, struct args *rest);
+val numneqv(struct args *list);
val max2(val a, val b);
val min2(val a, val b);
-val maxv(val first, val rest);
-val minv(val first, val rest);
+val maxv(val first, struct args *rest);
+val minv(val first, struct args *rest);
+val maxl(val first, val rest);
+val minl(val first, val rest);
val clamp(val low, val high, val num);
val expt(val base, val exp);
-val exptv(val nlist);
+val exptv(struct args *nlist);
val exptmod(val base, val exp, val mod);
val sqroot(val anum);
val isqrt(val anum);
val gcd(val anum, val bnum);
-val gcdv(val nlist);
+val gcdv(struct args *nlist);
val lcm(val anum, val bnum);
-val lcmv(val nlist);
+val lcmv(struct args *nlist);
val floorf(val);
val ceili(val);
val sine(val);
@@ -608,8 +614,8 @@ val logtwo(val num);
val expo(val);
val logand(val, val);
val logior(val, val);
-val logandv(val nlist);
-val logiorv(val nlist);
+val logandv(struct args *nlist);
+val logiorv(struct args *nlist);
val logxor(val, val);
val logtest(val, val);
val lognot(val, val);
@@ -617,7 +623,7 @@ val logtrunc(val a, val bits);
val sign_extend(val num, val nbits);
val ash(val a, val bits);
val bit(val a, val bit);
-val maskv(val bits);
+val maskv(struct args *bits);
val string_own(wchar_t *str);
val string(const wchar_t *str);
val string_utf8(const char *str);
@@ -660,10 +666,10 @@ val less(val left, val right);
val greater(val left, val right);
val lequal(val left, val right);
val gequal(val left, val right);
-val lessv(val first, val rest);
-val greaterv(val first, val rest);
-val lequalv(val first, val rest);
-val gequalv(val first, val rest);
+val lessv(val first, struct args *rest);
+val greaterv(val first, struct args *rest);
+val lequalv(val first, struct args *rest);
+val gequalv(val first, struct args *rest);
val chrp(val chr);
wchar_t c_chr(val chr);
val chr_isalnum(val ch);
@@ -717,33 +723,33 @@ val func_n4(val (*fun)(val, val, val, val));
val func_n5(val (*fun)(val, val, val, val, val));
val func_n6(val (*fun)(val, val, val, val, val, val));
val func_n7(val (*fun)(val, val, val, val, val, val, val));
-val func_f0v(val, val (*fun)(val env, val rest));
-val func_f1v(val, val (*fun)(val env, val, val rest));
-val func_f2v(val, val (*fun)(val env, val, val, val rest));
-val func_f3v(val, val (*fun)(val env, val, val, val, val rest));
-val func_f4v(val, val (*fun)(val env, val, val, val, val, val rest));
-val func_n0v(val (*fun)(val rest));
-val func_n1v(val (*fun)(val, val rest));
-val func_n2v(val (*fun)(val, val, val rest));
-val func_n3v(val (*fun)(val, val, val, val rest));
-val func_n4v(val (*fun)(val, val, val, val, val rest));
-val func_n5v(val (*fun)(val, val, val, val, val, val rest));
-val func_n6v(val (*fun)(val, val, val, val, val, val, val rest));
-val func_n7v(val (*fun)(val, val, val, val, val, val, val, val rest));
+val func_f0v(val, val (*fun)(val env, varg));
+val func_f1v(val, val (*fun)(val env, val, varg));
+val func_f2v(val, val (*fun)(val env, val, val, varg));
+val func_f3v(val, val (*fun)(val env, val, val, val, varg));
+val func_f4v(val, val (*fun)(val env, val, val, val, val, varg));
+val func_n0v(val (*fun)(varg));
+val func_n1v(val (*fun)(val, varg));
+val func_n2v(val (*fun)(val, val, varg));
+val func_n3v(val (*fun)(val, val, val, varg));
+val func_n4v(val (*fun)(val, val, val, val, varg));
+val func_n5v(val (*fun)(val, val, val, val, val, varg));
+val func_n6v(val (*fun)(val, val, val, val, val, val, varg));
+val func_n7v(val (*fun)(val, val, val, val, val, val, val, varg));
val func_n1o(val (*fun)(val), int reqargs);
val func_n2o(val (*fun)(val, val), int reqargs);
val func_n3o(val (*fun)(val, val, val), int reqargs);
val func_n4o(val (*fun)(val, val, val, val), int reqargs);
-val func_n1ov(val (*fun)(val, val rest), int reqargs);
-val func_n2ov(val (*fun)(val, val, val rest), int reqargs);
-val func_n3ov(val (*fun)(val, val, val, val rest), int reqargs);
+val func_n1ov(val (*fun)(val, varg), int reqargs);
+val func_n2ov(val (*fun)(val, val, varg), int reqargs);
+val func_n3ov(val (*fun)(val, val, val, varg), int reqargs);
val func_interp(val env, val form);
val func_get_form(val fun);
val func_get_env(val fun);
val func_set_env(val fun, val env);
val functionp(val);
val interp_fun_p(val);
-val generic_funcall(val fun, val arg[], int nargs);
+val generic_funcall(val fun, struct args *);
val funcall(val fun);
val funcall1(val fun, val arg);
val funcall2(val fun, val arg1, val arg2);
@@ -751,6 +757,7 @@ val funcall3(val fun, val arg1, val arg2, val arg3);
val funcall4(val fun, val arg1, val arg2, val arg3, val arg4);
val reduce_left(val fun, val list, val init, val key);
val reduce_right(val fun, val list, val init, val key);
+val transposev(struct args *lists);
val transpose(val lists);
/* The notation curry_12_2 means take some function f(arg1, arg2) and
fix a value for argument 1 to create a g(arg2).
@@ -763,13 +770,13 @@ val curry_123_1(val fun3, val arg2, val arg3);
val curry_123_23(val fun3, val arg1);
val curry_1234_34(val fun3, val arg1, val arg2);
val chain(val first_fun, ...);
-val chainv(val funlist);
-val chandv(val funlist);
-val juxtv(val funlist);
+val chainv(struct args *funlist);
+val chandv(struct args *funlist);
+val juxtv(struct args *funlist);
val andf(val first_fun, ...);
-val andv(val funlist);
+val andv(struct args *funlist);
val orf(val first_fun, ...);
-val orv(val funlist);
+val orv(struct args *funlist);
val notf(val fun);
val iff(val condfun, val thenfun, val elsefun);
val iffi(val condfun, val thenfun, val elsefun);
@@ -783,6 +790,7 @@ loc vecref_l(val vec, val ind);
val vec_push(val vec, val item);
val length_vec(val vec);
val size_vec(val vec);
+val vectorv(struct args *);
val vector_list(val list);
val list_vector(val vector);
val copy_vec(val vec);
@@ -812,8 +820,10 @@ val acons_new_c(val key, loc new_p, loc list);
val aconsql_new(val key, val value, val list);
val aconsql_new_c(val key, loc new_p, loc list);
val alist_remove(val list, val keys);
+val alist_removev(val list, struct args *keys);
val alist_remove1(val list, val key);
val alist_nremove(val list, val keys);
+val alist_nremovev(val list, struct args *keys);
val alist_nremove1(val list, val key);
val copy_cons(val cons);
val copy_alist(val list);
@@ -827,7 +837,7 @@ val merge(val list1, val list2, val lessfun, val keyfun);
val sort(val seq, val lessfun, val keyfun);
val multi_sort(val lists, val funcs, val key_funcs);
val sort_group(val seq, val keyfun, val lessfun);
-val unique(val seq, val keyfun, val hashargs);
+val unique(val seq, val keyfun, struct args *hashv_args);
val uniq(val seq);
val find(val list, val key, val testfun, val keyfun);
val find_if(val pred, val list, val key);