summaryrefslogtreecommitdiffstats
path: root/stdlib
Commit message (Collapse)AuthorAgeFilesLines
...
* infix: adjust operator expected diagnostic.Kaz Kylheku2025-04-041-1/+1
| | | | | | | | | * stdlib/infix.tl (parse-infix): The operator expected diagnostic can occur not just before an an operand, but before an prefix operator. For instance "a cos b". An operator is expected between a and cos. We don't want to say "before operand cos" because cos is an operator.
* Initial implementation of infix expressions.Kaz Kylheku2025-04-031-0/+174
| | | | | | | | | | | | | | | | The infix module provides a macro called ifx. Forms (evaluated expressions) enclosed inside ifx at any nesting level, which are not special operator or macro forms, are subject to automatic detection of an infix notation, which is transformed into regular Lisp. The notation is based on Lisp atoms; no read syntax is introduced. Infix may be freely mixed with ordinary Lisp. * autoload.c (infix_set_entries, infix_instantiate): New static functions. (autoload_init): Register new infix module for autoload. * stdlib/infix.tl: New file.
* match: new pattern matching macro, match-tuple-case.Kaz Kylheku2025-04-011-0/+3
| | | | | | | | | | | | | * autolod.c (match_set_entries): Autoload match module on match-tuple-case. * match.tl (match-tuple-case): New macro. * tests/011/patmatch.tl: New tests. The macro is trivial; if lambda-match works, the macro works. * txr.1: Documented.
* New function keep: generalized keepqual.Kaz Kylheku2025-03-281-0/+1
| | | | | | | | | | | * eval.c (eval_init): Register keep intrinsic. * lib.[ch] (keep): New function. * stdlib/compiler.tl (compiler comp-fun-form): Transform two argument keep to keepqual. * txr.1: Documented.
* compiler: reduce some equal-based sequence functions.Kaz Kylheku2025-03-281-0/+5
| | | | | | | | | | | | | | | * stdlib/compiler.tl (compiler comp-fun-form): Recognize two-argument forms of remove, count, pos, member and subst. When these don't specify test, key or map functions, they are equivalent to remqual, countqual, posqual, memqual and subqual. These functions are a bit faster because they have no arguments to default and some of their C implementations call the equal function either directly or via a pointer, rather than via going via funcall. The exceptions are posqual and subqual which actually call pos; but even for these it is still slightly advantageous to convert to to the fixed arity function, because funcall2 doesn't have to default the optional arguments with colon_k.
* place: fix bad indentation.Kaz Kylheku2025-03-111-4/+4
| | | | | | * stdlib/place.tl (sys:placelet-1): Fix a misindented call-update-expander function call. Also indent its arguments in function style.
* Expose brace expansion bexp function.Kaz Kylheku2025-03-091-2/+2
| | | | | | | | | | | | | | | | | * autoload.c (glob_set_entries): Remove autoload on sys:brace-expand. Add usr:exp. * stdlib/glob.tl (brace-expand): Renamed to usr:bexp. (glob*): Call bexp rather than brace-expand. * tests/018/glob.tl: Rename references to sys:brace expand to bexp. * txr.1: Add section describing the bexp function. Move brace expansion documentation from glob* to this new section, adjusting the wording a little bit, mainly to avoid referring to "patterns". Point glob* documentation to bexp, which also in turn references glob*.
* glob*: add string and integer ranges to brace expansion.Kaz Kylheku2025-03-081-11/+45
| | | | | | | | | | | | | | | | * stdlb/glob.tl (bexp-parse): Recognize .. as a token. (bexp-parse-brace): If a brace expansion doesn't contain commas, then check whether it contains .. and that its elements are all strings. In that case it is a possible range expansion and we thus transform it to a (- ...) node, subject to more validation in bexp-expand. (bexp-expand): Add casees to handle range expansion, taking care that invalid forms translate to verbatim syntax. * tests/018/glob.tl: New tests. * txr.1: Documented.
* Version 299.txr-299Kaz Kylheku2025-02-161-1/+1
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated.
* awk: add CSV support.Kaz Kylheku2025-01-301-0/+8
| | | | | | | | | | | * stdlib/awk (awk-state upd-rec-to-f): Handle a new case of fs being the keyword symbol :csv, producing a field-splitting lambda that calls get-csv. * tests/015/awk-basic.tl: Several new test cases for this CSV feature. * txr.1: Documented.
* awk: use prepared lambdas for field separation.Kaz Kylheku2025-01-281-64/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle field separations with lambdas, similarly to record separation. The idea is that we replace the rec-to-f method, which contains a cond statement checking the variables for which field separation discipline applies, with a lambda which is updated whenever any of those ariables change. * awk.tl (awk-state): New instance slot, rec-to-f. (awk-state :postinit): Call new upd-rec-to-f method so that rec-to-f is populated with the default field separating lambda. (awk-state rec-to-f): Method removed. (awk-state upd-rec-to-f): New method, based on rec-to-f. This doesn't perform the field separation, but returns a lambda which will perform it. (awk-state loop): We must call upd-rec-to-f whenever we change par-mode, because it influences field separation. (awk-mac-let): Replace the symbol macros fs, ft, fw and kfs with new implementations that use the reactive slot mechanism provided by rslot. Whenever the awk macro assigns any of these, the upd-rec-to-f method will be called. * tests/015/awk-basic.tl: New file. These basic tests of field separation pass before and after this change. * tests/common.tl (otest, motest): New macros.
* get-csv: rewrite in C.Kaz Kylheku2025-01-211-74/+0
| | | | | | | | | | | | | | * autload.c (csv_set_entries, csv_instantiate): Functions removed. (autoload_init): Autoload registration for stdlib/csv removed. * stdlib/csv.tl: File removed. * stream.c (get_csv): New function. (stream_init): Register get-csv intrinsic. * stream.h (get_csv): Declared.
* get-csv: use symbols for states.Kaz Kylheku2025-01-211-45/+44
| | | | | | * csv.tl (get-csv): Since there are only three states, there is no jump table optimization. We might as well use keyword symbols for the states rather than integers.
* get-csv: simplify implementation by CR-LF folding.Kaz Kylheku2025-01-211-30/+7
| | | | | | | | | * stdlib/csv.tl (get-csv): Pre-process the input by a small state machine that maps CR-LF sequences to LF. Then we don't have to recognize #\return anywhere in the state machine and can delete the cr and qcr states, as well as all the code recognizing #\return and branching to those states.
* New function: get-csv.Kaz Kylheku2025-01-211-0/+98
| | | | | | | | | | | | | * autloload.c (csv_set_entries, csv_instantiate): New static funtions. (autoload_init): Register autoload of stdlib/csv module via new functions. * stdlib/csv.tl: New file. * tests/010/csv.tl: Likewise. * txr.1: Documented.
* New macros for enumerated constants.Kaz Kylheku2025-01-201-0/+46
| | | | | | | | | | | | | * autoload.c (enum_set_entries, enum_instantiate): New static functions. (autoload_init): Register autoload of stdlib/enum module via new functions. * stdlib/enum.tl: New file. * tests/016/enum.tl: Likewise. * txr.1: Documented.
* lflow/lopip: optimize one argument situations via lop1.Kaz Kylheku2025-01-171-21/+25
| | | | | | | | | | | | | | | | | | | | | | | In an opip pipeline, only the first pipeline element can receive multiple arguments. The subsequent elements receive the single return value from the previous element. Therefore if it is a left-inserting pipeline created by lopip, only the first element needs to use lop. The others can use lop1, resulting in an optimization. Furthermore in the flow/lflow macros, even the first function in the pipeline is called with one argument: the result of the input expression. So the case of lflow, every element of the pipe that would translate to lop can go to lop1 instead. * stdlib/opt.tl (sys:opip-expand): Calculate a local variable called opsym-rest which determines which op symbol we use for the recursive call. This is the same as the incoming opsym, except in the case when opsym is lop, in which case we substitute lop1. (sys:lopip1): New macro, like lopip but uses lop1 for the first element also. (lflow): Expand to sys:lopip1 rather than lopip.
* New macro: lop1.Kaz Kylheku2025-01-171-1/+11
| | | | | | | | | | | | | * autoload.c (op_set_entries): Autoload on lop1 symbol. * stldlib/op.tl (sys:op-expand): Add lop1 case. (sys:opip-expand): Add lop1 to the list of operators that are recgonized and specially treated. (lop1): New macro. * tests/012/op.tl: New tests. * txr.1: Documented.
* lop: don't insert args when metas present.Kaz Kylheku2025-01-081-4/+8
| | | | | | | | | | | | | | | | | | | | | The lop macro is inconsistent from op in that it inserts the trailing function arguments on the left even if arguments are explicitly given in the form via @1, @2, ... or @rest. This change makes lop is equivalent to op in all situations when these metas are given. * stdlib/op.tl (compat-225, compat-298): New top-level variables. (op-expand): local variable compat replaced by references to compat-225. If compat-298 is *not* in effect, then metas are checked for first in the cond, preventing the lop transformation from taking place. * tests/012/op.tl: Test cases for lop, combinations of do with lop and a few for op also. * txr.1: Redocumented, added compat notes.
* Copyright year bump 2025.Kaz Kylheku2025-01-0149-49/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* match-case: bugfix in conversion to casequal.Kaz Kylheku2024-12-201-2/+0
| | | | | | | | | | | | | * stdlib/match.tl (match-case-to-casequal): the (do inc dfl-cnt) action has a problem: it inserts an implicit extra parameter to the invocation of inc, which crashes the + addition due to that parameter being the matching @nil object. We don't need this entire case because it handles @nil, which also matches the following case for (sys:var ...), since @nil is (sys:var nil). That case ahs the same action of incrementing dfl-cnt. * tests/011/patmatch.tl: Test case added.
* Version 298.txr-298Kaz Kylheku2024-12-171-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date.
* Version 297.txr-297Kaz Kylheku2024-12-161-1/+1
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated.
* quips: jab at Weller.Kaz Kylheku2024-12-081-0/+1
| | | | * stdlib/quips.tl (%quips%): New one.
* quips: new one.Kaz Kylheku2024-09-031-0/+1
| | | | * stdlib/quips.tl (%quips%): New entry.
* Version 296.txr-296Kaz Kylheku2024-08-071-1/+1
| | | | | | | | | | | | | | * 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.
* struct: slot warning only for bindable symbols.Kaz Kylheku2024-07-171-1/+2
| | | | | | * stdlib/struct.tl (sys:check-slot): Don't issue the diagnostic "<obj> isn't the name of a struct slot" for slots that are not bindable symbols like obj."abc".
* Version 295.txr-295Kaz Kylheku2024-06-281-1/+1
| | | | | | | | | | | | | | * 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.
* match: new @(scan-all) operator.Kaz Kylheku2024-06-281-0/+28
| | | | | | | | | | | | | | | | This is like @(scan) but collects all matches over the suffixes of the list. * autoload.c (match_set_entries): Intern scan-all symbol. * stdlib/match.tl (compile-scan-all-match): New function. (compile-match): Dispatch compile-scan-all-match on scan-all symbol. * tests/011/patmatch.tl: Tests for scanall and also missing tests for scan. * txr.1: Documented.
* match: bad indentation.Kaz Kylheku2024-06-271-4/+4
| | | | | * stdlib/match.tl (compile-scan-match): Fix wrong indentation of let* body.
* quips: remove weak one.Kaz Kylheku2024-06-151-1/+0
| | | | | * stdlib/quips.tl (%quips%): Remove quip about lecithin; it does not wear well.
* 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.
* New functions for filtering through external processes.Kaz Kylheku2024-04-041-0/+46
| | | | | | | | | | | | | | * 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.
* Version 294.txr-294Kaz Kylheku2024-03-171-1/+1
| | | | | | | | | | | | | | * 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.
* quips: food-related one.Kaz Kylheku2024-03-091-0/+1
| | | | * stdlib/quips.tl (%quips%): Remark about lecithin.
* tests: suppress warnings in seq.tl.Kaz Kylheku2024-03-083-37/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* quips: new Lisp entry.Kaz Kylheku2024-02-181-0/+1
| | | | * quips.tl (%quips%): New dad humor.
* compiler: use cons-count.Kaz Kylheku2024-02-091-1/+1
| | | | | | * stdlib/compiler.tl (simplify-variadic-lambda): Use cons-count to find occurrences of the rest variable rather than flatten and count.
* compiler: take advantage of fixed @(end) match.Kaz Kylheku2024-02-081-2/+1
| | | | | | * stdlib/compiler.tl (simplify-variadic-lambda): Remove work-around where two patterns are combined with or, expressing it the way it wants to be.
* match: remove bad restriction from @(sme) and @(end).Kaz Kylheku2024-02-081-13/+5
| | | | | | | | | | | | | | | | | | | | | | | | The end pattern in @(sme) and @(end) does not have to be a list pattern, dotted or otherwise. It should support any pattern whatsoever for a single object, which should match the terminating atom. The documentation says that, though not very clearly; it is reworded also. * stdlib/match.tl (check-end): Remove this function, since the end pattern can be any pattern. (pat-len): Bugfix: we are using the meq function incorrectly. The object being compared against several alternatives must be the leftmost argument of meq. This bug prevents a pattern like @(evenp @x) to be correctly considered of length zero. (sme, end): Remove calls to check-end, and just refer to original end variable. * tests/011/patmatch.tl: New tests. * txr.1: clarify that the end pattern may be any pattern, which can match just the terminating atom or a possibly dotted suffix.
* compiler: inlined chain: simplify variadic lambdas.Kaz Kylheku2024-02-081-2/+15
| | | | | | | | | | | | | | | The opip syntax often generates lambdas that have a trailing parameter and use [sys:apply ...]. This is wasteful in the second and subsequent argument positions of a chain, because we know that only a single value is coming from the previous function. We can pattern match these lambdas and convert the trailing argument to a single fixed parameter. * stdlib/compiler.tl (simplify-variadic-lambda): New function. (inline-chain-rec): Try to simplify every function through simplify-variadic-lambda. The leftmost function is treated in inline-chain, so these are all second and subsequent functions.
* compiler: implement inlining for chain expressions.Kaz Kylheku2024-02-071-1/+34
| | | | | | | | | | | | | | | | | | | | The opip syntax and its variants transforms into chain expressions. Currently, we emit actual chain function calls, and so all the chain arguments that are lambda expressions have become closures. In this commit, an inlining optimization is introduced which turns some chain function calls into chained expressions. The lambdas are then immediately called, and so succumb to the lambda-eliminating optimization. * stdlib/compiler.tl (compiler comp-fun-form): Handle chain forms. At optimization level 6 or higher, if the form is eligible for the transform, perform it. (inline-chain-rec, can-inline-chain, inline-chain): New functions. * txr.1: Mention that *opt-level* 6 does this chain optimization.
* compiler: whitespace issue.Kaz Kylheku2024-02-071-1/+1
| | | | | * stdlib/compiler (lambda-apply-transform): Fix misleading indentation.
* quips: new bad pun.Kaz Kylheku2024-01-201-0/+1
| | | | * stdlib/quips.tl (%quips%): New entry.
* Copyright year bump 2024.Kaz Kylheku2024-01-1848-48/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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, lib.c, lib.h, linenoise/linenoise.c, linenoise/linenoise.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, 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/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 year bumped to 2024.
* Version 293.txr-293Kaz Kylheku2023-12-281-1/+1
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: 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-191-0/+17
| | | | | | | | | | | | | | | | | | | | | | * 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.
* quips: jealous language quip.Kaz Kylheku2023-12-181-0/+1
| | | | * stdlib/quips.tl (%quips%): New one.