summaryrefslogtreecommitdiffstats
path: root/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* 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.
* quips: adjust Kant joke.Kaz Kylheku2023-12-061-1/+1
| | | | * stdlib/quips.tl (%quips%): Wording change.
* Version 292.txr-292Kaz Kylheku2023-11-201-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.
* stdlib/error.tl problem rears its head.Kaz Kylheku2023-11-161-25/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* New accessor: mref.Kaz Kylheku2023-11-151-0/+72
| | | | | | | | | | | | | | * 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.
* ref: bugfix in deletion of ref place.Kaz Kylheku2023-11-111-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ref function is not defined in the documentation as an accessor, but there is a ref place. Unfortunately, deletion is broken: (del (ref x y)) does not store the new sequence back into place x, and so it does not work correctly for lists; if x is a list, it doesn't change. Various accessors are defined in terms of ref, as place macros, such as the first, second, third, ... accessors. This fixes the bug for them also; (del (second list)) must update list. * stdlib/place.tl (ref): Fix the delete-expander to fetch the clobber expander of the sequence place, and use the simple setter to put the edited sequence into that place. * tests/012/seq.tl: Test case, which breaks without this fix. Test the (second ...) place also, which is defined in terms of ref. * txr.1: Split documentation for ref and refset, mainly because one is an Accessor and one is a Function. Removing some discussions about the equivalences between DWIM brackets and ref; there are subtleties there not worth going into. Description of refset is simplified. We mention the possibility of del over a ref place; only in that case is the sequence itself required to be a place.
* New macro: tap.Kaz Kylheku2023-11-081-0/+3
| | | | | | | | | | | * autoload.c (op_set_entries): Add tap symbol as autoload trigger for op module. * stdlib/op.tl (tap): New macro. * tests/012/op.tl: New test. * txr.1: Documented.
* quips: philosphy-related joke.Kaz Kylheku2023-11-051-0/+1
| | | | * stdlib/quips.tl (%quips%): New one.
* match: translate some match-case forms into casequal.Kaz Kylheku2023-10-221-20/+43
| | | | | | | | | | | | | | | | | | | The motivation here is that casequal brings in some optimizations not done by match-case, like hashed lookup and jump tables. * stdlib/match.tl (non-triv-pat-t): Move temporary definition higher in file since it is needed earlier in the bootsrapping. (match-case-to-casequal): New function. (match-case): Try converting clauses to casequal with new function. If that returns something, use that as the expansion, otherwise perform the normal expansion. * txr.1: Documentation revised. Existing text is wrong which says that the clauses of a caseq, caseql or casequal are always evaluated sequentially. Furthermore, now that match-case and match-ecase can be transformed to casequal, they also don't necessarily evaluate sequentially. We spell out the conditions under which they may translate.
* Integration with setjmp/longjmp.Kaz Kylheku2023-09-271-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Defining libpng bindings, with longjmp catching, is now possible. * autoload.c (ffi_set_entries): Add setjmp symbol, which is a new macro in stdlib/ffi.tl. * ffi.c (jmp_buf_s): New symbol variable. (mk_jmp_buf, rt_setjmp, longjmp_wrap): New functions. (ffi_init): Initialize jmp_buf_s. Register sys:rt-setjmp and longjmp intrinsics. * ffi.h (jmp_buf_s): Declared. * stdlib/ffi.h (setjmp): New macro. Rather than introducing a new special operator, we use a run-time support function called sys:rt-setjmp, which takes functional arguments. * unwind.[ch] (uw_snapshot, uw_restore): New functions. The rt_setjmp function needs these to restore our unwind frame stack into a sane state after catching a longjmp, which bails without unwinding it, leaving the pointers referring to frames that no longer exist. * tests/017/setjmp.tl, * tests/017/setjmp.expected: New files. * txr.1: Documented.
* New place-mutating macro ensure.Kaz Kylheku2023-09-131-0/+7
| | | | | | | | | * autload.c (place_set_entries): Add ensure as an autoload trigger symbol for the place module. * stdlib/place.tl (ensure): New macro. * txr.1: Documented.
* New glob* function.Kaz Kylheku2023-09-121-0/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The glob* function supports brace expansion, the ** pattern for matching zero or more path components, as well as a sane sort for path names. glob* relies on brace expansion written in Lisp; the ** processing and sorting is done by a glob-compatible C function called super_glob that uses glob. * autoload.c (glob_set_entries, glob_instantiate): New static functions. (autoload_init): Register autoload of stdlib/glob module. * glob.c (GLOB_XNOBRACE, GLOB_XSTAR): New macros. (glob_wrap): Call super_glob instead of glob if GLOB_XSTAR is present in flags. Avoid passing extension flags to glob. (super_glob_find_inner, super_glob_rec, glob_path_cmp, glob_str_cmp, super_glob): New static functions. (glob_init): Register sys:glob-xstar, and glob-xnobrace. sys:glob-xstar is used by glob* to request support for the ** pattern from glob. * stdlib/glob.tl: New file. * tests/018/glob.tl: New file. * txr.1: Documented.
* awk: prn returns nil.Kaz Kylheku2023-08-261-1/+2
| | | | | | | | | * stdlib/awk.tl (awk-state prn): Return nil in the no-argument case instead of returning whatever put-string returns. * tests/015/awk-misc.tl: New file. * txr.1: Documented.
* New macros opf and lopf.Kaz Kylheku2023-08-231-0/+6
| | | | | | | | | | | | | | These remove repetitive (op ...) syntax from the arguments of functional combinators. * stdlib/opt.tl (opf, lopf): New macros. * autoload.c (op_set_entries): Register opf and lopf as autoload triggers. * tests/012/op.tl: New tests. * txr.1: Documented.
* load-args-process: bugfix: :compile action must load.Kaz Kylheku2023-08-221-1/+1
| | | | | | | | | | * stdlib/load-args.tl (load-args-process): When compile-update-file doesn't do anything due to the compiled file being up-to-date, the file must be loaded, so that the effect is similar to compiling. Otherwise subsequent files may fail to compile due to missing definitions such as packages. * txr.1: Documented.
* doc: new hashing scheme for navigation, doc lookup.Kaz Kylheku2023-08-222-2321/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is not an easy change to make because it breaks the validity of existing URLs in the wild which point to specific sections of the TXR manual. Some of my recent changes to capitalization of numerous headings have already broken many URLs, so we might as well bite the bullet and do this now. The problem with the current scheme is that entire section titles are hashed: all the words of a title, not just the names of functions. Whenever we add a new function, macro or variable which is documented together with related functions in the same paragraph under the same heading, the heading changes, and the hash changes. For instance, the hash for the hash-map identifier is actually the hash of the string "Function <tt>hash-map</tt>". Under the new scheme, section titles are hashed in a more complicated way that is robust against most edits. If a title contains any symbols marked up with <tt>, then the leftmost such symbol is taken as the title. Otherwise, the whole title is mapped to lower case. There is no longer a stdlib/doc-syms.tl file, and the special disambiguated "D-<HEX>" codes are also gone. Symbols are no longer associated with section hashes or disambiguation section codes. The hash of a symbol is a 32 bit CRC-32 checksum, expressed as S-<HEX> where <HEX> is 8 hex digits. A section which defines symbols has not only a <a name="..."> for its own hash but also additional <a name="...>" elements for each of the symbols that it defines. If a section defines an ambiguous symbol (one that is also defined with a different meaning in a different section), then that symbol is not linked to either section; it is mapped to the generated disambiguating section. * genman.txr (dupes): Renamed to dupe-hashes for clarity. (tagnum): Hash removed. (direct): New hash. Tracks the assocation between sections hashes and hashes of symbols that are defined only in those symbols (no ambiguity) and thus the symbol hashes can navigate directly to the sections. Serves as a complement to the disamb hash. (colli): There are no collisions now, so initialize this to empty. (hash-str): Function removed. (hash-title): This function becomes more complicated. If a title has at least one <tt>..</tt> item, then that is taken in its place. Either way, the title is transformed and enumerated against duplication and hashed with crc32 instead of the original custom hashing function. (enumerate): Function removed: enumeration of titles is done inside hash-title. All manipulations of symhash using material from HTML now use html-decode, so that we hash the original symbol name like "str<" and not "str&lt;". When filtering the BODY, we have a new case: whenever we see a <a name="...">, we now check the new direct hash to see if there is a list of symbol hashes for the given section. If so, we generate additional <a name="..."> definitions for all the symbol hashes. At the end of the file, the "missing from image" processing is condensed, and the generation of the stdlib/doc-syms.tl file is removed. * stdlib/doc-syms.tl: Removed. * stdlib/doc-lookup.tl: Don't load doc-syms. Use crc32 plus formatting to conver a symbol to the hash that is used in the document and try the lookup with that.
* New function: csort-group.Kaz Kylheku2023-08-172-1/+5
| | | | | | | | | | | | | * autoload.c (csort_set_entries): Register csort-group as autoload trigger for stdlib/csort.tl. * stdlib/csort.tl (csort-group): New function. * tests/012/sort.tl: Tests for sort-group and csort-group. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* doc: massive revision of capitalization in headings.Kaz Kylheku2023-08-161-89/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | In this patch we change the convention of uncapitalized words occurring in headings such as "Special variable *foo*". * checkman.txr (check-var, check-func): Consolidated into a single pattern function called check-coNP. This now enforces capitalization, and also has a giant fall-back clause which explicitly recognizes .coNP headings that are not specially checked by the previous rules, after which there is an error case, so that unclassified .coNP headings are diagnosed. A bug is fixed here in the handling of Special Variable and Variable headings. The pattern match was wrong, so these were not being properly recognized. Without the error case at the end, a number of errors occur in the document where the .desc is missing after a Variable or Special Variable. * txr.1: (.dir, .dirs): Fix capitalization of Directive and Directives in headings generated by this macro. Fix capitalization in numerous .coNP headings. * stdlib/doc-syms.tl: Updated. Unfortunately, many symbols change their hash value because it's based on the entire heading.
* math: tofloat and toint in user-defined arithmetic.Kaz Kylheku2023-08-141-119/+119
| | | | | | | | | | | | | | | | | | * arith.c (tofloat_s, toint_s): New symbol variables. (tofloat, toint): If the argument is a COBJ, handle it via do_unary_method. (arith_init): Initialize new symbol variables. The functions tofloat, toint, tofloatz and tointz. are now registered here, rather than eval_init. * eval.c (eval_init): Remove registrations of tofloat, toint, tofloatz and tointz. * tests/016/ud-arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* listener: auto compound expression mode.Kaz Kylheku2023-08-141-0/+1
| | | | | | | | | | | | | * parser.c (listener_auto_compound_s): New symbol variable. (repl): If *listener-auto-compound-p* is true, then evaluate multiple forms directly as a compound expression, without inserting progn at the head. (parse_init): Initialize symbol variable and register the *listener-auto-compound-p* special. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New feature: local symbol renaming.Kaz Kylheku2023-08-102-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new function use-sym-as can bring a foreign symbol into a package under a different name, which is not that symbol's name. This is also featured in a new defpackage clause, :use-syms-as. With this simple relaxation in the package system, we don't require package local nicknames, which is more complicated to implement and less ergonomic, because it doesn't actually vanquish the use of ugly package prefixes on clashing symbols. * eval.c (eval_init): Register use-syms-as. * lib.c (use_sym_as): New function, made out of use_sym. (use_sym): Now a wrapper for use_sym_as. * lib.h (use_sym_as): Declared. * stdlib/package.tl (defpackage): Implement :use-syms-as clause. * tests/012/use-as.tl: New file. * txr.1: Documented, * stdlib/doc-syms.tl: Updated.
* compiler/match: eliminate (subtypep (typeof x) y).Kaz Kylheku2023-08-092-2/+3
| | | | | | | | | * stdlib/compiler.tl (compiler comp-fun-form): Recognize the pattern (subtypep (typeof x) y) and rewrite it to (typep x y). * stdlib/match.tl (compile-struct-match): Don't generate the (subtype (typeof x) y) pattern, but (typeof x y).
* new: left-inserting pipeline operators.Kaz Kylheku2023-08-082-12/+25
| | | | | | | | | | | | | | | | | | | * stdlib/op.tl (opip-expand): Take arguments which specify the op and do operators to be inserted. Pass these through the recursive calls. (opip, oand): Pass op and do for the new arguments. (lopip, loand): New macros like opip and oand, but passing lop and ldo to the expander. (lflow): New macro. * autoload.c (op_set_entries): Add autoload entries for lopip, loand and lflow. * tests/012/op.tl: A few new tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated.
* compiler: bug: ensure numbers externalized sanely.Kaz Kylheku2023-08-061-0/+3
| | | | | | | | | | | | * stdlib/compiler.tl (dump-to-tlo): To ensure numbers are externalized in such a way that they will be loaded back exactly, we need to set a few special variables. For integers, we want *print-base* to be 10. Numbers printed in other bases cannot be read back correctly. Octal, hex and binary could be, but they would need to be printed with the correct prefixes. For floating-point values, we want to switch to the default print format, and use flo-max-dig for the precision. That one s not not the default value; the default is flo-dig.
* Version 291.txr-291Kaz Kylheku2023-08-061-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: bug: constant folding load-time dregs.Kaz Kylheku2023-08-041-1/+2
| | | | | | | | | | | | | | | | The optimizer eliminates calls to pure library functions when all their arguments are D-registers. The call is made at compiled time and its value is inserted into the program as a constant (in a newly allocated D register). The bug is that we can't do this for a D register that is linked to a load-time value, because we don't know its value until run-time. * stdlib/optimize.tl (basic-blocks do-peephole-block): Add a constraint that none of the D registers can be a member of bb.lt-dregs, which holds the list of D registers that are used for load-time values.
* opip: new special handling of (let ...).Kaz Kylheku2023-08-031-9/+34
| | | | | | | | | | | | | * stdlib/op.tl (sys:opip-single-let-p, sys:opip-let-p): New functions. (sys:opip-expand): Restructure from collect loop to car/cdr recursive form, because the new let operators in opip need access to the rest of the pipeline. Implement let operators. * tests/012/op.tl: New tests. * txr.1: Documented.
* compiler: bug: disappearing basic block nojoin flag.Kaz Kylheku2023-07-311-0/+1
| | | | | | | | | | | Discovered while experimenting with new optimizations. * stdlib/optimize.tl (basic-blocks join-block): When we join the following block into the current block, we must propagate the nojoin property of the following block. The nojoin property has to do with the last instruction being xend. The joined block has that last instruction and so must be nojoin.
* compiler: bugfix: dangling rlinks after dead code eliminationKaz Kylheku2023-07-311-8/+10
| | | | | | | | | | | | | Discovered while experimenting with new optimizations. * stdlib/optimize.tl (basic-blocks :postinit): Pass t argument to new parameter of basic-blocks link-graph. (basic-blocks link-graph): New parameter indicating whether this is the first call; if false, we reset all the links. (basic-blocks elim-dead-code): This no longer has to reset the links before calling link-graph. But now calls link-graph one more time after the dead code removal so that no dead blocks appear in the graph.