summaryrefslogtreecommitdiffstats
path: root/share
Commit message (Collapse)AuthorAgeFilesLines
* tree: replace-tree-iter function.Kaz Kylheku2021-05-111-1/+2
| | | | | | | | | | | | | * tree.c (replace_tree_iter): New function. (tree_init): Register replace-tree-iter intrinsic. * tree.h (tree_init): Declared. * share/txr/stdlib/doc-syms.tl: Updated. * txr.1: Documented. * tests/010/tree.tl: New test case.
* tree: copy-tree-iter function.Kaz Kylheku2021-05-101-1/+2
| | | | | | | | | | | | | | | * lib.c (copy): Handle tree_iter_s via copy_tree_iter. * tree.c (copy_tree_iter): New function. (tree_init): copy-tree-iter intrinsic registered. * tree.h (copy_tree_iter): Declared. * tests/010/tree.tl: New test case. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* tree: new tree-peek function.Kaz Kylheku2021-05-091-3/+5
| | | | | | | | | | | | | | * tree.c (tn_peek_next): New static function. (tree_peek): New function. (tree_init): Register tree-peek intrinsic. * tree.h (tree_peek): Declared. * txr.1: Documented. * tests/010/tree.c: Work tree-peek into existing test case. * share/txr/stdlib/doc-syms.tl: Updated.
* matcher: new "each-match family" of macros.Kaz Kylheku2021-05-042-6/+43
| | | | | | | | | | | | | | | | | | * lisplib.c (match_set_entries): New autoload symbols: each-match, append-matches, keep-matches, each-match-product, append-match-products, keep-match-products. * share/txr/stdlib/doc-syms.tl: Updated. * share/txr/stdlib/match.tl (each-match-expander): New function. (each-match, append-matches, keep-matches, each-match-product, append-match-products, keep-match-products): New macros. * tests/011/patmatch.tl: New tests covering each macro, far from exhaustively. * txr.1: Documented.
* compiler: bug: not warning bad uses of some local funs.Kaz Kylheku2021-05-031-2/+3
| | | | | | | | | | | | | | | | | | When a lexical function defined with flet or labels is called with the wrong arguments, this is not being diagnosed if that function is being lifted to load-time. This is because the sys:load-time-lit that the lambda is wrapped with is not propagating the pars attribute of the frag structure from the lambda to its own returned frag. * share/txr/stdlib/compiler.tl (compiler comp-load-time-lit): After compiling the expression to obtain the exp frag, stuff exp.pars to both the lt-frag that is generated, as well as to the returned dummy frag carrying the dreg access that retrieves the function. It's important for this returned frag to carry the info, because from there it is propagated to the function binding by comp-fbind by the (set bind.pars frag.pars) expression.
* rel-path: bugfixes.Kaz Kylheku2021-05-031-9/+14
| | | | | | | | | | | | | | | * share/txr/stdlib/copy-file.tl: When removing .. components, a dotdot must only cancel preceding non-dotdot. We must check not only that the out stack is not empty but that the top element isn't dotdot. Also, eliminate empty components, like the documentation says. Lastly, we must check for the impossible cases, when the from path uses .. components that are impossible to navigate backwards to form a relative path. * tests/018/rel-path.tl: Test cases added. * txr.1: Updated with additional descriptions, fixes and examples.
* New function: rel-path.Kaz Kylheku2021-05-032-0/+33
| | | | | | | | | | | | | * lisplib.c (copy_file_set_entries): Add rel-path as autoload trigger for copy-file module. * share/txr/stdlib/copy-file.tl (rel-path): New function. * tests/018/rel-path.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* New function: portable-abs-path-p.Kaz Kylheku2021-05-021-1/+2
| | | | | | | | | | | | | | | * share/txr/stdlib/doc-syms.tl: Updated. * stream.c (portable_abs_path_p): New function, exact copy of old abs_path_p. (abs_path_p): Rewritten to be specific to host platform. No Windows-drive-like prefixes are checked on POSIX. (stream_init): Register new function. Register abs-path-p conditionally based on 258 compatibility. * stream.h (portable_abs_path_p): Declared. * txr.1: Documented, with compat notes.
* Version 258txr-258Kaz Kylheku2021-05-011-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated.
* tree: new functions for reseting iterator.Kaz Kylheku2021-04-301-1/+3
| | | | | | | | | | | | | | * tree.c (tree_reset, tree_reset_at): New functions. (tree_init): tree-reset and tree-reset-at intrinsics registered. * tree.h (tree_reset, tree_reset_at): Declared. * tests/010/tree.tl: New tests. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* tree: new tree-begin-at function.Kaz Kylheku2021-04-291-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * tree.c (enum tree_iter_state): New iterator state tr_find_low_prepared dedicated to the tree-begin-at traversal. This state indicates that tree-next should visit the starting node that it is given, and then after that, treat anything to the left of it as having been visited. In the other states, tree-next does not visit the node it is given but uses it as the starting point to find the next node. (tn_find_next): Bugfix here: when navigating the right link, the function neglected to add the node to the path. But the logic for backtracking up the path expects this: it checks whether the node from the path is the parent of a right child. Somehow this didn't cause a problem for full traversals with tree-begin; at least the existing test cases don't expose an issue. It caused a problem for tree-begin-at, though. (tn_find_low): New static function. This finds the low-key node in the tree, priming the iterator object with the correct state and path content to continue the traversal from that node on . We need the tr_find_low_prepared state in the iterator in order to visit the low node itself that was found. (tree_begin_at): New function. (tree_init): Register tree-begin-at intrinsic. * tree.h (tree_begin_at): Declared. * tests/010/tree.tl: New test cases for tree-begin-at. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* tree: more tests.Kaz Kylheku2021-04-291-100/+101
| | | | | | * tests/010/tree.tl: New tests, broadening coverage. * share/txr/stdlib/doc-syms.tl: Regenerated.
* matcher: quasi match incorrectly treats nil as bound.Kaz Kylheku2021-04-261-1/+1
| | | | | | | | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): bound-p local function must return nil if the symbol is nil. * share/txr/stdlib/match.tl: New test cases testing that @nil is treated as an unbound variable in the non-consecutive-variables test. Also, making duplicates of certain tests that start with a text match and sticking @nil as the first element into them, so that the text match is forced to be the second item.
* matcher: use match-str instead of sub-str and str=Kaz Kylheku2021-04-261-4/+4
| | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): Don't extract substrings with sub-str; use match-str to match in-place.
* matcher: bugfix in `text{rest}` case.Kaz Kylheku2021-04-261-2/+2
| | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): Calculate npos correctly relative to current pos. Use match-str rather than starts-with.
* matcher: diagnose unhandled quasiliteral cases.Kaz Kylheku2021-04-261-1/+6
| | | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): Close the gap in the expander by diagnosing all unhandled syntax. There is now enough useful functionality and stability to start documenting the feature.
* match: third round of quasi tests and fixes.Kaz Kylheku2021-04-251-0/+8
| | | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): Add case fo r unbound var followed by var, followed by nothing. * tests/011/patmatch.tl: New tests.
* matcher: use @(as) capture.Kaz Kylheku2021-04-251-4/+5
| | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): Instead of accessing args with car and cadr, capture that part in the match using @(as) and refer to the variable.
* matcher: second round of quasi tests and fixes.Kaz Kylheku2021-04-251-5/+9
| | | | | | | * share/txr/stdlib/match.tl (expan-quasi-match): Use rest variable consistently instead of (cdr args). Two instances of (cdr rest) should just be rest. New case added for variable with no modifiers followed by text being the last item.
* matcher: first round of quasi tests and bugfix.Kaz Kylheku2021-04-251-7/+5
| | | | | | | | | | * share/txr/stdlib/match.tl (expand-quasi-match): The return value of search-str isn't a length but an absolute position. We not only fix a bug, but lose a useless calculation. * tests/011/patmatch.tl: New test cases for quasiliteral patterns, starting with the most rudimentary. Last one broke, due to the above issue.
* matcher: recognize sys:quasi in necessary places.Kaz Kylheku2021-04-251-7/+7
| | | | | | | | | | | * match.tl (compile-cons-structure): Recognize quasi in the middle of cons structure and compile appropriately. (parse-lambda-match-clause): Recognize quasi in dot position properly. (check, check-end): Treat quasi as atom pattern. (pat-len): Recognize quasi in dotted position. (non-triv-pat-p): Handle quasi case. Any quasi containing elements that are lists is nontrivial.
* matcher: turn sys:quasi defmatch into built-in.Kaz Kylheku2021-04-251-36/+44
| | | | | | | | | | | | | | | This not only gets rid of the @ from @`...`, but allows the `` empty pattern `` to work. A bug is also fixed. * share/txr/stdlib/match.tl (compile-match): Recognize list headed by sys:quasi and feed to expand-quasi-match. (sys:quasi): defmatch removed. (expand-quasi-match): Function formed from sys:quasi defmatch. Instead of :form argument, we access *match-form*, like all the other internal functions. Instead of the :env parameter, we use the vars-list object. Using that object's exists method fixed a bug: failing to check for existing variables using boundp.
* matcher: new quasiliteral matching macro.Kaz Kylheku2021-04-241-0/+109
| | | | | | | | * share/txr/stdlib/match.tl (sys:quasi): New defmatch. This is a macro for now, which makes it require the @ prefix: e.g. @`@a-@b-@c`. The plain is to integrate this into the matcher to eliminate that @ prefix. The first priority are test cases and documentation.
* compiler: optimize zero and one item quasiliterals.Kaz Kylheku2021-04-241-1/+4
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (expand-quasi): Do not emit sys:fmt-join call unconditionally. If expand-quasi yields a list of one expression, we can just yield that expression. If the list is empty, we can yield a mutable empty string. (That case will not arise via `` because that converts to "" at read time, but code that generates quasiliteral syntax might have an empty case, and expect a mutable string in all cases).
* Version 257txr-257Kaz Kylheku2021-04-232-3/+3
| | | | | | | | | | | | | | | | | Log message correction superseding original commit 65213f5f7f6a204886a02c32f259ae2617d1dfb6. * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsymc.: Likewise * share/txr/stdlib/doc-syms.tl: Likewise.
* compiler: bug: eliminate-frame not initializing tregs.Kaz Kylheku2021-04-221-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | In eliminate-frame, our stategy of replacing vregs with tregs assumes that the newly minted tregs are initialized to nil. This is true if the block is executed only once, but not true if it's in the middle of a loop, where the previous iteration's treg values can be present. This results in miscompilation of code like (when-match (@x @(all @x)) '(1 (1 2)) x) which wrongly returns 1 instead of nil starting at optimization level 2. * share/txr/stdlib/compiler.tl (struct compiler): New slot, loop-nest, indicating the loop nesting level. (compiler eliminate-frame): add instructions to the start of the block of code to null out all the tregs that we allocated for replacing vregs. We do this only when compiling the repeated parts of a loop, as indicated by a positive value of loop-nest. (comp-for): Increment loop-nest before compiling the repeated parts of the loop; decrement it afterward.
* compiler: bug: graph issue in dead code elimination.Kaz Kylheku2021-04-221-1/+4
| | | | | | | | | | | | | * share/txr/stdlib/optimize.tl (basic-blocks join-block): When we merge a block N with its physical predecessor P, we must iterate over the jump targets of N, and update their reverse list to point to P instead of N. A full call to link-graph would fix it also, but we don't call link-graph anywhere in the optimization pipeline after this point. The reverse links are relied on to be correct elsewhere, such merge-jump-tunks, which needs to walk the blocks which jump to a removed duplicate block, to retarget them to go to another copy of that block.
* compiler: bug: const-folded (call ...) not quoted.Kaz Kylheku2021-04-211-1/+1
| | | | | | | * share/txr/stdlib/compiler.tl (comp-apply-call): When a call expression is evaluated at compile time, we must quote the result, because it could be a non-self-evaluating symbol, or list.
* matcher: defmatch: useful :env parameter.Kaz Kylheku2021-04-211-5/+9
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (compile-match): Pattern macro expanders now have an environment parameter. We turn the list of variables that have been bound so far into a fake macro-time lexical environment, the parent of which is the surrounding environment. The pattern macro can query this using the lexical-var-p function to determine whether a given variable already has a binding, either in the pattern, or in the surrounding lexical environment. (defmatch): Generate a two-argument lambda, and use the new mac-env-param-bind to make the environment object available to the user-defined expansion. * tests/011/patmatch.tl: New test cases for this environment mechanism, and also for defmatch itself. * txr.1: Document role of :env under defmatch.
* compile/eval: new operator, mac-env-param-bind.Kaz Kylheku2021-04-212-2/+15
| | | | | | | | | | | | | | | | | | | | | | mac-env-param-bind is like mac-param-bind but also allows the value for the :env parameter to be specified. * eval.c (op_mac_env_param_bind_s): New sy mbol variable. (op_mac_env_param_bind): New static function. (do_expand): Handle mac_env_param_bind_s. (eval_init): Initialize symbol variable and register macro. * share/txr/stdlib/compiler.tl (compiler compile): Add case for mac-env-param-bind. (compiler comp-mac-env-param-bind): New method. * share/txr/stdlib/doc-syms.tl: Updated with new hashes for tree-bind and mac-param-bind, and inclusion of mac-env-param-bind. * tests/012/binding.tl: New file. * txr.1: Documented.
* quips: two entries in Japanese.Kaz Kylheku2021-04-201-0/+2
| | | | | * share/txr/stdlib/quips.tl (%quips%): Song lyric parody of あなたに夢中 by キャンディーズ.
* matcher: new pattern operator @(end)Kaz Kylheku2021-04-202-44/+53
| | | | | | | | | | | | | | | * share/txr/stdlib/doc-syms.tl: New entry for end. * share/txr/stdlib/match.tl (check, check-end, check-sym, loosen, pat-len): New functions, taken from original local functions of sme macro. (sme): Refactored by hoisting local functions out. Some local variable renaming. (end): New pattern macro. * tests/011/patmatch.tl: New test for end. * txr.1: Documented.
* compile-file: fix bad diagnostic.Kaz Kylheku2021-04-201-1/+1
| | | | | | | * share/txr/stdlib/compiler.tl (open-compile-streams): When the output file cannot be opened, the diagnostic message wrongly refers to the input stream object rather than the output file path.
* matcher: first pattern macro, sme.Kaz Kylheku2021-04-192-1/+47
| | | | | | | | | | | | * lisplib.c (match_instantiate): Intern sme symbol. * share/txr/stdlib/doc-syms.tl: Update with sme entry. * share/txr/stdlib/match.tl (sme): New defmatch macro. * tests/011/patmatch.tl: New tests for sme. * txr.1: Documented.
* defmatch: pass form to mac-param-bind.Kaz Kylheku2021-04-191-1/+1
| | | | | | | | * share/txr/stdlib/match.tl (defmatch): Pass *match-form* to mac-param-bind so that the context is available to defmatch macros via the :form parameter. * txr.1: Documented use of :form in defmatch.
* compile/eval: print compiler error on *stderr*.Kaz Kylheku2021-04-191-1/+4
| | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/error.tl (compile-error): Print the error message on *stderr*, like we do with warnings. This allows the programming environment to pick up the error message and navigate to that line accordingly. The error message is also output by the unhandled exception logic but with a prefix that prevents parsing by the tooling. To avoid sending double error messages to the interactive user, we only issue the *stderr* message if *load-recursive* is true. * tests/common.tl (macro-time-let): New macro. This lets us bind special variables around the macro-expansion of the body, which is useful when expansion-time logic reacts to values of special variables. * tests/012/ifa.tl: Use macro-time-let to suppress *stderr* around the expansion of the erroneous ifa form. We now needs this because the error situation spits out a message on *stderr*, in addition to throwing.
* new: remove superflous prefix from diagnostic.Kaz Kylheku2021-04-191-2/+1
| | | | | * share/txr/stdlib/struct.tl (new-expander): Don't format prefix into error message; compile-error does that.
* matcher: new @(scan) operator.Kaz Kylheku2021-04-182-1/+23
| | | | | | | | | | | | | | * share/txr/stdlib/match.tl (compile-scan-match): New function. (compile-match): Hook scan operator into compiler. * lisplib.c (match_set_entries): Ensure scan is interned in usr package. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated with new entry for scan.
* matcher: allow user-defined patterns via defmatchKaz Kylheku2021-04-172-16/+36
| | | | | | | | | | | | | | | | | * lisplib.c (match_set_entries): Register defmatch and *match-symbol* to autoload match.tl. * share/txr/stdlib/doc-syms.tl: Updated with entries for defmatch and *match-macro*. * share/txr/stdlib/match.tl (*match-macro*): New special variable holding hash. (compile-match): Handle macros via *match-macro* hash. (defmatch): New macro. * txr.1: Documented. * tags.tl: Recognize defmatch forms.
* compiler: bugfix: rest parameter in inline lambdaKaz Kylheku2021-04-111-1/+4
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): Do not take all of the fixed arguments and rest expression to be the trailing list. Rather, skip as many elements from these as the function has fixed parameters. E.g. if there are two fixed parameters as in (lambda (a b . c)) and the call specifies four fixed parameters and a trailing x (1 2 3 4 . x) then the rest argument c must be (list* 3 4 . x) and not (list* 1 2 3 4 . x).
* compiler: bug: symbol not in ffuns in call forms.Kaz Kylheku2021-04-101-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | This bug causes forms like (call (fun 'foo) ...) not to register foo as a free reference in the function space, leading to inappropriate lambda lifting optimizations. The compiler thinks that a lambda is safe to move because that lambda doesn't reference any surrounding lexical functions, which is incorrect. A failing test case for this is (compile-file "tests/012/man-or-boy.tl") at *opt-level* 3 or higher. A bogus error occurs similar to "function #:g0144 is not defined", due to that function being referenced from a lifted lambda, and not being in its scope. * share/txr/stdlib/compiler.tl (compiler (comp-fun-form, comp-apply-call)): Pass the function symbol as an extra argument to comp-fun-form so that it's added to ffuns. (compiler comp-call-impl): Take new optional argument: a symbol to be added to the ffuns slot of the returned fragment, indicating that a function symbol is referenced.
* Version 256txr-256Kaz Kylheku2021-04-071-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated.
* doc: support doc function on android.Kaz Kylheku2021-04-071-2/+2
| | | | | * share/txr/stdlib/doc-lookup.tl (open-url): Define for android, which has xdg-open in the termux environment.
* awk: bugfix: string rs must not compile as regex.Kaz Kylheku2021-04-071-5/+5
| | | | | | | | * share/txr/stdlib/awk.tl (awk-state loop): When rs contains a string, do not pass it directly to regex-compile, because that function calls regex-parse when the argument is a string. Wrap it it a (compound ...) tree node to get it to be treated as sequence of characters to match.
* qref: bugfix: handle a.(b).?c correctly.Kaz Kylheku2021-04-051-1/+1
| | | | | * share/txr/stdlib/struct.tl (qref): Do not assume that (b) is the name of a slot to be looked up. Use qref to handle it.
* struct: fix lack of hygiene in null-safe qref.Kaz Kylheku2021-04-051-1/+3
| | | | | | | | | The expression a.?b is not being treated hygienically; a is evaluated twice. This is only if the null-safe object is the left most; a.b.?c is hygienic. * share/txr/stdlib/struct.tl (qref): Add the necessary gensym use to fix the broken case.
* compiler: remove optional param from lookup-var.Kaz Kylheku2021-04-051-5/+3
| | | | | | * share/txr/stdlib/compiler.tl (struct env): The mark-used optional parameter of lookup-var is not used anywhere, and so always nil. Let's remove it.
* awk: relax restriction on :name.Kaz Kylheku2021-04-041-4/+0
| | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-expander): Do not impose stricter restrictions on :name than the block mechanism itself. * txr.1: Documentation updated.
* lib: new function for documentation lookup.Kaz Kylheku2021-04-032-0/+2076
| | | | | | | | | | | | | | | | * genman.txr: dump contents of symhash into a doc-syms.tl library file, as a defvarl form. * lisplib.c (doc_instantiate, doc_set_entries): New static functions. (lisplib_init): Register autoload for doc-lookup module to symbols doc and *doc-url*. * share/txr/stdlib/doc-lookup.tl: New file. * share/txr/stdlib/doc-syms.tl: Likewise. * txr.1: Documented.
* compiler: incorrect self-check in spy framework.Kaz Kylheku2021-03-301-2/+2
| | | | | | * share/txr/stdlib/compiler.tl (compiler (pop-closure-spy, pop-access-spy)): The stack underflow checkt must be done by checking top, not the incoming spy argument.