diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-02-21 18:13:52 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-02-21 18:13:52 -0800 |
commit | 72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a (patch) | |
tree | 2232b5a5374c92d566f087f2bc5e5067a5fb8fd4 /stream.c | |
parent | 216c446da541d2a2e68c57feee04bafce00013e5 (diff) | |
download | txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.gz txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.bz2 txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.zip |
Introducing optional arguments.
* debug.c (help, show_bindings): put_string arguments reversed.
* eval.c (bind_args): Support colon notation in interpreted
function lambda lists for optional arguments. Improved error checking.
(apply): Allow optional arguments to be left out.
(dwim_loc): Reversed arguments to replace_str, replace_vec,
replace_list.
(eval_init): Numerous intrinsics now have arguments that are optional.
New function rand introduced which reverses arguments relative to
random. New intrinsic function hash introduced for alternative
construction of hashes.
* gc.c (sweep): Reversed arguments to put_char.
* hash.c (weak_keys_k, weak_vals_k, equal_based_k): New keyword
symbol variables.
(hashv): New function.
(hash_init): Intern new symbols.
* hash.h (weak_keys_k, weak_vals_k, equal_based_k, hashv): Declared.
* lib.c (colon_k): New keyword symbol variable.
(replace_list, replace_str, replace_vec): Arguments rearranged.
(tree_find): testfun becomes optional argument.
(int_str): base becomes optional argument.
(func_f0, func_f1, func_f2, func_f3, func_f4, func_n0,
func_n1, func_n2, func_n3, func_n4, func_f0v, func_f1v,
func_f2v, func_f3v, func_f4v, func_n0v, func_n1v,
func_n2v, func_n3v, func_n4v, func_interp): Initialize optargs to zero.
(func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): New functions.
(cobj_print_op): Reversed arguments to put_string.
(find): testfun and keyfun become optional arguments.
(replace): Parameters rearranged and arguments rearranged in calls to
replace_list, replace_str and replace_vec.
(obj_init): colon_k initialized.
(obj_print, obj_pprint): Arguments reversed, and stream defaults
to std_output. Arguments reversed in calls to put_char and put_string.
(dump): Arguments reversed in call to put_char.
* lib.h (struct func): sizes of minparam, fixparam bitfields
adjusted. New bitfield optargs. New unnamed bitfield added so
the previous ones add up to 16 bits.
(colon_k): Declared.
(func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): Declared.
(replace_list, replace_str, replace_vec, replace): Declarations updated.
* match.c (debuglf, dump_shell_string, dump_byte_string, dump_var,
do_output_line, extract): Reversed arguments to put_char and
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 51 |
1 files changed, 33 insertions, 18 deletions
@@ -488,7 +488,7 @@ static val strlist_out_put_string(val stream, val str) if (zerop(length)) break; - put_string(strstream, sub_str(str, nil, span_to_newline)); + put_string(sub_str(str, nil, span_to_newline), strstream); if (equal(span_to_newline, length)) break; @@ -513,7 +513,7 @@ static val strlist_out_put_char(val stream, val ch) push(get_string_from_stream(strstream), &lines); strstream = make_string_output_stream(); } else { - put_char(strstream, ch); + put_char(ch, strstream); } *car_l(cell) = lines; @@ -705,6 +705,9 @@ val close_stream(val stream, val throw_on_error) val get_line(val stream) { + if (!stream) + stream = std_input; + type_check (stream, COBJ); type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), stream, nao)); @@ -717,6 +720,9 @@ val get_line(val stream) val get_char(val stream) { + if (!stream) + stream = std_input; + type_check (stream, COBJ); type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), stream, nao)); @@ -729,6 +735,9 @@ val get_char(val stream) val get_byte(val stream) { + if (!stream) + stream = std_input; + type_check (stream, COBJ); type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), stream, nao)); @@ -790,33 +799,33 @@ static val vformat_num(val stream, const char *str, if (!left) for (i = 0; i < slack; i++) - if (!put_char(stream, chr(' '))) + if (!put_char(chr(' '), stream)) return nil; if (!zeropad) for (i = 0; i < padlen; i++) - if (!put_char(stream, chr(' '))) + if (!put_char(chr(' '), stream)) return nil; if (sign_char) { - put_char(stream, chr(sign_char)); + put_char(chr(sign_char), stream); str++; } else if (sign) { - put_char(stream, chr(sign)); + put_char(chr(sign), stream); } if (zeropad) for (i = 0; i < padlen; i++) - if (!put_char(stream, chr('0'))) + if (!put_char(chr('0'), stream)) return nil; while (*str) - if (!put_char(stream, chr(*str++))) + if (!put_char(chr(*str++), stream)) return nil; if (left) for (i = 0; i < slack; i++) - if (!put_char(stream, chr(' '))) + if (!put_char(chr(' '), stream)) return nil; return t; @@ -833,16 +842,16 @@ static val vformat_str(val stream, val str, int width, int left, if (!left) for (i = 0; i < slack; i++) - if (!put_char(stream, chr(' '))) + if (!put_char(chr(' '), stream)) return nil; for (i = 0; i < truelen; i++) - if (!put_char(stream, chr(cstr[i]))) + if (!put_char(chr(cstr[i]), stream)) return nil; if (left) for (i = 0; i < slack; i++) - if (!put_char(stream, chr(' '))) + if (!put_char(chr(' '), stream)) return nil; return t; @@ -883,14 +892,14 @@ val vformat(val stream, val fmtstr, va_list vl) digits = 0; continue; default: - put_char(stream, chr(ch)); + put_char(chr(ch), stream); continue; } break; case vf_width: switch (ch) { case '~': - put_char(stream, chr('~')); + put_char(chr('~'), stream); state = vf_init; continue; case '<': @@ -1146,8 +1155,11 @@ val formatv(val stream, val string, val args) abort(); } -val put_string(val stream, val string) +val put_string(val string, val stream) { + if (!stream) + stream = std_output; + type_check (stream, COBJ); type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), stream, nao)); @@ -1158,8 +1170,11 @@ val put_string(val stream, val string) } } -val put_char(val stream, val ch) +val put_char(val ch, val stream) { + if (!stream) + stream = std_output; + type_check (stream, COBJ); type_assert (stream->co.cls == stream_s, (lit("~a is not a stream"), stream, nao)); @@ -1170,9 +1185,9 @@ val put_char(val stream, val ch) } } -val put_line(val stream, val string) +val put_line(val string, val stream) { - return (put_string(stream, string), put_char(stream, chr('\n'))); + return (put_string(string, stream), put_char(chr('\n'), stream)); } val flush_stream(val stream) |