From 72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 21 Feb 2012 18:13:52 -0800 Subject: 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 --- match.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'match.c') diff --git a/match.c b/match.c index 3735b07a..9028cd81 100644 --- a/match.c +++ b/match.c @@ -73,7 +73,7 @@ static void debuglf(val form, val fmt, ...) format(std_error, lit("~a: (~a:~a) "), prog_string, spec_file_str, source_loc(form), nao); vformat(std_error, fmt, vl); - put_char(std_error, chr('\n')); + put_char(chr('\n'), std_error); va_end (vl); } } @@ -113,23 +113,23 @@ static void dump_shell_string(const wchar_t *str) { int ch; - put_char(std_output, chr('"')); + put_char(chr('"'), std_output); while ((ch = *str++) != 0) { switch (ch) { case '"': case '`': case '$': case '\\': case '\n': - put_char(std_output, chr('\\')); + put_char(chr('\\'), std_output); /* fallthrough */ default: - put_char(std_output, chr(ch)); + put_char(chr(ch), std_output); } } - put_char(std_output, chr('"')); + put_char(chr('"'), std_output); } static void dump_byte_string(const char *str) { while (*str) - put_char(std_output, chr(*str++)); + put_char(chr(*str++), std_output); } @@ -162,12 +162,12 @@ static void dump_var(val var, char *pfx1, size_t len1, obj_pprint(value, ss); str = get_string_from_stream(ss); - put_string(std_output, var); + put_string(var, std_output); dump_byte_string(pfx1); dump_byte_string(pfx2); - put_char(std_output, chr('=')); + put_char(chr('='), std_output); dump_shell_string(c_str(str)); - put_char(std_output, chr('\n')); + put_char(chr('\n'), std_output); } } @@ -1576,7 +1576,7 @@ static void do_output_line(val bindings, val specline, val filter, val out) if (str == nil) sem_error(specline, lit("bad substitution: ~a"), second(elem), nao); - put_string(out, str); + put_string(str, out); } else if (directive == rep_s) { val clauses = cdr(elem); val args = pop(&clauses); @@ -1679,7 +1679,7 @@ static void do_output_line(val bindings, val specline, val filter, val out) } break; case STR: - put_string(out, elem); + put_string(elem, out); break; case 0: break; @@ -1798,7 +1798,7 @@ static void do_output(val bindings, val specs, val filter, val out) } do_output_line(bindings, specline, filter, out); - put_char(out, chr('\n')); + put_char(chr('\n'), out); } } @@ -3565,7 +3565,7 @@ int extract(val spec, val files, val predefined_bindings) } if (!success) - put_line(std_output, lit("false")); + put_line(lit("false"), std_output); } return success ? 0 : EXIT_FAILURE; -- cgit v1.2.3