diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-05-30 09:08:50 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-05-30 09:08:50 -0700 |
commit | 1f54ad5cc1d384d0818a6bf6cec20a95ecc5a5ae (patch) | |
tree | aab51e24a075aed919f5ed3ad4d8232130768730 | |
parent | c5134a9ddba4fd14703d506b0cccd51d823e013e (diff) | |
download | txr-1f54ad5cc1d384d0818a6bf6cec20a95ecc5a5ae.tar.gz txr-1f54ad5cc1d384d0818a6bf6cec20a95ecc5a5ae.tar.bz2 txr-1f54ad5cc1d384d0818a6bf6cec20a95ecc5a5ae.zip |
Replace trivial format(nil, ...) with simpler ops.
* gencadr.txr (cadr_register): Use scat2 to glue two strings.
* cadr.c: Regenerated.
* lib.c (scat2, scat3): New functions.
* lib.h (scat2, scat3): Declared.
* liblib.c (place_instantiate, ver_instantiate,
ifa_instantiate, txr_case_instantiate,
with_resources_instantiate, path_test_instantiate,
struct_instantiate, with_stream_instantiate, hash_instantiate,
except_instantiate, type_instantiate, yield_instantiate,
sock_instantiate, termios_instantiate, awk_instantiate,
build_instantiate, trace_instantiate, getopts_instantiate,
package_instantiate, getput_instantiate, tagbody_instantiate,
pmac_instantiate, error_instantiate, keyparams_instantiate,
ffi_instantiate, doloop_instantiate, stream_wrap_instantiate,
asm_instantiate, compiler_instantiate, debugger_instantiate,
op_instantiate, save_exe_instantiate, defset_instantiate,
copy_file_instantiate): Use scat2 to glue two strings instead
of format.
* parser.c (find_matching_syms, hist_save, repl): Replace
trivial uses of format with scat2 or scat3.
* sysif.c (ensure_dir): Likewise.
* txr.c (get_self_path, substitute_basename, sysroot,
sysroot_init, parse_once_noerr, read_compiled_file_noerr,
read_eval_stream_noerr): Likewise.
* unwind.c (uw_unwind_to_exit_point): Likewise.
-rw-r--r-- | cadr.c | 2 | ||||
-rw-r--r-- | gencadr.txr | 2 | ||||
-rw-r--r-- | lib.c | 35 | ||||
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | lisplib.c | 68 | ||||
-rw-r--r-- | parser.c | 10 | ||||
-rw-r--r-- | sysif.c | 3 | ||||
-rw-r--r-- | txr.c | 16 | ||||
-rw-r--r-- | unwind.c | 2 |
9 files changed, 87 insertions, 53 deletions
@@ -402,7 +402,7 @@ static val cadr_register(val set_fun) reg_fun(intern(lit("cdddadr"), user_package), func_n1(cdddadr)); reg_fun(intern(lit("cddddar"), user_package), func_n1(cddddar)); reg_fun(intern(lit("cdddddr"), user_package), func_n1(cdddddr)); - load(format(nil, lit("~acadr"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("cadr"))); return nil; } diff --git a/gencadr.txr b/gencadr.txr index fea5b7a0..2e242653 100644 --- a/gencadr.txr +++ b/gencadr.txr @@ -46,7 +46,7 @@ static val cadr_register(val set_fun) @ (repeat) reg_fun(intern(lit("c@{ad}r"), user_package), func_n1(c@{ad}r)); @ (end) - load(format(nil, lit("~acadr"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("cadr"))); return nil; } @@ -4223,6 +4223,41 @@ val scat(val sep, ...) return ret; } +val scat2(val s1, val s2) +{ + struct cat_str cs; + + cat_str_init(&cs, nil, NULL); + + cat_str_measure(&cs, s1, 1); + cat_str_measure(&cs, s2, 0); + + cat_str_alloc(&cs); + + cat_str_append(&cs, s1, 1); + cat_str_append(&cs, s2, 0); + + return cat_str_get(&cs); +} + +val scat3(val s1, val sep, val s2) +{ + struct cat_str cs; + wchar_t onech[] = wini(" "); + + cat_str_init(&cs, sep, onech); + + cat_str_measure(&cs, s1, 1); + cat_str_measure(&cs, s2, 0); + + cat_str_alloc(&cs); + + cat_str_append(&cs, s1, 1); + cat_str_append(&cs, s2, 0); + + return cat_str_get(&cs); +} + val fmt_join(struct args *args) { cnum index; @@ -852,6 +852,8 @@ val replace_str(val str_in, val items, val from, val to); val sub_str(val str_in, val from_num, val to_num); val cat_str(val list, val sep); val scat(val sep, ...); +val scat2(val s1, val s2); +val scat3(val s1, val sep, val s2); val fmt_join(struct args *args); val split_str(val str, val sep); val split_str_keep(val str, val sep, val keep_sep); @@ -110,7 +110,7 @@ static val place_set_entries(val dlt, val fun) static val place_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aplace"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("place"))); return nil; } @@ -124,7 +124,7 @@ static val ver_set_entries(val dlt, val fun) static val ver_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aver"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("ver"))); return nil; } @@ -140,7 +140,7 @@ static val ifa_set_entries(val dlt, val fun) static val ifa_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aifa"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("ifa"))); return nil; } @@ -154,7 +154,7 @@ static val txr_case_set_entries(val dlt, val fun) static val txr_case_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~atxr-case"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("txr-case"))); return nil; } @@ -172,7 +172,7 @@ static val with_resources_set_entries(val dlt, val fun) static val with_resources_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~awith-resources"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("with-resources"))); return nil; } @@ -200,7 +200,7 @@ static val path_test_set_entries(val dlt, val fun) static val path_test_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~apath-test"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("path-test"))); return nil; } @@ -229,7 +229,7 @@ static val struct_set_entries(val dlt, val fun) static val struct_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~astruct"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("struct"))); return nil; } @@ -252,7 +252,7 @@ static val with_stream_set_entries(val dlt, val fun) static val with_stream_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~awith-stream"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("with-stream"))); return nil; } @@ -266,7 +266,7 @@ static val hash_set_entries(val dlt, val fun) static val hash_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~ahash"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("hash"))); return nil; } @@ -284,7 +284,7 @@ static val except_set_entries(val dlt, val fun) static val except_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aexcept"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("except"))); return nil; } @@ -298,7 +298,7 @@ static val type_set_entries(val dlt, val fun) static val type_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~atype"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("type"))); return nil; } @@ -322,7 +322,7 @@ static val yield_set_entries(val dlt, val fun) static val yield_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~ayield"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("yield"))); return nil; } @@ -364,7 +364,7 @@ static val sock_instantiate(val set_fun) { funcall1(set_fun, nil); sock_load_init(); - load(format(nil, lit("~asocket"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("socket"))); return nil; } @@ -387,7 +387,7 @@ static val termios_set_entries(val dlt, val fun) static val termios_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~atermios"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("termios"))); return nil; } @@ -420,7 +420,7 @@ static val awk_set_entries(val dlt, val fun) static val awk_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aawk"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("awk"))); return nil; } @@ -444,7 +444,7 @@ static val build_set_entries(val dlt, val fun) static val build_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~abuild"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("build"))); return nil; } @@ -465,7 +465,7 @@ static val trace_set_entries(val dlt, val fun) static val trace_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~atrace"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("trace"))); trace_loaded = t; return nil; } @@ -489,7 +489,7 @@ static val getopts_set_entries(val dlt, val fun) static val getopts_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~agetopts"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("getopts"))); return nil; } @@ -506,7 +506,7 @@ static val package_set_entries(val dlt, val fun) static val package_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~apackage"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("package"))); return nil; } @@ -531,7 +531,7 @@ static val getput_set_entries(val dlt, val fun) static val getput_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~agetput"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("getput"))); return nil; } @@ -547,7 +547,7 @@ static val tagbody_set_entries(val dlt, val fun) static val tagbody_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~atagbody"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("tagbody"))); return nil; } @@ -563,7 +563,7 @@ static val pmac_set_entries(val dlt, val fun) static val pmac_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~apmac"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("pmac"))); return nil; } @@ -587,7 +587,7 @@ static val error_set_entries(val dlt, val fun) static val error_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aerror"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("error"))); return nil; } @@ -614,7 +614,7 @@ static val keyparams_set_entries(val dlt, val fun) static val keyparams_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~akeyparams"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("keyparams"))); return nil; } @@ -636,7 +636,7 @@ static val ffi_set_entries(val dlt, val fun) static val ffi_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~affi"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("ffi"))); return nil; } @@ -653,7 +653,7 @@ static val doloop_set_entries(val dlt, val fun) static val doloop_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~adoloop"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("doloop"))); return nil; } @@ -676,14 +676,14 @@ static val stream_wrap_set_entries(val dlt, val fun) static val stream_wrap_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~astream-wrap"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("stream-wrap"))); return nil; } static val asm_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aasm"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("asm"))); return nil; } @@ -706,7 +706,7 @@ static val asm_set_entries(val dlt, val fun) static val compiler_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~acompiler"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("compiler"))); return nil; } @@ -731,7 +731,7 @@ static val compiler_set_entries(val dlt, val fun) static val debugger_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~adebugger"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("debugger"))); return nil; } @@ -762,14 +762,14 @@ static val op_set_entries(val dlt, val fun) static val op_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~aop"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("op"))); return nil; } static val save_exe_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~asave-exe"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("save-exe"))); return nil; } @@ -787,7 +787,7 @@ static val save_exe_set_entries(val dlt, val fun) static val defset_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~adefset"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("defset"))); return nil; } @@ -805,7 +805,7 @@ static val defset_set_entries(val dlt, val fun) static val copy_file_instantiate(val set_fun) { funcall1(set_fun, nil); - load(format(nil, lit("~acopy-file"), stdlib_path, nao)); + load(scat2(stdlib_path, lit("copy-file"))); return nil; } @@ -966,9 +966,9 @@ static void find_matching_syms(lino_completions_t *cpl, continue; if (qualify) - comple = format(nil, lit("~a~a:~a"), line_prefix, pkg_name, name, nao); + comple = scat(line_prefix, pkg_name, lit(":"), name, nao); else - comple = format(nil, lit("~a~a"), line_prefix, name, nao); + comple = scat2(line_prefix, name); lino_add_completion(cpl, c_str(comple)); gc_hint(comple); @@ -1406,7 +1406,7 @@ static void hist_save(lino_t *ls, val in_stream, val out_stream, val hist_len_var) { if (histfile_w && lino_have_new_lines(ls)) { - val histfile_tmp = format(nil, lit("~a.tmp"), histfile, nao); + val histfile_tmp = scat2(histfile, lit(".tmp")); const wchar_t *histfile_tmp_w = c_str(histfile_tmp); lino_t *ltmp = lino_make(coerce(mem_t *, in_stream), coerce(mem_t *, out_stream)); @@ -1442,9 +1442,9 @@ val repl(val bindings, val in_stream, val out_stream, val env) val done = nil; val counter = one; val home = if3(repl_level == 1, get_home_path(), nil); - val histfile = if2(home, format(nil, lit("~a/.txr_history"), home, nao)); + val histfile = if2(home, scat2(home, lit("/.txr_history"))); const wchar_t *histfile_w = if3(home, c_str(histfile), NULL); - val rcfile = if2(home, format(nil, lit("~a/.txr_profile"), home, nao)); + val rcfile = if2(home, scat2(home, lit("/.txr_profile"))); val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr)); val hist_len_var = lookup_global_var(listener_hist_len_s); val multi_line_var = lookup_global_var(listener_multi_line_p_s); @@ -405,8 +405,7 @@ static val ensure_dir(val path, val mode) if (!split_path) break; - partial_path = format(nil, lit("~a~a~a"), - partial_path, sep, pop(&split_path), nao); + partial_path = scat3(partial_path, sep, pop(&split_path)); } if (integerp(ret)) { @@ -254,7 +254,7 @@ static val get_self_path(void) val execname = string_utf8(getexecname()); if (car(execname) == chr('/')) return execname; - return format(nil, lit("~a/~a"), getcwd_wrap(), execname, nao); + return scat3(getcwd_wrap(), chr('/'), execname); } #else static val get_self_path(void) @@ -278,15 +278,13 @@ static val substitute_basename(val edited_path, val source_path) source_path); return if3(lslash, - format(nil, lit("~a~a"), - sub_str(edited_path, 0, succ(lslash)), - basename, nao), + scat2(sub_str(edited_path, 0, succ(lslash)), basename), basename); } static val sysroot(val target) { - return format(nil, lit("~a~a"), sysroot_path, target, nao); + return scat2(sysroot_path, target); } static void sysroot_init(void) @@ -305,7 +303,7 @@ static void sysroot_init(void) prog_dir = dir_name(prog_path); if (ref(prog_dir, negone) != chr(psc[0])) - prog_dir = format(nil, lit("~a~a"), prog_dir, chr(psc[0]), nao); + prog_dir = scat3(prog_dir, chr(psc[0]), lit("")); if (!(maybe_sysroot(lit(TXR_REL_PATH)) || maybe_sysroot(lit(TXR_REL_PATH EXE_SUFF)) || @@ -473,21 +471,21 @@ static void no_dbg_support(val arg) static int parse_once_noerr(val stream, val name) { - val pfx = format(nil, lit("~a:"), name, nao); + val pfx = scat2(name, lit(":")); ignerr_func_body(int, 0, parse_once(prog_string, stream, name), std_error, pfx); } static val read_compiled_file_noerr(val self, val stream, val name, val error_stream) { - val pfx = format(nil, lit("~a:"), name, nao); + val pfx = scat2(name, lit(":")); ignerr_func_body(val, nil, read_compiled_file(self, stream, error_stream), std_error, pfx); } static val read_eval_stream_noerr(val self, val stream, val name, val error_stream) { - val pfx = format(nil, lit("~a:"), name, nao); + val pfx = scat2(name, lit(":")); ignerr_func_body(val, nil, read_eval_stream(self, stream, error_stream), std_error, pfx); } @@ -121,7 +121,7 @@ static void uw_unwind_to_exit_point(void) val args = unhandled_ex.ca.args; if (opt_loglevel >= 1) { - val prefix = format(nil, lit("~a:"), prog_string, nao); + val prefix = scat2(prog_string, lit(":")); flush_stream(std_output); format(std_error, lit("~a unhandled exception of type ~a:\n"), |