summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* matcher: left-to-right scoping for @(and).Kaz Kylheku2021-02-062-26/+33
| | | | | | | | | | | | | | And binds left to right now; only or is parallel. * share/txr/stdlib/match.tl (compile-and-mach): Do not compile the patterns with copies of the var list, but with he one and only incoming var-list. Consequently, there are not var lists to merge. par-pat parameter renamed to and-pat. * txr.1: Improve and/or documentation, clarifying scope rules. Also, clarify that variables in non-matching patterns of an or are no set to nil, if they are existing bindings from before the or.
* matcher: @(as) must always bind fresh variable.Kaz Kylheku2021-02-062-13/+47
| | | | | | | | | | | | | | It is documented that as binds a new variable. Furthermore, it used to be called let. Yet, it back-references. Let's fix it. * share/txr/stdlib/match.tl (compile-new-var-match): New function: like compile-var-match but binds new variable, as if back-referencing didn't exist. (compile-as-match): Use compile-new-var-match. * txr.1: Improve as documentation. Clarify that it binds a fresh variable, and that pattern is processed in its scope. Include an example with circular structure.
* matcher: clean up var match.Kaz Kylheku2021-02-051-4/+6
| | | | | | * share/txr/stdlib/match.tl (compile-var-match): Pull symbol check into the cond. In null sym case, don't call var-list.record.
* compiler: take advantage of new scoping in optimizer.Kaz Kylheku2021-02-051-14/+14
| | | | | | * share/txr/stdlib/optimize.tl (basic-blocks peephole): Get rid of @(op ...) and @(require ...) operators in favor of direct backreferencing.
* matcher: back-reference Lisp variables.Kaz Kylheku2021-02-053-9/+64
| | | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (struct var-list): New slot, menv. (var-list exists): Method now falls back on lexical scope and dynamic variables. (get-var-list): New function. (when-match, if-match, match-case, when-exprs-match): Capture macro environment and use get-vars-list to convert to a vars object which carries it as the menv slot. With this, the compiler framework has access to the lexical environment. * tests/011/patmatch.tl: Test cases of back-referencing with Lisp lexicals. * txr.1: Documented.
* compiler: rewrite one peephole patern using @(with ...).Kaz Kylheku2021-02-051-8/+6
| | | | | | | * share/txr/stdlib/optimize.tl (basic-blocks peephole): Rewrite the recently added jump hreading optimization as a single pattern, doing the matching into the other basic block through the hash table using @(with ...).
* matcher: rearrange match order of @(with).Kaz Kylheku2021-02-053-28/+49
| | | | | | | | | | | | | | | | | The @(with side-pat expr main-pat) syntax becomes @(with main-pat side-pat expr), which is more useful. Also, the main-pat can be omitted. * share/txr/stdlib/match.tl (compile-with-match): Recognize two forms of the syntax: two argument form with main-pat omitted and the full form. In the full form, main-pat is on the left now and processed first, so we have to rearrange the compilation and integration order. * tests/011/patmatch.tl: Existing tests updated. Two-argument test added. * txr.1: Updated.
* matcher: don't set flag in last case.Kaz Kylheku2021-02-051-12/+18
| | | | | | | | | | | The last case in a match-case or lambda-match does not need to set the matched flag, since nothing tests it. * share/txr/stdlib/match.tl (match-case): Rename some local variables for consistency with lambda-match. Change the counter from 1, so we can then compare the index of the last case to the length and avoid emitting the set. (expand-lambda-match): Same optimization.
* compiler: new jump threading optimization case.Kaz Kylheku2021-02-051-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This opportunity now exists due to the previous commit which eliminates discarded register moves. The idea is to recognize code like if Txxx label0 jmp label1 ;; jump if Txx is not nil label1: if Txxx ... ;; Txxx is not nil jmp label2 ;; jump taken and rewrite the jmp in the first block to: if Txxx label0 jmp label2 The leading if Txx label0 is then susceptible to further threading via label0, as before. Before the previous compiler commit, there were dead register moves between the if and jmp that would be too complicated to analyze in the peephole. The motivation is that this pattern occurs in match-case and lambda-match due to the way the cases update a matched-p variable which is used to skip subsequent cases: case0 (unless matched-p case1) ;; sets matched-p if it matches (unless matched-p) case2) ;; sets matched-p if it matches ... and so on. Those successive matched-p tests now thread; if matched-p is true, the control flow will short-circuit past the subsequent tests. * share/txr/stdlib/optimize.tl (basic-blocks peephole): Add new case for recognizing aforementioned pattern.
* compiler: optimize away discard register.Kaz Kylheku2021-02-051-33/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When compiling the procedural special forms prog and prog1, there are subforms whose values are discarded. The compilation of those forms still requires an output register, which is passed down. In certain cases, wasteful moves of data into that register are generated, which we can eliminate. * share/txr/stdlib/compiler.tl (struct compiler): New slot, discards. Holds t-registers that are marked as discard. (compiler alloc-discard-treg): New method. (compiler free-treg): Remove freed treg from discard list. (compiler maybe-alloc-treg): If the given register is a discard, we must allocate. (compiler maybe-mov): New method, replacing maybe-mov function. (compiler comp-if): Replace maybe-mov function calls with method. In the (if test then) case, avoid referencing oreg register after a maybe-mov since it may be a discard such that the maybe-mov produced no code; reference the original register. (comp-progn): Allocate oreg-discard with alloc-discard-treg method instead of alloc-treg. (comp-prog1): Same thing with igreg. (comp-for): For compiling the test expression, use the same output register as what was used for the init block. Do not borrow oreg for this, which may be a discard that will be removed by the maybe-mov. (compiler (comp-setq, comp-ift, comp-switch, comp-block, comp-catch, comp-let, comp-fbind, comp-lambda-impl, comp-or, comp-tree-case, comp-load-time-lit): Replace maybe-mov function calls with method. (maybe-mov): Function removed, replaced by method.
* matcher: lambda-match: bug: wrong variable tested.Kaz Kylheku2021-02-041-1/+1
| | | | | | * share/txr/stdlib/match.tl (expand-lambda-match): The matched-p-temp variable must be tested for each clause, not result-temp. The result of a matching clause could be nil.
* matcher: lambda-match: error diagnostics.Kaz Kylheku2021-02-041-14/+20
| | | | | | | | | * share/txr/stdlib/match.tl (when-exprs-match): Bind the *match-form* special to macro form. (lambda-match, defun-match, :match): Likewise. (expand-lambda-match): Set the macro ancestor for the when-exprs-match form to the be clause syntax it was derived from.
* matcher: misleading diagnostics.Kaz Kylheku2021-02-041-2/+2
| | | | | | | * share/txr/stdlib/match.tl (compile-var-match, compile-predicate-match): Replace "is not a symbol" with "is not a bindable symbol". I had this message come up claiming that a :keyword is not a symbol.
* error: improve compiler error location reporting.Kaz Kylheku2021-02-041-8/+18
| | | | | | | | | | | * share/txr/stdlib/error.tl (sys:dig): New function. If the form has no source location, but has macro ancestry, thens try to search through that. (sys:loc): Don't bother with the conditional; source-loc-str always returns something. When there is no source location there is a "source loc n/a" string. (compile-error, compile-warning, compile-defr-warning): Use sys:dig to take advanage of macro ancestry information.
* doc: misspelled dump-deferred-warningsKaz Kylheku2021-02-041-1/+1
| | | | * txr.1: pluralize identifier in syntax section.
* matcher: add :match parameter macro.Kaz Kylheku2021-02-043-4/+252
| | | | | | | | | | | | | With this, we can do matching anywhere we are able to specify a function parameter list and a body, and we can specify ordinary arguments, which are inserted to the left of the implicit match. Plus, it specialy integrates with :key. * lisplib.c (match_set_entries): Autoload on :match. * share/txr/stdlib/match.tl (:match): New parameter macro. * txr.1: Documented.
* doc: param macros: missing return value requirements.Kaz Kylheku2021-02-041-0/+14
| | | | | | * txr.1: Document return value convention of parameter list transformers, without which it can only be deduced from the example.
* matcher: lambda-match: redoc, bugfix, test-casesKaz Kylheku2021-02-043-37/+205
| | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (expand-lambda-match): In a case that takes the maximum number of fixed args and no dotted pattern, in a function that is variadic, we must assert that the rest parameter is nil: there are no additional arguments. In the lambda args, we must generate the colon that separates the optional arguments. * tests/011/patmatch.tl: basic test cases for lambda-match and defun-match. * txr.1: lambda-match and defun-match redocumented, with examples.
* matcher: reimplementation of lambda-match.Kaz Kylheku2021-02-031-6/+98
| | | | | | | | | | | | | | | | | | | | | | This patch replaces the argument-list-based lambda match with one that matches fixed arguments without consing. Instead of generating a variadic function with zero fixed arguments, it generates a function with required, optional and rest argument based on considering the arity of all the matches. * share/txr/stdlib/match.tl (compile-exprs-match): New function. (compile-match): Wire a new pattern operator called sys:exprs, for internal use. This matches a list-like pattern against the values of multiple expressions, rather than a single expression. (when-exprs-mach): New internal macro for matching a sequence of patterns against a sequence of expressions of the same arity. (lambda-clause): New structure. (parse-lambda-match-clause, expand-lambda-match): New functions. (lambda-match, defun-match): Redefine using expand-lambda-match.
* matcher: bugfix: bad hygiene in match-case.Kaz Kylheku2021-02-031-4/+6
| | | | | | | * share/txr/stdlib/match.tl (match-case): Use a gensym for evaluating the obj expression, rather than passing that expression itself into the sub-compile jobs, where it is subject to multiple evaluation.
* lib: code review of get_special_slot uses.Kaz Kylheku2021-02-021-24/+23
| | | | | | | | | | | | | * lib.c (seq_info): Streamline code. Initialize ret.kind to SEQ_NOTSEQ to avoid repeating that in multiple else clauses. Make sure that if the nullify method returns nil, we also return in that case, and don't call get_special_slot on nil. (rplaca, rplacd): Change the default case to COBJ, so that the obj_struct_p inline can be used instead of structp. Put the default: label on the error case which the struct check falls through to; NIL now goes there. (sub): Use obj_struct_p, not structp, in a case where we already know we have a COBJ.
* lib: fix crash in iterable and nullify.Kaz Kylheku2021-02-021-1/+1
| | | | | | | * lib.c (seq_iterable): In the COBJ case, we must check whether the object is a structure before accessing get_special_slot. For instance (nullify #/a/) crashes because a regex is a COBJ but not a struct.
* matcher: fix @(and/or) backreferencing issue.Kaz Kylheku2021-02-021-1/+6
| | | | | | | | * share/txr/stdlib/match.tl (var-list merge): New method. (compile-or-match, compile-and-match): After compiling the sub-patterns, merge all of their new variables produced in their isolated var-list copies back into var-list, so they are visible to subsequent compilation.
* matcher: new failing backreferencing test case.Kaz Kylheku2021-02-021-0/+4
| | | | | | | | | | * tests/011/patmatch.tl: New test cases that break. The (copy var-list) logic in the handling of and and or is incomplete. The bifurcated vars must be merged together into the original vars. Without this, it looks as if the operator didn't bind any variables, and they can be repeated again without backreferencing. In the broken examples, variable a is taking on the value 2 instead of mismatching the previous value of 1.
* matcher: new @(with) operator.Kaz Kylheku2021-02-014-1/+74
| | | | | | | | | | | | * lisplib.c (match_instantiate): Ensure usr:with is interned. * share/txr/stdlib/match.tl (compile-with-match): New function. (compile-match): Wire in with operator. * tests/011/patmatch.tl: Test cases. * txr.1: Documented.
* matcher: rename @(let) to @(as).Kaz Kylheku2021-02-014-17/+17
| | | | | | | | | | | | | * lisplib.c (match_instantiate): Ensure usr:as is interned. * share/txr/stdlib/match.tl (compile-let-match): Rename to compile-as-match. (compile-match): Remove handling of let symbol; route as symbol to compile-as-match. * tests/011/patmatch.tl: Update all uses of let to as. * txr.1: Updated.
* matcher: restore nulling out of vars in @(or).Kaz Kylheku2021-02-011-12/+23
| | | | | | | | | | | | | * share/txr/stdlib/match.tl (compiled-match get-vars): Local function here becomes stand-alone defun, because we need it elsewhere. (compiled-mach wrap-guards): When processing the guard-disjunction object to produce the or branches, we calculate, for each branch, its own variables, and the variables of the preceding clauses. We generate code to set the previous variables to nil. Not all the previous variables, just those that are not also in the current clause. (get-vars): New function.
* matcher: adding test case for @(or) regression.Kaz Kylheku2021-02-011-0/+3
| | | | | | | * tests/011/patmatch.tl: New test case showing that @(or) no longer nulls out the variables from previous clauses like it used to. (2 2 nil) is returned, showing a is not set to nil when b matches.
* matcher: struct: move type test before slot tests.Kaz Kylheku2021-02-011-4/+2
| | | | | | | | | | | | | | | In the loose form of the @(struct ...) match, the struct type is matched by a pattern. This pattern should execute before the object is tested for the presence of the required slots by by guard1. It should not come between testing for the presence of slots, and then testing their contents. * share/txr/stdlib/match.tl (compile-struct-match): Do not lump together the type-match and slot-matches into a single all-matches list. Emit type-match's guard before guard1, and the slot-matches guards after. The order is basic test (guard0), struct type pattern match (type-match), slots-present (guard1) and then slot contents (slot-matches).
* matcher: struct: make guards lists; eliminate backquote.Kaz Kylheku2021-02-011-13/+15
| | | | | | * share/txr/stdlib/match.tl (compile-struct-match): make guard0 and guard1 lists match-guard items. Replace backquote with straight append.
* doc: mistake in example for @[...] pattern.Kaz Kylheku2021-02-011-3/+3
| | | | | | | * txr.1: Fix use of nonexistent odd function which should be oddp. The same example occurs in the test suite, but without this error. Also fix indentation in this and the two related examples above.
* matcher: bugfix: bad stray code in @[...] matcher.Kaz Kylheku2021-02-012-2/+5
| | | | | | | | | | * share/txr/stdlib/match.tl (compile-dwim-predicate-match): In he one-argument case, there is stray code referencing var-match.test-expr, which blows up. This is hit by exactly the one example in the documentation that was not added as a test case. * tests/011/patmatch.tl: Add test case from doc.
* doc: mistake in when-match rcons example.Kaz Kylheku2021-02-011-1/+1
| | | | | * txr.1: The de-sugared (rcons @a @b) example is missing a quote on the object, and so returns nil and not (1 2).
* Version 250txr-250Kaz Kylheku2021-01-316-249/+295
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* lib: get rid of alist_remove1 function.Kaz Kylheku2021-01-311-6/+1
| | | | | | | * lib.c (delete_package): This is the only user of alist_remove1. It can use remqual with a car_f key, which is more efficient. (alist_remove1): Function removed.
* @(rebind): bugfix: don't clobber right side variable.Kaz Kylheku2021-01-305-11/+79
| | | | | | | | | | | | | | | | | | | | | * Makefile (tst/tests/000/binding.ok): Pass -B to txr for this new test. * match.c (v_rebind): Fix gaping copy-and-paste bug here, which causes rebind to take on the behavior of local/forget; it takes all symbols that appear as its arguments from the environment and produces an environment in which they don't exist. What we want is to remove the left variables from the environment, and since that is a nested pattern, the right way to do that is to flatten it. Bug reported by Frank Schwidom. * tests/000/binding.txr: New file. * tests/000/binding.expected: New file. * txr.1: Improve documentation of @(rebind), also making improvements in @(set) documentation.
* doc: bad syntax formatting: partition and split.Kaz Kylheku2021-01-291-4/+4
| | | | | | * txr.1: Fix issues in the formatting of the index-list, index and function arguments of partition, partition*, split and split* functions.
* matcher: prune @nil in cons and vector matches.Kaz Kylheku2021-01-291-9/+19
| | | | | | | | | | | | | | | | | | Elimination of unused temporaries is really the job of the compiler, but we can do some simple things to get better code from the matcher in the meanwhile. In list and vector matches, @nil gets used just for placeholding. We can avoid generating the code which binds the corresponding value to an unused gensym. share/txr/stdlib/match.tl (compile-var-match): When the variable is nil, then do not generate a match-guard with empty content. Just generate an empty guard-chain. The higher level compiler can then check for this empty guard chain and prune its own material away. (compile-vec-match, compile-cons-structure): Eliminate every gensym and its initializing expression, whose corresponding compiled sub-match has an empty guard chain.
* matcher: bugfix: @nil isn't trivial.Kaz Kylheku2021-01-292-1/+2
| | | | | | | | | | | | | * share/txr/stdlib/match.tl (non-triv-pat-p): Extend sys:var match so (sys:var nil) is identified as trivial. * tests/011/patmatch.tl: Add broken test case fixed by this. This doesn't show up when @nil is used as the only match. It also doesn't show up if @nil is used in a vector or list in a mixture with other operators, because those other ones identify the overall list pattern as non-trivial. None of the occurrences of @nil in the existing test suite, like (@nil @nil @x) tickle the bug.
* optimizer: add a few peephole reductions.Kaz Kylheku2021-01-292-2/+14
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler optimize): Call peephole method on basic-blocks object, rather than thread-jumps. * share/txr/stdlib/optimize.tl (basic-blocks thread-jumps): Rename method to peephole, since it does more than just thread-jumps. Add some dead code elimination, and elimination of wasteful moves.
* matcher: remove duplicate variables in one place.Kaz Kylheku2021-01-281-21/+11
| | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (compiled-match get-var-exprs): method get-var-exprs removed. This is only used in one place, which is going away. Actually, the value is not even used; it is discarded. (compiled-match get-vars): This method now passes the list of variables thorugh uniq. The logic of get-guard-values is pulled into a local function, since get-guard-values has only one caller now. (get-guard-values): Function removed. (compile-or-match): Removing all-var-exprs variable and all that calculation of the unique names, as well as the extra match-guard which duplicates those names pointlessly.
* matcher: rid compiled-match of test-expr and vars.Kaz Kylheku2021-01-281-89/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (match-vars): Get rid of base, since only match-guard would need it now. (match-guard): Move match-vars methods and slots into this structure. (compiled-match): No longer inherits match-vars, so no longer has vars and var-exprs slots. Also, slot test-expr removed. (compiled-match :postinit): Removed. (compiled-match {get-vars, get-var-exprs}): Do not prepend vars and var-exprs which no longer exist. (compile-struct-match, compile-vec-match, compile-range-match, compile-cons-structure, compile-let-match, compile-hash-match): Get rid of vars, var-exprs and test-expr. These are just causing duplicate variables to exist. (compile-var-match): Convert necessary test-expr and vars into match-guard object put into guard-chain. (compile-atom-match, compile-or-match): Get rid of test-expr. (compile-op-match, compile-predicate-match): Get rid of stray reference to test-expr. (compile-dwim-predicate-match): Move obj-var test into guard. Get rid of vars, var-exprs and test-expr. (compile-loop-match): Move vars and and test expression into a second guard object, so there are now guard0 and guard1. (compile-and-match): Get rid of all-var-exprs local variable and its compuation, vars, var-exprs and test-expr. (compile-not-match): Get rid of test-expr and empty vars. (compile-hash-match):
* matcher: add test-expr to match-guard.Kaz Kylheku2021-01-281-10/+10
| | | | | | | | | | | | | | * share/txr/stdlib/match.tl (match-guard): New slot, test-expr. This provides a bottom test, with all the variables bound, allowing us to allocate just one match guard in a few instances where we are allocating two. This will be important in the upcoming refactoring. (compiled-match :postinit): Allocate just one match-guard with test-expr instead of a separate one with a guard-expr. (wrap-guards): Wrap the test-expr to the code, if it is not t. (compile-hash-match): Reduce two match guards to one in two instances.
* matcher: restructuring to fix new broken case.Kaz Kylheku2021-01-282-96/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This one test case requires restructuring. The handling for the @(or ...) operator is now very different. To support @(or ...), there is now a new variant of the match-guard object called guard disjunction, which contains multiple match-guard chains. Furthermore, the separation between both guard-chain lists and compiled-match having a test expression and variables is being obliterated. For now, what we do is in a :postinit handler on compiled-match, we immediately convert the test-expr, vars and var-exprs slots into a match-guard object, which is placed into the guard-chain, and then we clear these slots. They are now vestigial only and will be removed. * tests/011/patmatch.tl: New test case which shows that (@(or foo bar) ...) does not short immediately short circuit to a failure when the corresponding element is neither foo nor bar. Matching proceeds to the right, wasting cycles and possibly causing errors. * share/txr/stdlib/match.tl (*match-var*): Move to top, above structs. There are some methods which refer to this variable now for throwing internal errors. (guard-disjunction): New object that is compatible with a match-guard, and placed into guard-lists as if it were a match-guard. This handles the bifurcation logic of an OR match. (compiled-match): New :postinit handler converts local vars, var-exprs and test-expr into a match-guard placed into the chain, and then clears these values. The compilation of code is done purely from the guard-chain. (compiled-match get-vars): This method is now complicated due to the guard-disjunction objects, and so uses a helper function called get-guard-values. (compiled-match get-var-exprs): New method accompanying get-vars to get the accompanying init expressions. (compiled-match wrap-guards): Two changes are going on here. One is that the funccion takes on more of the responsibility which was previously carried out by the callers. The callers were interpolating the test-expr and vars from a compiled-match into a piece of code, which was then passed to wrap-guards. Hence the naming: the job was just to wrap some guards. Now, wrap-guards is called just with the body forms, and does all of the work. Secondly, wrap-guards is complicated due to the handling of the guard-disjunction items. Also, there is some case handling to generate better code; we avoid generating an empty (let () ...) and (alet () ...). (compiled-match add-guard-pre, compiled-match add-guards-pre, compiled-match add-guards-post): New methods for adding guards after construction. These interfaces replace hacks of pushing new variables, tweaking the test-expr, or explicitly pushing guards onto the list. (get-guard-values): New function for iterating over a guard-chain, including match-guard and guard-disjunction items, retrieving a particular list-valued slot from each one using the fun argument, and returning a list of all those lists catenated together. (compile-struct-match, compile-vec-match, compile-range-match): Eliminate test-expr, replacing it with the harmless t. (compile-op-match): We don't try to extend the test-expr of the compiled var. Rather we add our guard expressin using the add-guard-pre interface. (compile-dwim-predicate-match): Likewise, and also, we do not calculate the test-expr for the output compiled-match from the constituent match test-exprs. We ignore those and just set the test-expr pat-match.obj-var. The constituent test-exprs have been converted to guard-chain items already, so there is no point in referring to them. (compile-predicate-match): Use add-guard-pre method to add guard instead of pushing it on list. (compile-cons-structure): Eliminate test-expr being calculated from constituent test-exprs, and just stub it out to t. (compile-require-match): Use add-guards-post to push match-guard onto compiled child mach, instead of tweaking its test-expr. (compile-let-match): Oblierate calculation of test-expr from child test-exprs, replacing with t stub. (compile-loop-match): Call wrap-guards in the new way, without generating assignments or test-expr. (compile-parallel-match): This method is removed; there are now separate compile-or-match and compile-and-match methods. (compile-or-match): New method: compiles consitituent expressions, and converts them into multiple guard-chains for a guard-disjunction object. Then wrap-guards will finish the job of emitting the or logic out of those chains. (compile-and-match): This shares some common logic with compile-or-match, but is substantially simpler. Pattern matching is implicitly AND-based: in a pattern, all the sub-patterns have to match. So there isn't much to do beyond just evaluating all the patterns against the same object. They can all be thrown into one combined flat guard chain. (compile-not-match): Adjust to new wrap-guards interface. Nothing left to do here but pass the expression t to it. (copmile-hash-mach): The post-constructon manipulations of the child compiled matches are done with the appropriate add-guards-pre. The test-expr is eliminated, replaced with t. (compile-match): Wire or and and to the new separate methods compile-or-match and compile-and-match. (when-match, if-match, match-case): Simplified due to when-match interface change. The macros depend on a lot less implementation detail now: they bind the required vars and generate the code.
* compiler: bug: append-each mutates lists.Kaz Kylheku2021-01-281-5/+7
| | | | | | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (expand-each): The algorithm for appending is completely wrong. Not only does it destructively mutate, it doesn't look like it will behave like the interpreted append-each operator, since it assumes it can rplacd the tail cons of the output list, which won't work for non-list sequence types. * share/txr/stdlib/compiler.tl (expand-each): New translation strategy: append-each each will now accumulate the values of the body expression into a list, exactly like collect-each does. Then it will apply the sys:append function to that list. This ensures the "as if" semantics (append-each behaves like the append function), and non-destructive behavior: everything is copied that needs to be, except that a list tail can share substructure.
* matcher: remove superflous test-expr in hash op.Kaz Kylheku2021-01-271-2/+0
| | | | | | | * share/txr/stdlib/match.tl (compile-hash-match): In the trivial key case, we are wastefully installing the same expression as both a guard in the guard-chain and as a test-expr. We should not be frobbing vm.test-expr.
* matcher: fix broken predicate test.Kaz Kylheku2021-01-271-1/+2
| | | | | * share/txr/stdlib/match.tl (compile-predicate-match): Promote condition from test-expr into guard-chain.
* mather: new bad (@(predicate) @(all ...)) test case.Kaz Kylheku2021-01-271-0/+2
| | | | | * tests/011/patmatch.tl: Predicates must also be tested earlier, as guard conditions.
* matcher: smallest fix for broken test case found.Kaz Kylheku2021-01-271-1/+3
| | | | | | * share/txr/stdlib/match.tl (compile-atom-match): Do not express the match for the atom via test-expr. That is too late. It needs to be a guard in the guard chain.
* matcher: new broken test case: bad order of checks.Kaz Kylheku2021-01-271-0/+2
| | | | | | | * tests/011/patmatch.tl: Even though bar mismatches foo, the second element @(all) is processed and tries to collect the list. This results in an error due to the list being improper.