summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* New function: copy-hash-iter.Kaz Kylheku2024-06-184-1/+54
| | | | | | | | | | | | * hash.c (hash_iter_ops): Use copy_hash_iter as the clone operation. (copy_hash_iter): New function. * hash.h (copy_hash_iter): Declared. * tests/010/hash.tl: New tests. * txr.1: Documented.
* iter_reset: call seq_info only when needed.Kaz Kylheku2024-06-171-7/+11
| | | | | | * lib.c (iter_reset): Propagate sinf variable and seq_info call which initializes it into the scopes where it is used.
* More work on copy-iter.Kaz Kylheku2024-06-172-10/+88
| | | | | | | | | | * lib.c (copy_iter): Use the copy method for arguments which are structures, or else return just the objects if they implement list-like sequences. Error out otherwise. For an argument that is not an iterators or structure, error out if it is not a number, nil, or a list-like sequence. * txr.1: Documented.
* cobj: clone method streamlines copy; structs get copy method.Kaz Kylheku2024-06-1725-73/+173
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.h (struct cobj_ops): New function pointer, clone. (cobj_ops_init, cobj_ops_init_ex): Add clone argument to macros. * lib.c (seq_iter_cobj_ops): Use copy_iter as the clone operation. (cptr_ops): Use copy_cptr as clone operation. (copy): Replace if statements by check whether COBJ has a clone operation. If so, we use it to copy the object. * struct.h (enum special_slot): New member, copy_m. * struct.c (copy_s): New symbol variable. (special_sym): Associate copy_m enum value with copy symbol. (struct_init): Initialize copy_s with interned symbol. (struct_inst_clone): New static function. (struct_type_ops): Specify no clone operation via null pointer. (struct_inst_ops): Specify struct_inst_clone as clone operation. * arith.c (psq_ops): Indicate no clone operation via null pointer. * buf.c (buf_strm_ops): Likewise. * chksum.c (sha1_ops, sha256_ops, md5_ops): Likewise. * ffi.c (ffi_type_builtin_ops, ffi_type_struct_ops, ffi_type_ptr_ops, ffi_type_enum_ops, ffi_closure_ops, union_ops): Likewise. (carray_borrowed_ops, carry_owned_ops, carray_mmap_ops): Specify copy_carray as clone operation. * gc.c (prot_array_ops): Indicate no clone operation via null pointer. * gzip.c (gzio_ops_rd, gzip_ops_wr): Likewise. * hash.c (hash_iter_ops): Likewise. (hash_ops): Specify copy_hash as clone operation. * parser.c (parser_ops): Indicate no clone operation via null pointer. * rand.c (random_state_clone): New static function. (random_state_ops): Use random_state_clone as clone function. * regex.c (char_set_obj_ops, regex_obj_ops): Indicate no clone operation via null pointer. * socket.c (dgram_strm_ops): Likewise. * stream.c (null-ops, stdio_ops, tail_ops, pipe_ops, dir_ops, string_in_ops, byte_in_ops, strlist_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops, record_adapter_ops): Likewise. * strudel.c (strudel_ops): Likewise. * sysif.c (cptr_dl_ops, opendir_ops): Likewise. * syslog.c (syslog_strm_ops): Likewise. * unwind.c (cont_ops): Likewise. * vm.c (vm_desc_ops, vm_closure_ops): Likewise. * tree.c (tree_ops): Use copy_search_tree for clone operation. (tree_iter_ops): Use copy_tree_iter for clone operation. * genchksum.txr: Changes in chksum.c specified in one place here. * tests/012/oop.tl: Couple of new tests. * txr.1: Documented.
* New function: copy-iter.Kaz Kylheku2024-06-153-0/+18
| | | | | | * eval.c (eval_init): Register copy-iter intrinsic. * lib.[ch] (copy_iter): New function.
* quips: remove weak one.Kaz Kylheku2024-06-151-1/+0
| | | | | * stdlib/quips.tl (%quips%): Remove quip about lecithin; it does not wear well.
* seq_iter: fix inadequate gc marking for some types.Kaz Kylheku2024-06-152-6/+22
| | | | | | | | | | | | * lib.c (seq_iter_mark_oop, seq_iter_mark_cat): New static functions. (si_oop_ops, si_fast_oop_ops): Use seq_iter_mark_oop instead of the generic one, because we need to mark the next field, not only the iter. (si_cat_ops): Use seq_iter_mark_cat, since we need to mark only the second field, dargs. * lib.h (seq_iter_ops_init_mark): New macro.
* New permi: iterator version of perm.Kaz Kylheku2024-06-155-10/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register permi intrinsic. * combi.c (permi_get, permi_peek, permi_clone): New static functions. (permi_ops): New static structure. (permi_iter): New static function. (permi): New function. * combi.h (permi): Declared. * lib.h (struct seq_iter_ops): New function pointer, clone. (seq_iter_ops_init, seq_iter_ops_init_nomark): Initialize new member. (seq_iter_ops_init_clone): New macro. (seq_iter_cls): Existing external name declared. (seq_iter_cobj_ops, seq_iter_mark_op): Previously internal names declared external. * lib.c (seq_iter_mark_op, seq_iter_cobj_ops): Static variables become extern. (seq_iter_clone): New static function. (seq_iter_init_with_info): Use seq_iter_clone instead of assuming we can trivially clone an iterator state bitwise.
* lib: rename seq_iter_ops static object.Kaz Kylheku2024-06-141-9/+10
| | | | | | | | | | The seq_iter_ops static structure is an instance of cobj_ops. Its name is the same identifier as that of struct seq_iter_ops, which is not related. This is confusing. * lib.c (seq_iter_ops): Structure renamed to seq_iter_obj_ops. (seq_begin, iter_begin, iter_dynamic, iter_catv): References to object updated to new name.
* perm: small streamlining in string case.Kaz Kylheku2024-06-131-1/+1
| | | | | * combi.c (perm_str): We don't have to convert the string to a list and then vector, since we have vec_seq.
* combi: consolidate k argument check.Kaz Kylheku2024-05-291-24/+14
| | | | | | * combi.c (check_k): New static function. (perm, rperm, comb, rcomb): Replace copy pasted code with call to check_k.
* bugfix: one missing case of fmt_cat separator defaulting.Kaz Kylheku2024-05-271-1/+1
| | | | | | | | | | In a recent commit, the defaulting of the separator in quasiliteral variable formatting was moved down into the fmt_cat routine. One stray case remains in subst_vars. * eval.c (subst_vars): A call to fmt_cat is specifying a separator value consisting of a single space. This is wrong, preventing fmt_cat from defaulting it in different ways according to type.
* quasiliterals: buffers in hex, separation for strings and buffers.Kaz Kylheku2024-05-277-9/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this commit, output variables in the TXR Pattern language and in TXR Lisp quasiliterals now support separator strings for values that are strings and buffers. Values which are buffers appear differently: they are rendered as a sequence of lower case hex digit pairs. When a string-valued variable specifies a separator, the separator appears between characters of the string value. Previously, the separator was ignored. When a buffer-valued variable specifies a separator. the separator appears between pairs of digits, not between digits. For instance if ethaddr is a variable holding #b'08:00:27:79:c7:f5', then the quasiliteral `@ethaddr` produces "08002779c7f" whereas `@{ethaddr ":"}` produces "08:00:27:79:c7:f5". * buf.[ch] (buf_str_sep): New function. * lib.[ch] (fmt_str_sep): New function. * eval.c (fmt_cat): If the argument is a string, and a separator is present, replace the value with the result of calling fmt_str_sep. If the argument is a buffer, and a separator is present, use buf_str_sep to convert to a string, otherwise use tostringp. * txr.1: Section on Output Variables updated. * tests/012/readprint.tl: New tests.
* interpose: use seq_iter and seq_build.Kaz Kylheku2024-05-262-7/+32
| | | | | | | * lib.c (interpose): non-list cases consolidated into one, which uses generic iteration and building. * tests/012/seq.tl: New tests
* quasilit: move separator defaulting to fmt_cat.Kaz Kylheku2024-05-031-4/+5
| | | | | | | | | | | | | | | | | | | | | The motivation here is an upcoming change in which we will support the separator modifier for buffers and strings. Currently, it does nothing. If we write `@{a ":"}`, and a is a buffer or string, the separator is ignored. We don't fix that in this commit, but we fix the problem that some higher level formatting functions are defaulting the separator to " " (single space) and passing it down. We want to control the defaulting based on the type of the object in one place. * eval.c (fmt_cat): Do not assume here that sep has been defaulted; do the defaulting to space here. (format_field, fmt_flex): Initialize the separator to nil, not space. If no separator occurs among the modifiers, it gets passed down as nil through to fmt_cat. (fmt_simple): Don't default the sep argument to space; pass it through to do_format_field which will pass it down to fmt_cat.
* cat-str: grammar in diagnostic.Kaz Kylheku2024-05-031-1/+1
| | | | | * lib.c (cat_str_measure): add missing word "is" in type error message.
* buf: pprint produces hex, not raw bytes.Kaz Kylheku2024-05-034-15/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pprint semantics of buffers is that the raw bytes are dumped into the stream. This is poor. It was hastily designed based on analogy with strings, which pprint by just sending their contents to the stream; but for strings this is justified because they represent text. We also fix the semantics of buffer values being rendered by quasiliteral notation. Currently, the are treated as sequences, and so they explode into individual decimal integers. * buf.c (buf_pprint): Print the bytes as pairs of lower-case hex digits, with no line breaks. In 294 compatibility or lower, put out bytes as before. * eval.c (fmt_cat): When not in 294 compatibility mode, treat a buffer object via tostringp, which will render it to hexadecimal via buf_pprintf. In compatibility mode, treat it as before, which is as a sequence: the individual values of the buffer are converted to text, thus decimal values in the range 0 to 255, catenated using the given separator. * tests/012/readprint.tl: New tests. * txr.1: Documented. Also expanding on what pretty printing means in TXR.
* New function: iter-cat.Kaz Kylheku2024-04-165-0/+129
| | | | | | | | | | | | | | | | * eval.c (eval_init): Register iter-cat intrinsic. * lib.h (struct seq_iter): New union member dargs. (iter_catv): Declared. * lib.c (seq_iter_get_cat, seq_iter_peek_cat): New static functions. (si_cat_ops): New static structure. (iter_catv): New function. * tests/012/iter.tl: New tests. * txr.1: Documented.
* doc: missing word in close-lazy-streams.Kaz Kylheku2024-04-061-3/+4
| | | | | * txr.1: Fix "stream is recorded in a hidden." and revise some neighboring text for clarity.
* compiler: update list of constant and effect-free functions.Kaz Kylheku2024-04-051-25/+28
| | | | | | | | | | | | | | | * stdlib/constfun.tl (%const-foldable-funs%): Numerous functions added, mostly new ones. (%effect-free-funs%): Indentation fixed. Some functions added, but also removed. We don't want anything in here that could take a functional argument. The optimizer will blindly a call to an effect-free function, if its result is not used, regardless of what the arguments are. It won't take into consideration that there is a functional argument, which could be a function that has a side effect, and that is called by the supposedly effect-free function. So for instance, sort is out; the comparison or key functions could have side effects. We could put these functions into a special category.
* doc: command-get-buf syntax.Kaz Kylheku2024-04-041-1/+1
| | | | | * txr.1: Fix bad formatting in syntax synopsis of command-get-buf.
* New functions for filtering through external processes.Kaz Kylheku2024-04-044-0/+171
| | | | | | | | | | | | | | * stdlib/getput.tl (sys:maproc-common): new function. (map-command-lines, map-command-str, map-command-buf, map-process-lines, map-process-str, map-process-buf): New functions. * autoload.c (getput_set_entries): Trigger autoload of getput module on new function symbols. * tests/018/getput.tl: New tests. * txr.1: Documented.
* New function: lcons-force.Kaz Kylheku2024-04-044-0/+46
| | | | | | | | * lib.[ch] (lcons_force): New function. * eval.c (eval_init): Register lcons-force intrinsic. * txr.1: Documented.
* Version 294.txr-294Kaz Kylheku2024-03-177-1006/+1087
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* tests: stability of fini test case.Kaz Kylheku2024-03-171-1/+1
| | | | | | | | * test/012/fini.tl: Pass t to sys:gc to request full garbage collection. Otherwise the output may be reordered, due to some of the objects made earlier in the test case being promoted to the mature generation and thus not finalized by the (sys:gc) call.
* append, nconc; replace implementation with seq_build.Kaz Kylheku2024-03-102-28/+82
| | | | | | | | | | * lib.c (seq_append2, seq_appendv, seq_nconc2, seq_nconcv): New functions. (append2, appendv, nappend2, nconcv): Now implemented using new functions. * lib.h (seq_append2, seq_appendv, seq_nconc2, seq_nconcv): Declared.
* quips: food-related one.Kaz Kylheku2024-03-091-0/+1
| | | | * stdlib/quips.tl (%quips%): Remark about lecithin.
* window-map: condense with seq_iter and seq_build.Kaz Kylheku2024-03-092-82/+53
| | | | | | | | | | | * lib.c (window_map_common): New static function formed from window_map_list. (window_map_list, window_map_vec): Function removed. (window_map, window_mappend, window_mapdo): Simplify to wrappers around window_map_common. * txr.1: Some wording improved in the window-map documentation.
* build: include place.tlo among early tlo's.Kaz Kylheku2024-03-081-1/+2
| | | | | | * Makefile (STDLIB_EARLY_TLOS): Include place.tlo between compiler.tlo and asm.tlo. If place is built late, it has a bad impact on the build time.
* doc: bad syntax under load-for.Kaz Kylheku2024-03-081-1/+1
| | | | * txr.1: fix incorrect markup.
* tests: suppress warnings in seq.tl.Kaz Kylheku2024-03-085-39/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When tests/012/compile.tl compiles tests/012/seq.tl, there are now some compiler warnings due to constant expressions that throw. We introduce a new compiler option to suppress them, and then use it. * stdlib/comp-opts.tl: New file. The definitions related to compiler options are moved here out of compile.tl, so that optimize.tl can use them. * stdlib/compiler.tl (compile-opts, %warning-syms%, when-opt, *compile-opts*, opt-controlled-diag): Moved to comp-opts.tl. New constant-throws option added to compile-opts and %warning-syms%. (safe-constantp): Make the constant expression throws diagnostic conditional on the new option. * stdlib/optimize.tl: Load comp-opts file. (basic-blocks do-peephole-block): Make diagnostic about throwing situation subject to constant-throws option. * tests/012/seq.tl: Turn off constant-throws warning option before the ref tests that work with ranges. Fix: one of the expressions calls refs with the wrong number of arguments, which was unintentional. * txr.1: Document new diagnostic option.
* rfind: use seq_iter.Kaz Kylheku2024-03-071-7/+8
| | | | | | * lib.c (rfind): We combine the default case with SEQ_LISTLIKE and use the seq_iter abstraction rather than car/cdr.
* find: use seq_iter.Kaz Kylheku2024-03-071-41/+21
| | | | | | | * lib.c (find): We retain the optimization for strings when the comparison is regular equality (eq, eql, equal). The other cases are handled by seq_iter rather than separate list-like and vector-like cases.
* doc: improvements in dwim and call documentationKaz Kylheku2024-03-071-4/+18
| | | | | | | | | | | * txr.1: Under call function, document that callable objects need not be functions; the dwim operator description has the details. Fix a formatting problem in the dwim operator syntax synopsis. Under dwim, clarify in more detail that the behavior for various objects are a consequence of their function calling semantics, rather than inherent in the dwim operator.
* New function: rangeref.Kaz Kylheku2024-03-075-5/+173
| | | | | | | | | | | | | | | | | | | | | Because ranges can be iterated like sequences, and are identified as vector-like, they have to support indexing. However, ranges already have semantics as a function: with a sequence argument, they slice it. Let's put the semantics into a function called rangeref, so it can be coherently documented. * eval.c (eval_init): Register rangeref intrinsic. * lib.c (generic_funcall): Range as a function works in terms of rangeref. (ref): Handle RNG case via rangeref. (rangeref): New function. * lib.h (rangeref): Declared. * tests/012/seq.tl: New tests.
* list-vec: replace int type.Kaz Kylheku2024-03-021-2/+2
| | | | | * lib.c (list_vec): use ucnum rather than int for the index and length variables.
* unique: covert to seq_build.Kaz Kylheku2024-03-021-3/+4
| | | | | | * lib.c (unique): Build output using seq_build_t, rather than consing up a list which is then converted to the desired sequence type.
* mapcar: avoid alloca proportional to number of args.Kaz Kylheku2024-03-014-2/+33
| | | | | | | | | | | | | | | * eval.c (MAP_ALLOCA_LIMIT): New preprocessor symbol. (map_common): If the number of args is greater than MAP_ALLOCA_LIMIT, then allocate the array of seq_iter_t structures from chk_malloc rather than alloca. In case an exception might be thrown during the execution of this function, we bind that memory to a buf object. If we return normally, we call the new function buf_free to release it. Otherwise we rely on the garbage collector. * buf.[ch] (buf_free): New function. * tests/012/seq.tl: Test case which hits this behavior.
* zip: make more generic.Kaz Kylheku2024-03-014-48/+120
| | | | | | | | | | | | | | | | * lib.c (do_pa_12_1_v, pa_12_1_v): Static functions removed. (transposev, transpose): Functions removed. * lib.c (transposev, transpose): Declarations removed. * eval.c (join_f): New global variable. (zip_fun, zipv, transpose): New static functions. (eval_init): gc-protect join_f, and initialize it. Registration of zip intrinsic goes to zipv rather than transposev. sys:fmt-join and join registered with help of global join_f rather than local. * tests/012/seq.tl: New zip test cases.
* doc: replace "index-list" with "index-seq".Kaz Kylheku2024-02-291-57/+60
| | | | | | | | * txr.1: All arguments that give a list of indices into a sequence are called index-seq, because they are not required to be lists. Only the COMPATIBILITY section refers to index-list arguments, mentioning that those arguments are now called index-seq.
* partition, split, split*: iter used for indicesKaz Kylheku2024-02-292-37/+43
| | | | | | | | | | | | | | | | | | * lib.c (partition_func, split_func, split_star_func): Indices passed through lazy cons are now iterator, rather than a sequence accessed via car and cdr, which is inefficient for nonlists. (partition-split-common): Use iter-begin to convert indices to iterator, which becomes the cdr field of the lazy cons. * txr.1: Update documentation for these functions to clarify that the second argument is a sequence. The inaccurate text claiming that "if the second argument is an atom other than a function" is rewritten. This doesn't describe the behavior that is implemented, where the test applied is seqp, not atom. The indices can be a vector of integers, which is an atom.
* partition-if: use seq_build for accumulating partitions.Kaz Kylheku2024-02-281-4/+6
| | | | | * lib.c (partition_if_func): Instead of list_collect_decl and make_like, use seq_build.
* partition-by: replace sequence traversal with iter.Kaz Kylheku2024-02-281-10/+13
| | | | | | | | * lib.c (partition_by_func): The seq object is now an iter object: use iter_more, iter_item and iter_step rather than non-null test, car and cdr. (partition_by): Obtain iterator for sequence using iter_begin, and use that in its place.
* partition-by: replace tuple accumulation with seq_build.Kaz Kylheku2024-02-281-6/+7
| | | | | * lib.c (partition_by_func): Use seq_build instead of list_collect_decl and make_like.
* seq_build: seq_pend must be nondestructive for lists.Kaz Kylheku2024-02-282-3/+21
| | | | | | | | | | | | | | | | | | | | Let's have both a seq_pend and seq_nconc, where seq_nconc can reuse the pieces of list passed to it. * lib.h (struct seq_build_ops): New member, nconc. (seq_build_ops_init): Add nconc parameter and initializer. (seq_nconc): Function declared. * lib.c (seq_build_list_pend): Switch to list_collect_append, otherwise mappend behaves destructively. (seq_build_list_nconc): New function. (sb_vec_ops, sb_str_ops, sb_buf_ops, sb_struct_ops, sb_carray_ops): Use seq_build_generic_pend for nconc operation. (sb_list_ops): Use new seq_build_list_nconc for nconc operation. (sb_finished_ops): Use null pointer for nconc operation. (seq_nconc): New function.
* seq_build: convert list buiding to list_collect.Kaz Kylheku2024-02-282-68/+10
| | | | | | | | | | | | | | | | | | | | | | | | | We want to use the list_collect functions for consistency. For instance, these functions allow an atom to be added to an improper list if the terminating atom is a sequence. (append '(1 . "abc") "d") yields (1 . "abcd"). * lib.h (struct seq_build): New member, tail. * lib.c (seq_build_list_add): Use list_collect. (seq_build_list_pend): Use list_collect_nconc. (seq_build_list_finish): Nothing to do here, except call seq_build_convert_to_finished since bu->obj is the head of the list at all times now. (seq_build_improper_add, seq_build_improper_pend): Functions removed. (sb_improper_ops): Structure removed. (seq_build_convert_to_improper): Function removed. (seq_build_convert_to_list): Different strategy needed here now. The list just goes into bu->obj, and we have to set up the tail to either point to the last cons cell's cdr, or else to bu->obj if the list is empty. (seq_build_init): Initialize bu->tail in the three cases that set up list collection.
* seq_build: whitespace.Kaz Kylheku2024-02-281-1/+1
| | | | * lib.c (sb_vec_ops): fix indentation.
* seq_build: remove unnecessary convert calls.Kaz Kylheku2024-02-281-2/+0
| | | | | | * lib.c (seq_build_struct_finish, seq_build_carray_finish): Do not call seq_build_convert_to_finished, since seq_build_list_finish has already done that.
* seq_build: remove one finish function.Kaz Kylheku2024-02-281-6/+1
| | | | | | | | * lib.c (seq_build_improper_finish): Function removed. (sb_improper_ops): Replace seq_build_improper_finish with null pointer. The seq_finish function checks for null and avoids calling, so we don't need the noop implementation.
* seq_build: safeguard against adding to finished object.Kaz Kylheku2024-02-281-0/+14
| | | | | | | | * lib.c (seq_build_convert_to_finished): New function. (seq_build_list_finish): call seq_build_convert_to_finished. (sb_finished_ops): New static struct. All operations except mark are null pointers so this will crash if used.