summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
...
* * lib.c (symbol_setname): New static function.Kaz Kylheku2014-09-031-7/+26
| | | | | | | | | | | | | | (obj_init): Change exception symbol names with underscores to use friendly dashes instead. (compat_fixup): New function. * lib.h (compat_fixup): Declared. * txr.1: Change occurrences of exception symbols from underscores to dashes. * txr.c (txr_main): Call compat_fixup when -C option is processed.
* * eval.c (eval_init): Update registration of lisp-parse and readKaz Kylheku2014-09-021-1/+2
| | | | | | | | | | | | | | | | | | | | to account for new parameter. * lib.c (syntax_error_s): New symbol_variable. (obj_init): New symbol variable initialized. * lib.h (syntax_error_s): Declared. * parser.h (lisp_parse): Declaration updated. * parser.l (lisp_parse): Takes third parameter. * txr.1: Third parameter of read described. * txr.c (txr_main): Pass colon_k to third parameter of lisp_parse to obtain exception throwing behavior. * unwind.c (uw_init): Register syntax-error as subtype of error.
* * arith.c (arith_init): Register some variables: *flo-dig*,Kaz Kylheku2014-09-011-1/+1
| | | | | | | | | | | | *flo-min*, *flo-max*, *flo-epsilon*, *pi* and *e*. * genvim.txr: Include arith.c in scan for symbols. * lib.c (init): arith_init() must now be called after eval_init(). * txr.1: Documented new variables.. * txr.vim: Updated.
* GC correctness fixes: make sure we pin down objects for which we borrowKaz Kylheku2014-08-251-2/+9
| | | | | | | | | | | | | | | low level C pointers, while we execute code that can cons memory. * lib.c (list_str): Protect the str argument. (int_str): Likewise. * regex.c (search_regex): protect the haystack string, while using the h pointer to its data, since regex_run can use the derivative-based engine which conses. * stream.c (vformat_str): Protect str argument, since put_char might conceivably cons. (vformat): Protect fmtstr.
* * eval.c (eval_init): Register uniq function.Kaz Kylheku2014-07-291-0/+33
| | | | | | | | * lib.c (uniq): New function. * lib.h (uniq): Declared. * txr.1: Documented uniq.
* * eval.c (eval_init): Register nconc as intrinsic.Kaz Kylheku2014-07-291-0/+12
| | | | | | | | * lib.c (nconcv): New function. * lib.h (nconcv): Declared. * txr.1: Documented nconc.
* * lib.c (reduce_left, reduce_right): Nullify incoming sequenceKaz Kylheku2014-07-291-0/+4
| | | | argument so empty vectors and strings can be processed.
* * eval.c (eval_init): Register partition-by intrinsic.Kaz Kylheku2014-07-281-0/+46
| | | | | | | | | * lib.c (partition_by_func): New static function. (partition_by): New function. * lib.h (partition_by): Declared. * txr.1: Documented partition-by.
* Fix 2014-02-05 safety regression: unchecked use of non-function objectsKaz Kylheku2014-07-271-5/+5
| | | | | | | | in some contexts that require functions. * lib.c (funcall, funcall1, funcall2, funcall3, funcall4): check type(fun) before dereferencing to see whether there are optional args.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* * configure: Add a check, in the case that we cannot make anKaz Kylheku2014-07-221-0/+22
| | | | | | | | | | | | | | | | | executable, whether this is due to being required to use C99. For instance, the Solaris environment requires compilation using the C99 dialect if _XOPEN_SOURCE is set to 600 or higher. * debug.c: When compiling as C99, we have to obey the special C99 conventions for instantiating inline functions. * hash.c: Likewise. * lib.c: Likewise. * parser.y: Likewise. * unwind.c: Likewise.
* * eval.c (eval_init): Register juxt as intrinsic.Kaz Kylheku2014-07-201-0/+10
| | | | | | | | | * lib.c (do_juxt): New static function. (juxtv): New function. * lib.h (juxtv): Declared. * txr.1: Documented juxt.
* * lib.c (search_str): Support negative starting index.Kaz Kylheku2014-07-191-4/+14
| | | | | | Hoist uselessly repeated c_str operation out of loop. * txr.1: Document negative starting index for search-str.
* * eval.c (mapdov): New function.Kaz Kylheku2014-07-191-0/+10
| | | | | | | | | | | (eval_init): Register mapdo intrinsic. * lib.c (mapdo): New function. * lib.h (mapdo): Declared. * txr.1: Documented mapdo. Documented zero-argument case for mapcar, mapcar*, mappend and mappend*.
* * eval.c (eval_init): Register interpose and lconsp as intrinsics.Kaz Kylheku2014-07-141-0/+61
| | | | | | | | | * lib.c (lconsp, interpose): New functions. (lazy_interpose_func, lazy_interpose): New static functions. * lib.h (lconsp, interpose): Declared. * txr.1: Documented lconsp and interpose.
* * lib.c (replace_list, sel): fix use of unused variable.Kaz Kylheku2014-07-071-2/+2
|
* * eval.c (dwim_loc): Support indexing using a list of positions,Kaz Kylheku2014-07-021-10/+65
| | | | | | | | | | | | | | | such as obtained by the where function. * lib.c (replace_list, replace_str, replace_vec): Allow the from argument to be a list of index positions, possibly empty. * txr.1: Condensed syntactic descriptions under dwim operator. Range Indexing section no longer says that the value nil can be used as either endpoint of a range. This will not work any longer since a "from" value of nil looks like an empty list of indexes. Documented new behavior under replace, and shortened documentation for replace-list, replace-str and replace-vec.
* * lib.c (sel): Bugfix: not implemented correctly for sequencesKaz Kylheku2014-06-301-4/+2
| | | | which are lists.
* * lib.c (where, sel): Extend into hashes.Kaz Kylheku2014-06-271-6/+34
| | | | * txr.1: document hash support for select and where.
* Bugfix: apply_intrinsic and iapply must not destructivelyKaz Kylheku2014-06-271-0/+7
| | | | | | | | | | | | manipulate argument lists. * eval.c (apply_frob_args): Rewrite to non-destructive one-pass version. (iapply): Likewise. * lib.c (term): New function. * lib.h (term): Declared.
* * lib.c (last): Bugfix: reversed null test.Kaz Kylheku2014-06-261-1/+1
|
* * eval.c (eval_init): register range_regex and tok_whereKaz Kylheku2014-06-261-0/+23
| | | | | | | | | | | | | | as intrinsics. * lib.c (tok_where): New function. * lib.h (tok_where): Declared. * regex.c (range_regex): New function. * regex.h (range_regex): Declared. * txr.1: Documented tok-where and range-regex.
* * lib.c (search): Bugfix in type mismatch error message:Kaz Kylheku2014-06-261-1/+1
| | | | trying to print cons function pointer as value.
* * eval.c (mapcarv): Use mapcar_listout, so list_of_lists can beKaz Kylheku2014-06-261-3/+32
| | | | | | | | | | | | | a non-list sequence. (eval_init): Register transpose and zip as intrinsics. * lib.c (curry_12_1_v): New static function. (transpose, mapcar_listout): New functions. (mapcar): Redefined in terms of mapcar_listout. * lib.h (transpose, mapcar_listout): Declared. * txr.1: Documented transpose and zip.
* Optimization: add missing tail updates to some listKaz Kylheku2014-06-201-5/+5
| | | | | | | | | | | collecting loops. * lib.c (tuples_func, where, sel): Catch return value of list_collect and update tail variable. * match.c (do_txeval): Likewise. * parser.y (expand_meta): Likewise for list_collect_nconc.
* * eval.c (me_ap): New static function.Kaz Kylheku2014-06-191-3/+12
| | | | | | | | | | | | | | (eval_init): Use new list_f instead of func_n0v(identity). Register multi as intrinsic. Register me_ap as ap macro. * lib.c (list_f): New global variable. (multi): New function. (multi_sort): Use list_f in place of func_n0v(identity). (obj_init): gc-protect and initialize list_f. * lib.h (list_f, multi): Declared. * txr.1: Documented multi and ap.
* * eval.c (eval_init): Register member and member_if as intrinsics.Kaz Kylheku2014-06-181-0/+35
| | | | | | | | | | * lib.c (member, member_if): New functions. * lib.h (member, member_if): Declared. * txr.1: Documented. * txr.vim: Regenerated.
* * lib.c (generic_funcall): Bugfixes: support symbols.Kaz Kylheku2014-06-171-4/+12
| | | | | | | | Removed dubious statement which clamps nargs to the number of fixed parameters, breaking variadic calls. Test case: (mapcar 'list '(1 2)) -> ((1) (2)) Note: generic_funcall is only used when non-function objects are used as functions; variadic funcalls were not broken.
* * eval.c (eval_init): register tuples as intrinsic.Kaz Kylheku2014-06-171-0/+35
| | | | | | | | | * lib.c (tuples_func): New static function. (tuples): New function. * lib.h (tuples): Declared. * txr.1: Documented.
* * lib.c (obj_print): Render character DC00 as "pnul".Kaz Kylheku2014-06-151-3/+8
| | | | | | | | | | | | | Clean up code which chooses rendering for characters. Print C0 and C1 control characters, as well as D800-DFFF, FFFE and FFFF and characters above FFFF using hex; others are printed using the #\<char> notation. * parser.y (char_from_name): map "pnul" to DC00. * txr.1: Documented pnul, clarified character printing rules, and added a cautionary note about possible ambiguity in printing.
* * eval.c (eval_init): Register pos_max, pos_min, find_max,Kaz Kylheku2014-06-151-5/+88
| | | | | | | | | | | | | | | | | | find_min and seqp as intrinsics. * lib.c (gt_f, lt_f): New variables. (to_seq): renamed to toseq. (seqp): New function. (minmax): New static function. (replace_str, replace_vec): Follow to_seq renaming. (find_max, find_min, pos_max, pos_min): New functions. (obj_init): gc-protect and initialize gt_f and lt_f. * lib.h (gt_f, lt_f): Declared. (to_seq): Declaration updated to toseq. (seqp, find_max, find_min, pos_max, pos_min): Declared. * txr.1: Updated.
* * eval.c (eval_init): where and sel registered as intrinsicsKaz Kylheku2014-06-151-2/+65
| | | | | | | | | | | | where and select. * lib.c (generic_funcall): Support a sequence as an argument to a sequence. (where, sel): New functions. * lib.h (where, sel): Declared. * txr.1: Documented.
* * eval.c (eval_init): Change registration of string_cmpKaz Kylheku2014-06-101-9/+31
| | | | | | | | | | | | | | | | | | | to cmp_str. Add registrations for str_eq, str_lt, str_gt, str_le, and str_lt. * lib.c (string_cmp): Name changes to cmp_str, and the function fixed so that it actually works. The name change doesn't affect anyone because the function was too broken to use due to the incorrect type dispatch. (string_lt): Name changes to str_lt. (str_eq, str_gt, str_le, str_ge): New functions. * lib.h (string_cmp, string_lt): Declarations renamed. (str_eq, str_gt, str_le, str_ge): New declarations. * txr.1: Document string-cmp to cmp-str rename, that string-lt is deprecated, and the new str<, str>, str>=, str<= and str= functions.
* * lib.c (match_str): Extended to suffix testing, with a negativeKaz Kylheku2014-06-091-8/+23
| | | | | | start argument. * txr.1: Documented.
* Fixing issue with list-like iteration over generic sequences,Kaz Kylheku2014-06-061-18/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | namely that empty strings and vectors are not nil. The nullify function is introduced. It is also exposed to users, as is the existing make_like function. * eval.c (mapcarv, mappendv, lazy_mapcar, lazy_mapcarv): Use nullify to handle non-list inputs correctly. (eval_init): Registering make_like and nullify as intrinsics. * lib.c (copy_list, to_seq, list_collect_nconc, list_collect_append, reverse, lazy_appendv_func, lazy_appendv, ldiff, memq, memql, memqual, remq, remql, remqual, remove_if, keep_if, rem_lazy_rec, remq_lazy, remql_lazy, remqual_lazy, remove_if_lazy, keep_if_lazy, countqual, countql, countq, count_if, some_satisfy, all_satisfy, none_satisfy, do_chain, chainv, do_and, andv, do_or, orv, cat_vec, assoc, assql, mapcar, mapcon, mappend, sort, multi_sort, find, find_if, posqual, posql, posq, pos, pos_if, set_diff, search): Use nullify for correctness. Some functions fixed so return sequence matches type of input sequence. (nullify): New function. * lib.h (nullify): Declared. * txr.1: Documented nullify and ake-like.
* * eval.c (eval_init): Register new search function as intrinsic.Kaz Kylheku2014-06-061-0/+66
| | | | | | | | | | | * lib.c (search_list): New static function. (search): New function. * lib.h (search): New function declared. * txr.1: Documented. * txr.vim: Regenerated.
* Documenting the return value of rplaca and rplacd, and changingKaz Kylheku2014-06-031-7/+11
| | | | | | | | | | | | it to be the cell, rather than the new value. * eval.c (transform_op): Fix use of rplacd that uses return value. (force): Likewise. * lib.c (rplaca, rplacd): Return cons. (rem_lazy_rec, obj_init): Fix use of rplacd that uses return value. * txr.1: Documented.
* String type related bugfixes: neglecting to handle all three kinds inKaz Kylheku2014-05-101-0/+4
| | | | | | | | | | | | | | | some places. In particular, the test case echo : | ./txr -c '@a:@a' - breaks because of neglected LIT in do_match_line. * arith.c (tofloat, toint): Handle LIT type in switch. * lib.c (ref, refset, replace, update): Handle LSTR type. * match.c (do_match_line, do_output_line): Handle LSTR and LIT objects in switch.
* * lib.c (eql): Bugfix: not handling floating-point types!Kaz Kylheku2014-04-071-5/+13
| | | | | Two objects which are equal floating-point values must be considered eql even if they are distinct objects (not eq).
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-146/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash, Change to how locations are passed around, for the sake of generational GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash,
* * lib.c (string_time): If possible, change the timezone in theKaz Kylheku2014-03-291-0/+5
| | | | | struct tm from "GMT" to "UTC", so that the time_string_utc function will use UTC for the %Z format.
* More generational GC fixes. One GC fix.Kaz Kylheku2014-03-271-7/+8
| | | | | | | | | | | | | | | * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common): Use set macro instead of plain assignment. * hash.c (hash_grow, copy_hash, hash_update_1): Use set macro instead of plain assignment. * lib.c (nreverse, lazy_appendv_func, lazy_appendv, vec_push, refset): Use set macro instead of plain assignment. (make_package): Assign all fields of the newly created PKG object before calling a function which can trigger GC. * parser.y (rlset): Use set macro.
* Fix generational GC regression caused by fixesKaz Kylheku2014-03-271-12/+12
| | | | | | | | | | in in 2014-03-12, when prof was introduced. The attempt to fix a bug made things worse. * lib.c (adjust_bounds): New static function. (chk_malloc, chk_calloc, chk_realloc): Replace existing logic with call to adjust_bounds. (chk_malloc_gc_more): Bugfix: add missing call to adjust_bounds.
* * eval.c (me_quasilist): New static function.Kaz Kylheku2014-03-251-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | (eval_init): Register me_quasilist as quasilist macro expander. * lib.c (quasilist_s): New global variable. (obj_init): quasilist_s initialized. * lib.h (quasilist_s): Declared. * match.c (do_txreval): Handle quasilist syntax. * parser.l (QWLIT): New exclusive state. Extend lexical grammar to transition to QWLIT state upon the #` or #*` sequence which kicks off a word literal, and in that state, piecewise lexically analyze the QLL, mostly by borrowing rules from quasiliterals. * parser.y (QWORDS, QWSPLICE): New tokens. (n_exprs): Integrate splicing form of QLL syntax. (n_expr): Integrate non-splicing form of QLL syntax. (litchars): Propagate line number info. (quasilit): Fix "string literal" wording in error message. * txr.1: Introduced WLL abbreviation for word list literals, cleaned up the text a little, and documented QLL's.
* * eval.c (eval_init): Register last function as intrinsic.Kaz Kylheku2014-03-231-0/+6
| | | | | | | | * lib.c (last): New function. * lib.h (last): Declared. * txr.1: Documented last.
* * eval.c (eval_init): Register empty as intrinsic.Kaz Kylheku2014-03-231-0/+34
| | | | | | | | | | | | * lib.c (copy): Bugfix: handle lazy strings. Also, handle hash tables via copy_hash. (length): Bugifx: handle lazy strings. Also, handle hash tables via hash_count. (empty): New function. * lib.h (empty): Declared. * txr.1: Documented.
* * lib.c (iffi): Bugfix: was still using incorrect, outdated optionalKaz Kylheku2014-03-121-2/+1
| | | | argument defaulting logic.
* * eval.c (plus_s, prof_s): New symbol global variables.Kaz Kylheku2014-03-121-3/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (op_prof, me_pprof): New static functions. (eval_init): Intern prof symbol, store in prof_s. Captured interned + symbol in plus_s. Register prof operator and pprof macro. * gc.c (gc_bytes): New global variable. (more): Use nse function chk_malloc_gc_more instead of chk_malloc. (make_obj): Increment gc_bytes. * lib.c (malloc_bytes): New global variable. (chk_malloc, chk_realloc): Increment malloc_bytes. (chk_calloc): Bugfix: incorrect size in recursion into oom_realloc. Incorrect calculation of malloc_high_bound. Increment malloc_bytes. (chk_malloc_gc_more): New function. * lib.h (alloc_bytes_t): New typedef. (malloc_bytes, gc_bytes): Declared. (chk_malloc_gc_more): Declared. * stream.c (format_s): New symbol global. (stream_init): format_s inited. format_s used to register formatv function. * stream.h (format_s): Declared. * txr.1: Documented prof and pprof. * genvim.txr: Recognize reg_fun calls with intern followed by a preceding assignment or other syntax. * txr.vim: Updated.
* * lib.c (lazy_sub_str): Bugfix: "from" was mistakenly usedKaz Kylheku2014-03-091-1/+1
| | | | | | | in the adjustment of the "to" value. * match.c (search_form): Use predefined constants for -1 and 1 instead of calling num.
* * lib.c (upop): New function.Kaz Kylheku2014-03-071-0/+6
| | | | | | | | | | | | | | * lib.h (upop): Declared. * txr.c (txr_main): Two bugfixes. One is that the argument - was being pushed back twice resulting in *args* being ("-" "-"). This is because the option processing loop checked for "-" and pushed it back into args, and then some logic after the loop pushed arg back into args again. But, these pushes were wrong because they push back a different cons cell; we would like to be able to do (ldiff *full-args* *args*). This is solved by upop, which provides one element of undo. After upop, we can restore the prior list from the undo save location.