summaryrefslogtreecommitdiffstats
path: root/stream.c
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 /stream.c
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 'stream.c')
-rw-r--r--stream.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/stream.c b/stream.c
index ed423dd8..1efc58b6 100644
--- a/stream.c
+++ b/stream.c
@@ -50,11 +50,11 @@
#if HAVE_WINDOWS_H
#include <windows.h>
#endif
+#include ALLOCA_H
#include "lib.h"
#include "gc.h"
#include "signal.h"
#include "unwind.h"
-#include ALLOCA_H
#include "args.h"
#include "stream.h"
#include "utf8.h"
@@ -1863,6 +1863,11 @@ val make_catenated_stream(val stream_list)
return cobj(coerce(mem_t *, s), stream_s, &cat_stream_ops.cobj_ops);
}
+val make_catenated_stream_v(struct args *streams)
+{
+ return make_catenated_stream(args_get_list(streams));
+}
+
val catenated_stream_p(val obj)
{
return if2(streamp(obj), c_true(obj->co.ops == &cat_stream_ops.cobj_ops));
@@ -2135,8 +2140,12 @@ static void vformat_str(val stream, val str, int width, enum align align,
rel1(&str);
}
-static val aformat(val stream, val fmtstr, struct args *al)
+val formatv(val stream_in, val fmtstr, struct args *al)
{
+ uses_or2;
+ val stream = if3(stream_in == t,
+ std_output,
+ or2(stream_in, make_string_output_stream()));
val save_indent = get_indent(stream);
val save_mode = nil;
val name = lit("format");
@@ -2503,7 +2512,7 @@ static val aformat(val stream, val fmtstr, struct args *al)
uw_catch_end;
- return t;
+ return (stream_in) ? t : get_string_from_stream(stream);
}
val vformat(val stream, val fmtstr, va_list vl)
@@ -2515,7 +2524,7 @@ val vformat(val stream, val fmtstr, va_list vl)
while ((arg = va_arg(vl, val)) != nao)
args_add_checked(lit("format"), args, arg);
- return aformat(stream, fmtstr, args);
+ return formatv(stream, fmtstr, args);
}
val vformat_to_string(val fmtstr, va_list vl)
@@ -2543,27 +2552,6 @@ val format(val stream, val str, ...)
}
}
-val formatv(val stream, val string, val arglist)
-{
- uses_or2;
- val st = if3(stream == t,
- std_output,
- or2(stream, make_string_output_stream()));
- cnum argc = args_limit(lit("format"), c_num(length_list(arglist)));
- struct args *args = args_alloc(argc);
- val ret;
-
- class_check(st, stream_s);
- args_init(args, argc);
-
- for (; arglist; arglist = cdr(arglist))
- args_add(args, car(arglist));
-
- ret = aformat(st, string, args);
-
- return (stream) ? ret : get_string_from_stream(st);
-}
-
static val put_indent(val stream, struct strm_ops *ops, cnum chars)
{
while (chars--)
@@ -3293,7 +3281,7 @@ void stream_init(void)
reg_fun(intern(lit("stream-set-prop"), user_package), func_n3(stream_set_prop));
reg_fun(intern(lit("stream-get-prop"), user_package), func_n2(stream_get_prop));
reg_fun(intern(lit("fileno"), user_package), curry_12_1(func_n2(stream_get_prop), fd_k));
- reg_fun(intern(lit("make-catenated-stream"), user_package), func_n0v(make_catenated_stream));
+ reg_fun(intern(lit("make-catenated-stream"), user_package), func_n0v(make_catenated_stream_v));
reg_fun(intern(lit("cat-streams"), user_package), func_n1(make_catenated_stream));
reg_fun(intern(lit("catenated-stream-p"), user_package), func_n1(catenated_stream_p));
reg_fun(intern(lit("catenated-stream-push"), user_package), func_n2(catenated_stream_push));