summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* get-csv: use unsafe version string-extend.Kaz Kylheku2025-01-301-6/+43
| | | | | | | | | | | | | | | Another almost 16% speedup. * lib.c (us_length_STR): New static function. (string_extend): Use us_length_STR, since we know the object is of type STR. (us_string_extend_STR_CHR): New function. (length_str): Handle STR case via use_length_STR. * lib.h (us_string_extend_STR_CHR): Declared. * stream.c (get_csv): Use us_string_extend_STR_CHR instead of string_extend.
* string-extend: don't use set macro to update length.Kaz Kylheku2025-01-301-1/+1
| | | | | | | * lib.c (string_extend): We know that num_fast + delta is in the fixnum range, because we checked this condition. So we can just assign it without informing the garbage collector. This yields about a 16% speedup in get-csv.
* cobj: optimize subclass checks based on depth 1 assumptionKaz Kylheku2025-01-301-10/+6
| | | | | | | | | | | | | | | | | Nowhere in the image do we have cobj_class inheritance deeper than one. No class has a superclass which itself has a superclass. Based on this, we can eliminate loops coded to handle the general case. * lib.c (sutypep, cobjclassp): Do not iterate to chase the chain of super pointers. Do the subclass check based on the assumption that there is at most a super pointer to class which itself then has no super. (cobj_register_super): Assert if the situation occurs that a class is registered with a super that is not a root. All these calls take place on startup, so if the assumption is wrong, the assert will be 100% reproducible.
* vector: ensure minimum alloc size.Kaz Kylheku2025-01-291-6/+7
| | | | | | | | | | | | | | Like in a recent commit for mkstring, we impose a minimum allocation size of 6 for vectors, which means 8 cells together with the two informaton words at the base of the vector. * lib.c (vec_own): Take an alloc parameter in addition to the length, which is stored in v[vec_alloc]. (vector): Impose a minimum alloc size of 6. (copy_vec, nested_vec_of_v): Pass alloc parameter to vec_own which is the same as the length parameter; i.e. no behavior change for these functions.
* string-extend: grow faster.Kaz Kylheku2025-01-291-2/+2
| | | | | | | * lib.c (string_extend): When more space is needed in the string, grow by 50% rather than 25%. This speeds up code at the expense of some wasted space. Waste space can be dealt with by the final flag in programs where it matters.
* mkstring: minimum 7 char alloc size.Kaz Kylheku2025-01-291-2/+3
| | | | | | * lib.c (mkstring): Do not allocate less than 8 characters, including null terminator, to the string. This speeds up code which builds up strings from empty, one character at a time.
* build: remove HAVE_MALLOC_USABLE_SIZE.Kaz Kylheku2025-01-291-35/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The malloc_usable_size use in the STR type actually makes operations like string_extend substantially slower. It is faster to store the allocated size locally. Originally, on platforms that have malloc_usable_size, we were able to use the word of memory reclaimed from the string type to store a cached hash code. But that logic was revereted in 2022, so there is no such benefit. * configure (have_malloc_usable_size): Variable removed. Test for the malloc_usable_size function removed. (HAVE_MALLOC_USABLE_SIZE, HAVE_MALLOC_NP): Do not define these preprocessor symbols. * lib.c (HAVE_MALLOC_NP_H): Do not test for this variale to include <malloc_np.h> (string-own, string, string_utf8, mkstring, mkustring, string_extend, string_finish, string_set_code, string_get_code, length_str): Eliminate #ifdefs on HAVE_MALLOC_USABLE_SIZE. * lib.h (struct wstring): Eliminate #ifdef on MALLOC_USABLE_SIZE, so alloc member is unconditionally defined on all platforms.
* json: flat must override all effects of :standardKaz Kylheku2025-01-161-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | * stream.h (struct json_opts): Member flat removed. I noticed that !jo.flat was always being tested together with jo.fmt == json_fmt_standard. Except for a few places where the code only tested for json_fmt_standard, resulting in flat output, but some extra spaces. What distiguishes flat mode now is simply that we disable stream indentation. * lib.c (out_json_rec): Remove tests for !jo.flat. (out_json): Remove initialization of jo.flat member. In this function we set up indentation on the stream resulting in multi-line mode (existing behavior). (put_json): Remove initialization of jo.flat member. If flat mode is requested, then it overrides the format to json_fmt_default. I.e. json_fmt_standard coresponding to :standard is only in effect if flat is not requested. In this function we set up indentation on the stream if flat mode isn't requested, otherwise we disable indentation (existing behavior, enough to make flat work). * tests/010/json.tl: Tests for flat mode, :standard formatting, and combinaton of both.
* put_json: bug: incorrect defaulting of flat argument.Kaz Kylheku2025-01-151-2/+3
| | | | | | | | | | this also affects put_jsonl and tojson. * lib.c (put_json): The flat argument must be properly defaulted. Without this we are treating it as true when it is missing due to the convention that missing args are signaled by the : symbol. This bugs breaks the ability to use the :standard value for *print-json-format*.
* Copyright year bump 2025.Kaz Kylheku2025-01-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, alloca.h, args.c, args.h, arith.c, arith.h, autoload.c, autoload.h, buf.c, buf.h, cadr.c, cadr.h, chksum.c, chksum.h, chksums/crc32.c, chksums/crc32.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, gzio.c, gzio.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lex.yy.c.shipped, lib.c, lib.h, linenoise/linenoise.c, linenoise/linenoise.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, psquare.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, socket.c, socket.h, stdlib/arith-each.tl, stdlib/asm.tl, stdlib/awk.tl, stdlib/build.tl, stdlib/cadr.tl, stdlib/comp-opts.tl, stdlib/compiler.tl, stdlib/constfun.tl, stdlib/conv.tl, stdlib/copy-file.tl, stdlib/csort.tl, stdlib/debugger.tl, stdlib/defset.tl, stdlib/doloop.tl, stdlib/each-prod.tl, stdlib/error.tl, stdlib/except.tl, stdlib/expander-let.tl, stdlib/ffi.tl, stdlib/getopts.tl, stdlib/getput.tl, stdlib/glob.tl, stdlib/hash.tl, stdlib/ifa.tl, stdlib/keyparams.tl, stdlib/load-args.tl, stdlib/match.tl, stdlib/op.tl, stdlib/optimize.tl, stdlib/package.tl, stdlib/param.tl, stdlib/path-test.tl, stdlib/pic.tl, stdlib/place.tl, stdlib/pmac.tl, stdlib/quips.tl, stdlib/save-exe.tl, stdlib/socket.tl, stdlib/stream-wrap.tl, stdlib/struct.tl, stdlib/tagbody.tl, stdlib/termios.tl, stdlib/trace.tl, stdlib/txr-case.tl, stdlib/type.tl, stdlib/vm-param.tl, stdlib/with-resources.tl, stdlib/with-stream.tl, stdlib/yield.tl, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, time.c, time.h, tree.c, tree.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, vm.c, vm.h, vmop.h, win/cleansvg.txr, y.tab.c.shipped: Copyright bumped to 2025.
* bug: string range length signed/unsigned.Kaz Kylheku2024-12-161-1/+2
| | | | | | | | * lib.c (length_str_range): On platforms where wchar_t is unsigned, we calculate bogus values for reversed ranges. On Android, gcc warns about the code, and the recently added tests fail. Let's cast the characters to long before doing the subtraction, which is the argument type of labs.
* string ranges: bug: ranges of length 1.Kaz Kylheku2024-12-151-1/+11
| | | | | | | | | * lib.c (seq_iter_init_with_info): String ranges are inclusive. We must not assume at a range whose endpoints are the same is empty; we must check that case for the endpoints being strings. * tests/012/seq.tl: New tests.
* copy: now handles range objects.Kaz Kylheku2024-10-011-0/+2
| | | | | | | | | | | | | | | | Ranges are iterable, denoting abstract sequences. The copy function now copies a range by constructing the array. This is useful when copy is used for the purpose of obtaining a mutable copy. For example, (shuffle 0..100) will now work, returning a shuffled vector of the integers from 0 to 99. * lib.c (copy): Handle RNG case via vec_seq. * tests/012/seq.tl, * tests/012/sort.tl: New test cases. * txr.1: Documented. Documentation for the copy function improved.
* refset, replace: adjust diagnostic for unsupported object.Kaz Kylheku2024-09-301-2/+2
| | | | | | | * lib.c (refset, replace): Word the bad object diagnostic in terms of it not being a modifiable sequence. This covers cases when the object is something abstractly iterable, like a range. We don't want to say that it's not a sequence.
* keep-if, remove-if, keep-keys-if: mapfun argument.Kaz Kylheku2024-07-301-24/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We introduce a mapfun argument to these functions so that they can additionally transform the accumulated values. The keep-keys-if function is now implemented through the same helper function as keep-if but with the mapfun argument defaulting to a copy of the keyfun argument. * eval.c (eval_init): Update registrations of remove-if, keep-if and keep-keys-if to new arities of C functions. * lib.c (rem_if_impl): Implement new optional mapfun parameter. (remove_if, keep_if): Add mapfun parameter. (keep_keys_if): Implement via rem_if_impl, and add mapfun argument. We do the defaulting of keyfun here, so that we can then use that argument's value to default mapfun. * lib.h (remove_if, keep_if, keep_keys_if): Declarations updated. * tests/012/seq.tl: Couple of test cases exercising mapfun argument of keep-if and remove-if. * txr.1: Documented.
* lib: get rid of internal rewindable iter nonsense.Kaz Kylheku2024-07-251-79/+17
| | | | | | | | | | | | | | | | | | | | Iterator rewinding is only used by the three functions isec, isecp and diff, which can easily just re-initialize the iterator. * lib.c (seq_iter_rewind): Static function removed. (seq_iter_init_with_info): Remove support_rewind argument, and adjust all code referencing it on the assumption that it's zero. (seq_iter_init_with_rewind): Static function removed. (seq_iter_init, iter_begin, iter_reset, nullify, find, rfind): Drop last argument from seq_iter_init_with_info. (diff, isec, iescp): Use seq_iter_init rather than seq_iter_init_with_rewind. Instead of seq_iter_rewind, just reinitialize the iterator. * lib.h (seq_iter_init_with_info): Declaration updated. * eval.c (tprint): Drop last argument from seq_iter_init_with_info.
* zip: more permissive implementation.Kaz Kylheku2024-07-241-0/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | zip and transpose should allow non-character data when the leftmost column is a string, falling back on making lists, like seq_build. We can't use seq_build as-is because of the special semantics of transpose/zip with regard to strings. We introduce a "strcat" variant of seq_build for this purpose. * lib.c (seq_build_strcat_add): New static function. (sb_strcat_ops): New static structure like sb_str_ops, but with seq_build_strcat_add as the add operation, which allows string arguments to be appended to the string rather than switching to a list. (seq_build_strcat_init): New function. * lib.h (seq_build_strcat_init): Declared. * eval.c (zip_strcat): New static function; uses seq_build_strcat_init. (zipv): Only recognize strings specially; all else goes through the existing default case. Strings use zip_strcat. * tests/012/seq.tl: New test case. * txr.1: Describe special semantics of zip/tranpose; previously only documented in one example. Clarify that the rows are only sequences of the same kind as the leftmost column if possible, otherwise lists. Remove text which says that it's an error for the other columns to contain non-string, non-character objects if the leftmost column is a string.
* make-like: use seq_build.Kaz Kylheku2024-07-231-40/+19
| | | | | | | | | | | * lib.c (make_like): Simplify implementation using seq_build, which also lets it handle more cases. * tests/012/seq.tl: New tests. Some existing test fixed, including one for tuples*. * txr.1: Documentation updated: mainly that make-like doesn't strictly require a list argument.
* parser: remove some wasteful string object allocations.Kaz Kylheku2024-07-221-4/+10
| | | | | | | | | | | | | | | | * lib.c (int_str_wc): New function, made out of int_str. This can be used by the parser to work with a wchar_t * string without having to create a string object. (int_str): Implemented in terms of int_str_wc. * parser.l (grammar): Remove string_own calls from numerous rule bodies that use int_str to return a number. These rules now capture the wchar_t string, pass it to int_str_wc and then immediately free it. Whereas string_own allocates an extra object and leaves it to the garbage collector. * lex.yy.c.shipped: Regenerated.
* New functions: find-maxes and find-mins.Kaz Kylheku2024-07-161-0/+37
| | | | | | | | | | | * eval.c (eval_init): New intrinsic functions find-maxes and find-mins. * lib.[ch] (find_maxes, find_mins): New function. * tests/012/seq.tl: New tests. * txr.1: Documented.
* json: new special var *print-json-type*.Kaz Kylheku2024-07-121-8/+25
| | | | | | | | | | | | | | | | | | | | This variable controls whether we emit the "__type" key for structures. * lib.c (out_json_rec): React to the new variable, via the flag in the json_opts structure: include the "__type" key only if it is requested. (out_json, put_json): Initialize the type flag in the josn_opts according to the *print-json-type* dynamic variable. * stream.c (print_json_type_s): New symbol variable. (stream_init): print_json_type_s initialized, and corresponding special variable registered, with intial value t. * stream.h (struct json_opts): New bitfield member, type. (print_json_type_s): Declared. * txr.1: Documented.
* New funtion related to where function.Kaz Kylheku2024-07-111-0/+40
| | | | | | | | | | | | | | * eval.c (eval_init): register intrinsics wheref, whereq, whereql and wherequal. * lib.c (wheref_fun): New static function. (wheref, whereq, whereql, wherequal): New functions. * lib.h (wheref, whereq, whereql, wherequal): Declared. * tests/012/seq.tl: New tests. * txr.1: Documented.
* partition, split, split*: bug handling negative indices.Kaz Kylheku2024-07-101-3/+4
| | | | | | | | | | | | | | | | * lib.c (partition_func, split_func, split_star_func): When negative indices occur after the sequence has already been shortened, the conversion to positivce must take into account the base. This must be added so that the positive index produced is relative to the original length of the input sequence. When index_rebased is calculated, the base is subtracted out again. If we based the positive index off the shortened length, it's as if we are subtracting base twice. * tests/012/seq.tl: Dubious test cases for split* are replaced with the new results that make sense. Additional test cases are added which cover this issue, for not only split* but split and partition.
* split, split*: fix poor behavior for beyond-length indices.Kaz Kylheku2024-07-101-6/+8
| | | | | | | | | | * lib.c (split_func, split_Star_func): Ignore indices greater than the length of the sequence, the same as negative indices are ignored which don't become nonnegative after adding the length. * tests/012/seq.tl: Fix questionable test cases, which now confirm the right behavior.
* split**: split for far negative indices.Kaz Kylheku2024-07-101-1/+1
| | | | | | | | | * lib.c (split_star_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in split_func and partition_func in recent commits. * tests/012/seq.tl: Test cases added.
* split: fix for far negative indices.Kaz Kylheku2024-07-101-1/+1
| | | | | | | | | * lib.c (split_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in partition_func in the previous commit. * tests/012/seq.tl: Test cases added.
* split, split*, partition: tests, fixes.Kaz Kylheku2024-07-101-2/+2
| | | | | | | | | | | | | | * lib.c (partition_func): In empty index list case, run the sequence through sub(seq, zero, t) so that ranges are expanded: e.g. 1..3 becomes (1 2). The corresponding code in split_func and split_star_func also needs this fix, but the current test cases don't reproduce a problem. (partition_split_common): Likewise here. * tests/012/seq.tl: Tests for split, split* and partition. Some tests have questionable results. We accept these as they are for now; will address these.
* partition, split, split*: infinite looping regression.Kaz Kylheku2024-07-081-6/+9
| | | | | | | | | | | | | | This is a bug introduced in 9cfa3435 on 2024-02-24. The underlying cause is lack of test coverage for these functions. * lib.c (partition_func, split_func, split_star_func): The original code iterated through the indies using the pop macro, thus extracting the next index and stepping in one step. The iter_begin rewrite wrongly moved the iter_step into one of the cases. The index iteration must be stepped in the case where the loop is continued vi continue, otherwise an infinite loop results.
* sub: don't produce an iterator.Kaz Kylheku2024-07-071-1/+1
| | | | | | | | | | | | | | | | | | | | | Having the sub function yield an iterator in some cases is a defective requirement, causing problems like this: 1> (partition 1..10 '(2 3)) ((1 2) (3) #<seq-iter: a24c380>) With fix: 1> (partition 1..10 '(2 3)) ((1 2) (3) (4 5 6 7 8 9)) * lib.c (sub_iter): When the interval is open and we are operating on a sequence via iter-begin, do not return an iterator. Convert it to a lazy list. Not subjecting this to -C compat flag; I can't imagine anyone writing code to depend on this, rather than stepping around it as a bugx. * txr.1: Documentation updated.
* json: fix flat-p argument in put-json and put-jsons.Kaz Kylheku2024-07-061-33/+35
| | | | | | | | | | | | | | | | The flat-p flag is not being passed through ther recursion. Some of the formatting code emits newlines unconditionally. Instead of passing down the enum json_fmt, we pass down a new structure which carries the flat-p flag also. * stream.h (struct json_opts): New struct. * lib.c (out_json_rec): Take a struct json_opts argument instead of enum json_fmt. Handle the flat flag to avoid generating line breaks. (out_json, put_json): Prepare json_opt structure and pass to out_json_rec.
* json: support printing structs in JSON format.Kaz Kylheku2024-07-061-0/+62
| | | | | | | * lib.c (out_json_sym): New static function. (out_json_rec): Handle structp. * txr.1: Documented.
* New functions: cshuffle and cnshuffle.Kaz Kylheku2024-07-011-6/+26
| | | | | | | | | | | | | | | | | | | These functions find random cyclic permutations. * eval.c (eval_init): Register cshuffle and cnshuffle intrinsics. * lib.c (nshuffle_impl): New static function, formed out of nshuffle. (nhuffle): Now wrapper around nshuffle_impl. (shuffle): Also wraps nshuffle_impl rather than nshuffle. (cnshuffle, cshuffle): New funtions. * lib.h (cnshuffle, cshuffle): Declared. * txr.1: Documented new functions. Also added warning about limitations on permutation reachability in relation to PRNG state size.
* lib: rcyc_cons set type to CONS.Kaz Kylheku2024-06-291-0/+1
| | | | | * lib.c (rcyc_cons): Reset type of recycled cons to CONS, in case the object is a LCONS.
* packages: streamline is-a-string testing.Kaz Kylheku2024-06-271-28/+19
| | | | | | | * lib.c (make_sym, make_package, use_sym_as, find_symbol, find_symbol_fb, intern_intrinsic, intern_fallback_intrinsic): replace stringp test with dummy calls to c_str, for the side effect of the type check.
* iter-begin: handle FLNUM.Kaz Kylheku2024-06-261-0/+6
| | | | | | | | | | * lib.c (iter_begin, iter_more, iter_item, iter_step, iter_reset, copy_iter): Handle FLNUM like NUM, so that we don't wastefully return a dynamic iterator object. * tests/012/iter.tl: Test cases for numeric and character iteration. Test cases for iter-begin on some basic types. copy-iter test for floats.
* lib: replace generic errors with more specific errors.Kaz Kylheku2024-06-201-78/+90
| | | | | | | | | | | | | | | | | | | | * lib.c (unsup_obj, iter_step, last, nthcdr, list_collect, list_collect_nconc, list_collect_append, list_collect_nreconc, list_collect_revappend, nreverse, reverse, replace_list, lazy_appendv, tuples, tuples_star, chk_grow_vec, chk_manage_vec, chk_wrealloc, chk_substrdup, chk_substrdup_utf8, chk_strdup_8bit, chk_xalloc, endp, mkstring, mkustring, string_extend, replace_str, replace_str, cat_str_measure, fmt_str_sep, split_str_keep, spln, tok_str, tokn, cmp_str, int_str, chr_str, chr_str_set, chr_str_set, symbol_package, make_package, use_sym_as, find_symbol, find_symbol_fb, intern_intrinsic, intern_fallback_intrinsic, get_current_package, func_interp, func_get_form, callerror, vec_set_length, vecref, vecref_l, replace_vec, replace_obj, fill_vec, cat_vec, int_cptr, calc_win_size, mismatch, rmismatch, refset, dwim_set, dwim_del, rangeref): Replace error in exceptions with more specific error like type_error, range_error, numeric_error or alloc_error.
* string ranges: individual positions are ascending/descending.Kaz Kylheku2024-06-201-34/+9
| | | | | | | | | | | | | | | | | | | | In this patch we get rid of the wrongheaded notion that a string range, as such, is ascending or descending. In fact, the corresponding character positions are individually ascending or descending. * lib.c (seq_iter_get_range_str): Either increment or decrement the character in the step string depending on whether that position is in order or reversed. (seq_iter_get_rev_range_str): Static function removed. (si_rev_range_str_ops): Static structure removed. (seq_iter_init_with_info): For string ranges, use si_range_str_ops regardless of the strings being lexicographically reversed. * test/012/iter.tl: New test case. * txr.1: Redocumented string ranges.
* length: support string ranges.Kaz Kylheku2024-06-201-1/+39
| | | | | | | | For calculating the length of a range, we can't just do numeric subtractions because it fails for string ranges. * lib.c (length_str_range, length_rng): New static functions. (length): Use length_rng for ranges.
* bugfix: several seq_iter kinds need clone operation.Kaz Kylheku2024-06-181-8/+18
| | | | | | | | | | | | | | Several seq_iter_t kinds of objects cannot be correctly bitwise copied, because they point to an iterator object that cannot be shared. * lib.c (seq_iter_clone_op): New static function. (si_hash_ops, si_tree_ops, si_oop_ops, si_fast_oop_ops): Use seq_iter_clone_op, which uses the copy function to duplicate it->ui.iter after doing a bitwise copy of the structure. * lib.h (seq_iter_ops_init_full): New macro.
* 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-171-10/+35
| | | | | | | | | | * 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-171-14/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-151-0/+16
| | | | | | * eval.c (eval_init): Register copy-iter intrinsic. * lib.[ch] (copy_iter): New function.
* seq_iter: fix inadequate gc marking for some types.Kaz Kylheku2024-06-151-6/+21
| | | | | | | | | | | | * 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-151-8/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* quasiliterals: buffers in hex, separation for strings and buffers.Kaz Kylheku2024-05-271-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-261-7/+21
| | | | | | | * lib.c (interpose): non-list cases consolidated into one, which uses generic iteration and building. * tests/012/seq.tl: New tests
* cat-str: grammar in diagnostic.Kaz Kylheku2024-05-031-1/+1
| | | | | * lib.c (cat_str_measure): add missing word "is" in type error message.
* New function: iter-cat.Kaz Kylheku2024-04-161-0/+64
| | | | | | | | | | | | | | | | * 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.