summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* configure: normalize spacing in diagnosticsPaul A. Patience2024-01-011-14/+14
| | | | | * configure: Add space after ellipses where missing, and prefer putting the space in the initial printf.
* iter_begin: gc problem.Kaz Kylheku2024-01-011-0/+2
| | | | | | | | | | Also affects seq_begin. * lib.c (seq_begin, iter_begin): We must gc_protect the incoming obj also, not only the iter. Both these pointers are in the seq_info_t structure which is no longer used at the time the iterator is being allocated by the call to cobj, and so may be prematurely garbage collected.
* configure: fix for BSD grep.Paul A. Patience2024-01-011-2/+2
| | | | | * configure: Pipe output of strings into grep in endianness test, like is done for ubsan.
* Version 293.txr-293Kaz Kylheku2023-12-286-659/+709
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated.
* build: automate clean-up of shipped scanner and parserKaz Kylheku2023-12-285-9/+44
| | | | | | | | | | * Makefile (shipped): Copy the shipped materials unconditionally, rather than checking if they are different. If a patch exists for a shipped file, then apply it. * lex.yy.c.shipped, y.tab.c.shipped: Updated. * lex.yy.c.patch, y.tab.c.patch: New files.
* read-objects: clean up working, but odd code.Kaz Kylheku2023-12-281-3/+2
| | | | | | | | | | | | | This was prompted by a misleading indentation warning. * parser.c (read_objects_common): The indented statment "return error_return_val;" belongs with the if. This works anyway because if lisp_parse_impl returned unique_s, it means that either pi->syntax_tree is nao, or pi->errors is positive. So, let's take advantage of that and don't bother checking for pi->syntax_tree == nao. If unique_s was returned and there are no errors, we hit EOF and so break out of the loop.
* cygwin: run, sh: mangle termination status word.Kaz Kylheku2023-12-281-0/+10
| | | | | | | | | | * stream.c (run): On Cygwin, the spawnvp function is returning a 16 bit termination status word where the upper 8 bits is the termination status if the termination is normal, otherwise the lower 8 bits holds a termination signal. Let's massage it so that the function returns an integer termnation status, or nil if the termination was abnormal, same as we do on POSIX platforms with fork/wait.
* perm, rperm, comb, rcomb: test generic sequences, bugfixes.Kaz Kylheku2023-12-272-28/+36
| | | | | | | | | | | | | | | | | | | | | | | | perm doesn't generate items of the right type. We need to add the original sequence to the state vector and use make_like. The new generic sequence support in rperm is broken, too. * combi.c (perm_while_fun, perm_gen_fun_common): Rename p variable to vec. (perm_init_common): Rename to perm_init. Take one more argument and store in new fourth element of state vector. (perm_vec, perm_list, perm_str): Pass nil to new parameter of perm_init. (perm_seq_gen_fun): Use perm_list_gen_fun to get list permutations, and coerce each one to the same type as the sequence with make_like. (rcomb_seq_gen_fun): Remove redundant call to rcomb_gen_fun_common. The rcomb_list_gen_fun function is called, which does this already, so we lose every other sequence element. * tests/015/comb.tl: New tests.
* rcomb: support general sequences.Kaz Kylheku2023-12-271-1/+17
| | | | | | * combi.c (rcomb_seq_gen_fun, rcomb_seq): New static functions. (rcomb): Replace error throw in default case with call to rcomb_seq.
* comb: support general sequences.Kaz Kylheku2023-12-271-1/+16
| | | | | | | * combi.c (comb_seq_gen_fun, comb_seq): New static functions. (comb): Call comb_seq in default case rather than throwing error.
* comb: eliminate comb_hash_while_fun.Kaz Kylheku2023-12-271-8/+3
| | | | | | | | * combi.c (comb_hash_while_fun): Function removed. (comb_hash): For the while function, use the unwrapped state, and just comb_while_fun. The augmented state with hash is used only with comb_hash_gen_fun.
* rperm: support general sequences.Kaz Kylheku2023-12-271-6/+23
| | | | | | | | | | | | | | | | * combi.c (rperm_init): Take one more parameter. Allocate the state vector to three elements and put the extra value there. (rperm_list, rperm_vec, rperm_str): Pass nil for the extra value to rperm_init; these do not use it. (rperm_seq_gen_fun, rperm_seq): New functions. These use the extra value to store the original seq in the state, so that the elements of the output sequence can be converted to the same type of sequence as the input. (rperm): Replace error throw in default case with call to rperm_seq.
* rperm: change state representation to vector.Kaz Kylheku2023-12-271-8/+15
| | | | | | | | * combi.c (rperm_init): New static function. (rperm_while_fun, rperm_gen_fun): Retrieve state info from vector-based state rather than cons. (rperm_list, rperm_vec, rperm_str): Call rperm_init to allocate state.
* rcomb, perm, rperm: test.Kaz Kylheku2023-12-271-0/+317
| | | | * tests/015/comb.tl: New tests.
* doc: fix comb reference under rcomb.Kaz Kylheku2023-12-271-1/+1
| | | | | * txr.1: Section describing rcomb function wrongly refers to comb.
* comb: bug: missing combinations.Kaz Kylheku2023-12-262-39/+174
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The comb function is broken; some combinations of items are missing in the output. This is because the iteration reset step in comb_gen_fun_common handles only one column of the state, neglecting to reset the other columns: what is now done by the for (j = i ... loop. I'm changing the representation of the state from a list of lists to a vector of lists. Moreover, it is not reversed. This allows the loop in comb_gen_fun_common to perform random access. * combi.c (k_conses): Return a vector, that is not reversed. (comb_init): New helper function to slightly abstract the use of k_conses. (comb_while_fun): Termination now occurs if the state vector is nil (degenerate case, like k items chosen from n, when k > n), or if the vector has nil in element zero (special flag situation). (comb_gen_fun_common): Rewritten, with correction. The logic is similar. Since we have random access, we don't need the "prev" variable. When we reset a column iterator, we now also populate all the columns to the right of it. For instance, if a given column resets to (a b c), the one to the right must reset to (b c), and so on. In the broken function, this is what was not done, resulting in missing items due to, say, a column resetting to (a b c) but the one next to it remaining at (c). (comb_list_gen_fun): Drop nreverse. (comb_vec_gen_fun, comb_str_gen_fun, comb_hash_gen_fun): Use the same i iterator for the state and the output object, accessing the vector directly. (comb_list, comb_vec, comb_str, comb_hash): Use comb_init. * tests/015/comb.tl: New file.
* perm: support general sequences.Kaz Kylheku2023-12-261-1/+24
| | | | | | * combi.c (perm_seq_gen_fun, perm_seq): New functions. (perm): Call perm_seq in default case to handle more sequence kinds.
* doc: in Math Library mention User-Defined ArithmeticKaz Kylheku2023-12-201-0/+28
| | | | | | | | | * txr.1: The Math Library is documented in a way that is oblivious to User-Defined Arithmetic. This is now clarified. When some of the argument types of a math function are user-defined arithmetic structures, the stated conversions and restrictions don't apply, since it defers all semantics to the method invoked.
* Makefile: operands reversed in abbreviated output.Kaz Kylheku2023-12-201-1/+1
| | | | | | * Makefile (shipped): This rule works correctly but shows, for instance, COPY lex.yy.c.shipped -> lex.yy.c. which is backwards. Let's fix it.
* json: support Lisp comments.Kaz Kylheku2023-12-204-3594/+3645
| | | | | | | | | | | | | | | I've run into situations in which I wanted a comment in a big JSON quasiliteral to explain some embedded piece of code. We support only semicolon comments, and no #; ignore notation. * parser.l (grammar): Recognize Lisp comments in the JSON state also. That does it. * tests/010/json.tl: One modest little test. * txr.1: Documented. * lex.yy.c.shipped: Regenerated.
* compiler: optimizer must watch for throwing constant exprsKaz Kylheku2023-12-202-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have these issues, which are regressions: 1> (compile-toplevel '(/ 1 0)) ** expr-1:1: warning: sys:b/: constant expression (sys:b/ 1 0) throws ** /: division by zero ** during evaluation at expr-1:1 of form (sys:b/ 1 0) 1> (compile-toplevel '(let ((a 1) (b 0)) (/ a b))) ** /: division by zero ** during evaluation at expr-1:1 of form (compile-toplevel [...]) While the compiler's early pass constant folding is careful to detect constant expressions that throw, care was not taken in the optimizer's later constant folding which takes place after constant values are propagated around. After the fix: 1> (compile-toplevel '(let ((a 1) (b 0) (c t)) (if c (/ a b)))) ** expr-1:1: warning: let: function sys:b/ with arguments (1 0) throws #<sys:vm-desc: 9aceb20> 2> (compile-toplevel '(let ((a 1) (b 0) (c nil)) (if c (/ a b)))) #<sys:vm-desc: 9aef9f0> * stdlib/compiler.tl (compiler): New slot top-form. (compile-toplevel): Initialize the top-form slot of the compiler. The optimizer uses this to issue a warning now. Since the warning is based on analyzing generated code, we cannot trace it to the code more precisely than to the top-level form. * stdlib/optimize.tl (basic-blocks): New slot, warned-insns. List of instructions that have been warned about. (basic-blocks do-peephole-block): Rearrange the constant folding case so that as part of the pattern match condition, we include the fact that the function will not throw when called with those constant arguments. Only in that case do we do the optimization. We warn in the case when the function call does throw. A function rejected due to throwing could be processed through this rule multiple times, under multiple peephole passes, so for that reason we use the warned-insns list to suppress duplicate warnings.
* compiler: don't retain last form if it's an atom.Kaz Kylheku2023-12-201-1/+2
| | | | | | * stdlib/compiler.tl (compiler compile): Don't store form into me.last-form if it's an atom; it won't be useful or error reporting.
* New functions: read-objects, file-get-objects, ...Kaz Kylheku2023-12-197-8/+169
| | | | | | | | | | | | | | | | | | | | | | * parser.c (read_objects_common): New static function, formed from read_objects_from-string. (read_objects_from_string): Now wrapper for read_objects_common. (read_objects): New function. * parser.h (read_objects): Declared. * eval.c (eval_init): Register read-objects intrinsic. * autoload.c (getput_set_entries): Add three new symbols: file-get-objects, file-put-objects and file-append-objects. * stdlib/getput.tl (put-objects): New system function. (file-get-objects, file-put-objects, file-append-objects): New functions. * txr.1: Documented. * tests/018/getput.tl: New file.
* hash: new function, hash-join.Kaz Kylheku2023-12-184-0/+90
| | | | | | | | | | | * hash.c (hash_join): New function. (hash_init): hash-join intrinsic registered. * hash.h (hash_join): Declared. * tests/010/hash.tl: New tests. * txr.1: Documented.
* hash: test cases and small doc fix.Kaz Kylheku2023-12-182-1/+22
| | | | | | | * tests/010/hash.tl: Add test cases for the hash set operations. * txr.1: Clarify that in hash-uni, the mapping functions are used on all items, not just ones subject to joinfun.
* hash: rename parameters in declaration.Kaz Kylheku2023-12-181-1/+1
| | | | | | * hash.h (hash_uni): Rename lunitfun and runitfun parameters to the same names as in the definition, which follow the terminology in the manual.
* quips: jealous language quip.Kaz Kylheku2023-12-181-0/+1
| | | | * stdlib/quips.tl (%quips%): New one.
* txr: bug in handling @{nil ...} variable match.Kaz Kylheku2023-12-173-1/+7
| | | | | | | | | | | | | | | | | | | | | | | In March 2012, b7f1f4c5bbea86e288b6a4d68595c1d2d07217bd introduced the feature that the @nil variable matches and discards. This was incompletely implemented. Some cases of a nil variable with modifiers fail to match. * match.c (dest_bind): This function must correctly handle the case when pattern is nil: it should just return bindings without extending them. If the pattern is any nonbindable symbol, it should indicate a failed match using t. The logic has not been touched since 2009, at which time an additional bogosity was introduced of calling funcall(testfun, pattern, value) when pattern is a non-bindable symbol. If value is a string, that could never work. Possibly the idea is that the value could come from a symbol-valued expression, such as one producing a keyword symbol. We are not going to support that, unless someone complains. * tests/000/nilvar.txr, tests/000/nilvar.expected: New files, providing a test case that fails without this commit.
* hash: small fix in function self name.Kaz Kylheku2023-12-111-1/+1
| | | | | * hash.c (gethash_d): Use gethash-d as self rather than gethash_d for consistency.
* listener: fix several bugs in auto compound expr mode.Kaz Kylheku2023-12-111-3/+5
| | | | | | | | | | | | * parser.c (repl): The first bug is that we are not correctly checking the special variable: auto_parens holds the binding. Thus TXR was behaving as if they feature is always enabled. The second bug is that forms might not be a list; it could be the colon symbol, so we cannot evaluate cdr(forms). The third bug is that we don't want to create (progn . :) when forms is the : symbol. These two bugs are reproduced by turning on the mode and evaluating (1 2 3 . 4 5 6), a bad form.
* compiler: handle non-locally-exiting top-level forms.Kaz Kylheku2023-12-111-1/+4
| | | | | | | | | | | | | | * stdlib/compiler.tl (compile-file-conditionally): When evaluation of a compiled top-level form is not suppressed, there is a risk that it can terminate non-locally, via throwing an exception or performing a block return. The compilation of the file is then aborted. We can do better: using an unwind-protect, we can catch all non-local control transfers out of the form and just ignore them. The motivation for this is that it lets us compile files which call (return-from load ...), without requiring that it be written as (compile-only (return-from load ...)). Other things will work, like compiling a (load "foo") where foo doesn't exist or aborts due to errors.
* load: load block value should be exit status.Kaz Kylheku2023-12-117-11/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When TXR executes a top-level program, such that it will exit when the last form in that program terminates, it simulates a load. There is a block named load visible, and the program can evaluate a (return-from load <expr>). The value of that <expr> is thrown away, and the termination status is always unsuccessful. In this patch, (return-from load <expr>) is made to work such that the value of <expr> will determine the exit status, according to the same interpretation that (exit <expr>) would give to the value. * sysif.[ch] (exit_wrap): Static function becomes external. * txr.c (txr_main): In the cases where we execute a file and return from main, we now call exit_wrap instead. The termination status is not simply based on whether the file was successfully read, but takes into account the load block. * tests/019/load-ret/{script.tl,bad.tl}: New files. * tests/019/load-ret/load-ret.tl: New tests. * txr.1: Documented.
* print: print/read consistency problem with rcons.Kaz Kylheku2023-12-082-1/+11
| | | | | | | | | | * lib.c (obj_print_impl): Do not print (rcons X Y) as X..Y if X looks like (rcons ...). This causes the problem that (rcons (rcons 1 2) 3) prints as 1..2..3, a notation which unambiguously means (rcons 1 (rcons 2 3)). * tests/012/syntax.tl: New test cases.
* quips: adjust Kant joke.Kaz Kylheku2023-12-061-1/+1
| | | | * stdlib/quips.tl (%quips%): Wording change.
* doc: fix "an" typos.Kaz Kylheku2023-12-031-13/+13
| | | | | * txr.1: Fix numerous "an" articles that should be "a", as well as one case of "and" missing a "d".
* doc: quasiquote: note about special quote splice.Kaz Kylheku2023-12-031-0/+44
| | | | | | | | * txr.1: Add dialect note about TXR supporting ,',*args whereby multiple items get spliced into a quote, which effectively distributes into multiple quotes. The direct equivalent does not work in all Common Lisp implementations, and doesn't appear to be required by the standard.
* doc: typo under rlink.Kaz Kylheku2023-11-251-1/+1
| | | | * txr.1: fix transposition: "ot" -> "to".
* sh-esc: clean up mess I made.Kaz Kylheku2023-11-253-31/+113
| | | | | | | | | | | | | | | | | | | | | | Not all special characters can just be backslash escaped. Spaces and newlines must be quoted. * stream.c (sh_esc_common): New function. Handles both sh-esc and sh-esc-all logic, distinguished by a flag. Quoting is used, rather than backslash escaping. If the string contains no special characters, it is just erturned. If it can be double quoted, it is double quoted. Otherwise it is single quoted and any contained single quotes are replaced by '\''. (sh_esc, sh_esc_all): Now just wrap sh_esc_common. (sh_esc_dq): Remove the newline from the set of escaped characters. Escaping a newline generates a continuation sequence which eats the newline. * tests/018/sh-esc.tl: Most test cases deleted; many new test cases added. * txr.1: Documentation revised.
* glob: suppress consecutive duplicates; fix memleak.Kaz Kylheku2023-11-222-12/+23
| | | | | | | | | | | | | | | | | | | * glob.c (glob_wrap): When converting the glob array to the returned list, suppress consecutive duplicates. This has to be done separately for each call to glob or super_glob, so we now interleave the production of the output list with the glob calls. It has to be done separately because there can be duplicates between different patterns. E.g. if (glob "?") matches one path then (glob '("?" "?")) must return two copies of it. Furthermore, the brace expansion implementation in glob* produces multiple glob calls and appends their results. Duplicates inside a single super_glob call result when there are multiple ** (double star) patterns present, which are matched by the same path in more than one way. If the results are sorted, then the duplicates appear consecutively and we will squash them. Also, a memory leak is fixed here: we must free(pat_u8) unconditionally, before testing for the early exit situation.
* tests: fix FFI libpng setjmp test case for Solaris 10.Kaz Kylheku2023-11-201-1/+2
| | | | | | | * tests/017/setjmp.tl: Solaris has libpng.so, but but some version without png_set_longjmp_fn. We add a test for the presence of this function as a precondition for running the real test.
* Version 292.txr-292Kaz Kylheku2023-11-207-1233/+1412
| | | | | | | | | | | | | | * 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.
* time: bug: must subtract gmtoff, not add.Kaz Kylheku2023-11-192-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This works fine: 1> (time-struct-utc 0) #S(time year 1970 month 1 day 1 hour 0 min 0 sec 0 wday 4 yday 0 dst nil gmtoff 0 zone "GMT") 2> *1.(time-utc) 0 3> *1.(time-local) 28800 But we want the following to return the same results: 1> (time-struct-local 0) #S(time year 1969 month 12 day 31 hour 16 min 0 sec 0 wday 3 yday 364 dst nil gmtoff -28800 zone "PST") 2> *1.(time-utc) -57600 3> *1.(time-local) -28800 With the patch, we do: 1> (time-struct-local 0) #S(time year 1969 month 12 day 31 hour 16 min 0 sec 0 wday 3 yday 364 dst nil gmtoff -28800 zone "PST") 2> *1.(time-utc) 0 3> *1.(time-local) 28800 This is also broken: 1> (time-parse-utc "%H:%M:%z" "00:00:-0800") -28800 It must return 28800. * time.c (time_meth): This function, which is the imlpementation of the time-utc and time-local methods, must subtract the gmtoff field, not add it. This is so that a UTC time expressed in a local time zone will convert back to the correct UTC epoch. (time_parse_local, time_parse_utc): Here we likewise must subtract the gmtoff.
* stdlib/error.tl problem rears its head.Kaz Kylheku2023-11-163-36/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There used to be a hack in the Makefile whereby the compilation of stdlib/error.tl was forced to occur earlier. I got rid of it. Now, the issue that was solving reproduced. A situation can occur whereby loading error.tl triggers loading some other files, which end up performing an expansion that needs sys:bind-mac-check: but that function has not yet been defined because error.tl has not yet loaded that far. The issue occurs when stdlib/place.tl is compiled before stdlib/error.tl. The compiled place.tl has a run-time dependency on functions in error.tl, because the compiled version of mac-param-bind and other forms relies on a run-time support function sys:bind-mac-check defined in stdlib/error.tl. * stdlib/error.tl (sys:dig): This function triggers the problem, but it's not the only cause. Here, the problem is because the (set ...) macro is used which triggers loading the stdlib/place module. That brings in the need for bind-mac-params. So here we use sys:setq instead. That is not a complete solution. The changes in eval.c are also required, because built-in macros like whilet expand to code that uses the (set ...) macro. Note how sys:dig uses whilet. (sys:bind-mac-check, sys:bind-mac-error): We move these functions above compile-warning. This addresses remaining circularity problem. The compile-warning function uses the catch macro which brings in stdlib/except.tl, which pulls in stdlib/op.tl due to its use of (do ...), which pulls in stdlib/place.tl. So if we already define sys:bind-mac-check at that point, we are good. * eval.c: Sweep the file for almost all places where macros generate code that invokes (set <symbol> <value>) and replace that with (sys:setq <symbol> <value>) to eliminate the dependency on loading the stdlib/place.tl module. (me_def_variable, me_gun, me_while_until_star, me_case, me_whilet, me_mlet, me_load_for, me_pop_after_load): In all these macro expanders, use sys:setq rather than set in the generated code. * tests/019/load-hook.tl: Some test cases here look for a macro expansion containing (set ...), needing to be fixed to look for (sys:setq ...) due to the change in eval.c.
* doc: incorrect description of rlink.Kaz Kylheku2023-11-151-3/+7
| | | | | * txr.1: The rlink function resolves the target path if it is a symlink, not the new link's path.
* doc: fix wrong typesetting of nil and t.Kaz Kylheku2023-11-151-13/+13
| | | | | | | | * txr.1: Fix numerous occurrences of nil and t being typeset using "meta" rather than "code". That makes them slanted in the HTML and PDF, and appear in angle brackets as <nil> and <t> in text-based man output. We want a non-slanted type, and no angle brackets for these.
* oop: allow del on struct sequences.Kaz Kylheku2023-11-153-4/+63
| | | | | | | | | | * lib.c (dwim_del): Remove check against structures from OBJ case; we just let this pass through to the logic that invokes replace. * tests/012/aseq.tl: New test cases. * txr.1: Document how del works on a [obj index] place.
* oop: segfault in special methods cache.Kaz Kylheku2023-11-152-11/+34
| | | | | | | | | | | | | * struct.c (invalidate_special_slots): New static function. (invalidate_special_slot_nonexistence): Move static function up in file, to be next to invalidate_special_slots. (make_struct_type, static_slot_ens_rec): Call the new invalidate_special_slots function in addition to calling static_slot_home_fixup whenever the stslots array is resized. The spslot array contains pointers to the elements of stslots, which become invalid when that is resized. * tests/012/oop-seq.tl: Repro test case added.
* dwim: correction to error diagnostic.Kaz Kylheku2023-11-151-1/+1
| | | | | | | * lib.c (dwim_set): The "not a place" diagnostic applies not only in situations when the object is a list; the diagnostic should not imply that the argument is a list when it isn't.
* New accessor: mref.Kaz Kylheku2023-11-156-0/+308
| | | | | | | | | | | | | | * eval.c (eval_init): Register mref intrinsic. * lib.[ch] (mref): New function. * stdlib/place.tl (sys:mref1): New place. (mref): New place macro, defined in terms of sys:merf1, ref place and mref function. * tests/012/seq.tl: New tests. * txr.1: Documented.
* place: bad indentation.Kaz Kylheku2023-11-131-9/+9
| | | | * stdlib/place.tl (dwim): Fix incorrect indentation.