summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* doc: fix match-case intro sentence.Kaz Kylheku2021-02-091-1/+1
| | | | * txr.1: "the match-case macro", not "the match-case".
* doc: explain dot position of variable in predicate.Kaz Kylheku2021-02-091-0/+23
| | | | | | * txr.1: Explain that the dot position of a variable in a predicate pattern corresponds to the usual application syntax. Add an example of this from the test case file.
* doc: clarify implicit insertion object into predicate.Kaz Kylheku2021-02-091-1/+1
| | | | | * txr.1: Better wording is that the object is added as an implicit rightmost argument.
* doc: fix fumbled text under predicate pattern.Kaz Kylheku2021-02-091-1/+1
| | | | * txr.1: "three two" should be "second three".
* doc: with pattern operator clarification.Kaz Kylheku2021-02-091-2/+6
| | | | | * txr.1: Clarify that expr is not evaluated if the main-pattern fails to match.
* doc: double nil in list pattern description.Kaz Kylheku2021-02-091-1/+1
| | | | * txr.1: Fix "atom pattern nil nil".
* doc: fixes in pattern matching introduction.Kaz Kylheku2021-02-091-15/+17
| | | | | | | | * txr.1: Improving text about variables. Removing obsolete reference to parallel scoping behavior of @(and) and mentioning that @(as) binds fresh variables, which could cause multiple occurrences of a variable in the same patter not to refer to the same variable.
* struct: changing meaning of obj.[fun ...] syntax.Kaz Kylheku2021-02-095-25/+55
| | | | | | | | | | | | | | | | | | | | | | | | | Until now, the obj.[fun ...] syntax has uselessly denoted exactly the same thing as [obj.fun ...]. This latter syntax is what should be used for that meaning. The new meaning of obj.[fun ...] will be that it performs method dispatch, where obj is passed to obj.fun as the leftmost argument: obj.[fun ...] is [obj.fun obj ...], with obj evaluated once. * share/txr/stdlib/struct.tl (qref): Expansion change done here, with backward compat switch. * share/txr/stdlib/termios.tl (termios (go-raw, go-cbreak)): Some a.[b c] turned to [a.b c] here. * tests/012/oop.tl (animal print): Likewise. * tests/012/struct.tl: Likewise, and some expansion tests updated to reflect the new expansion. * txr.1: Documentation revised in multiple places and compat note added.
* matcher: replace wrg function with reduce-right.Kaz Kylheku2021-02-091-23/+14
| | | | | | | * share/txr/stdlib/match.tl (wrap-expr): Remove wrg local function. Replace call with simple reduce-right, which doesn't require a reversal of the original list. (compiled-match): Likewise.
* matcher: wrap-guards type case to method dispatch.Kaz Kylheku2021-02-091-44/+48
| | | | | | | | * share/txr/stdlib/match.tl (match-guards wrap-expr): New method. (guard-distinction wrap-expr): New method. (compiled-match wrap-guards): Reduce type-case to wrap-expr method call.
* matcher: match-guard: use op list, and zip.Kaz Kylheku2021-02-091-2/+2
| | | | | | | | * share/txr/stdlib/match.tl (match-guard assignments): Use simpler op expression to generate a function that produces set assignments. (match-guard lets): Use zip function instead of mapcar with ret and quasiquote.
* matcher: get rid of undocumented @(range) op.Kaz Kylheku2021-02-091-5/+4
| | | | | | | | * share/txr/stdlib/match.tl (compile-match): Remove the rcons entry which was supposed to be already gone in version 250, and is no longer documented. (compile-range-match): Edit parameter name to remove misleading reference to rcons.
* Version 251txr-251Kaz Kylheku2021-02-086-1162/+1210
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Re-synced to 251. * txr.vim, tl.vim: Regenerated.
* RELNOTES: Fix wrong 2020 dates.Kaz Kylheku2021-02-081-4/+4
|
* matcher: add @(or) test involving existing variables.Kaz Kylheku2021-02-081-0/+5
| | | | | | | * tests/011/patmatch.tl: New test case showing that existing variables that don't match in an @(or) retain their values; they do not become nil, unlike freshly bound variables in non-matching or-clauses.
* matcher: @(and) back-referencing test.Kaz Kylheku2021-02-081-0/+3
| | | | | | * tests/011/patmatch.tl: back-referencing between the expressions in an @(and) patter has recently been introduced, and needs some coverage.
* matcher: fix backreferencing in predicate.Kaz Kylheku2021-02-082-1/+7
| | | | | | | | | * share/txr/stdlib/match.tl (compile-predicate-match): Always allocate res-var as a gensym; do not use resvar. Otherwise we will freshly bind resvar as a local, failing to back-reference. * tests/011/patmatch.tl: Add test cases, the second of which fails before this change.
* matcher: test for dotted variable in predicate.Kaz Kylheku2021-02-081-0/+4
| | | | * tests/011/patmatch.tl: New test case.
* compiler: frame optimizations apply to dframe too.Kaz Kylheku2021-02-081-2/+2
| | | | | * share/txr/stdlib/optimize.tl (basic-blocks peephole): Use or pattern to look for dframe as well as frame.
* doc: document feature of multi-sort.Kaz Kylheku2021-02-081-0/+4
| | | | | | * txr.1: Document that multi-sort takes a single function in place of a list of one function. This has been a feature of the implementation from the beginning.
* compiler: jump skid optimization.Kaz Kylheku2021-02-071-0/+8
| | | | | | | | | | | | | | | | | | If an (if reg label0) target branches due to reg being nil, and the target of the branch is another branch instrution of the form (ifq reg nil label1), we know that that branch is not taken: the code following that instruction is executed. THus can jump right to that code. (if reg label0) (if reg xlabel) ... ... label0 label0 (ifq reg nil label1) --> (ifq reg nil label1) ... xlabel ... * share/txr/stdlib/optimize.tl (basic-blocks peephole): New sub-case under (jmp @reg @jlabel).
* compiler: frame reduction optimizations.Kaz Kylheku2021-02-071-1/+36
| | | | | | | | | | | | | | These optimizations have to do with moving a (frame x y) instruction past the next instruction. The goal is to move the frame past a conditional branch, under the right circumstances, so that the frame is eliminated when the branch is taken. * share/txr/stdlib/optimize.tl (basic-blocks (cut-block, next-block)): New methods. (basic-block peephole): Add two patterns: one to move a frame past a mov, call or gcall. Another more complicated one to move it past an if which jumps to an end.
* matcher: exprs-syntax: process trivial matches first.Kaz Kylheku2021-02-071-12/+15
| | | | | | | * share/txr/stdlib/match.tl (compile-exprs-match): Sort the expressions and patterns so trivial matches are processed first. The original order is used for evaluating the expressions.
* multi-sort: bug: always return list of lists.Kaz Kylheku2021-02-071-6/+13
| | | | | | | * lib.c (multi_sort): If any of the input lists is empty, then there is an empty list of tuples to sort, producing a an empty list that doesn't transpose back to a list of empty lists. We code this as a special case.
* matcher: eliminate use of flags.Kaz Kylheku2021-02-071-27/+18
| | | | | | | | | * share/txr/stdlib/match.tl (if-match, match-case, lambda-match): Instead of returning the result from the case(s), which gets stored in a result variable, and setting a flag to t, set the result variable inside the case, and return t. This eliminates the flag. In match-case and lambda-match, the cases can then be combined into an or form.
* matcher: predicate: document dot position of @avar.Kaz Kylheku2021-02-061-5/+9
| | | | | * txr.1: The @avar variable may be in the dot position of the form, denoting application.
* matcher: remove @(op ...) pattern.Kaz Kylheku2021-02-063-41/+2
| | | | | | | | | | | | | | | All he typical uses of this are better served by the new predicate match. If op is really needed, it can be used with the DWIM form of the predicate, as in @[(op ...) ...]. * share/txr/stdlib/match.tl (compile-op-match): Function removed. (compile-match): Remove op case. * tests/011/patmatch.tl: Keep op test cases by converting them to predicate test cases. * txr.1: Documentation removed.
* matcher: redesign predicate pattern.Kaz Kylheku2021-02-065-110/+142
| | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (compile-dwim-predicate-match): Function removed. There is no more special @(dwim ...) or @[...] pattern. (compile-predicate-match): Function rewritten, providing different syntax and semantics. (compile-match): dwim dispatch removed. (non-triv-pat-p): Replaced @(op ...) calls with new-style predicate syntax. (var-pat-p): Likewise, and upgraded one instance of old-style predicate syntax to new. * share/txr/stdlib/compiler.tl (reduce-or): Adjust predicate pattern to new style. * share/txr/stdlib/optimize.tl (dedup-labels): Likewise. * tests/011/patmatch.tl: All test cases with predicate syntax are updated to new style. One test case removed; some added. * txr.1: Predicate patterns re-documented. All examples involving predicate patterns updated.
* 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.