summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* vm/asm: housecleaning: remove deprecated opcodes.Kaz Kylheku2021-02-143-137/+35
| | | | | | | | | | | | | | | | | | Since we have are breaking binary compatibility in the upcoming TXR 252, we might as well take the opportunity to remove deprecated opcodes that the compiler doesn't use. * share/txr/stdlib/asm.tl (op-fin): Opcode removed. (op-pprof): Derive directly from op-end rather than op-fin. (op-movrsi, op-movsmi, op-movrbi, op-movi-pseudo): Opcodes removed. * vm.c (vm_fin, vm_movrsi, vm_movsmi, vm_movrbi): Functions removed. (vm_execute): FIN, MOVRSI, MOVSMI, MOVRBI cases removed. * vmop.h: Regenerated. (vm_op_t): Enum members FIN, MOVRSI, MOVSMI, MOVRBI removed.
* printer: lambda bugfix.Kaz Kylheku2021-02-121-1/+1
| | | | | | | | | | | * lib.c (obj_print_impl): Don't pass non-symbols to fboundp. This causes a problem in the case where we are printing an object like ((lambda ...) ...). The car of this object is the (lambda ...) form. When when pass this to fboundp, the underlying function lookup mechanism wants to turn it into a function object and tries to expand it. This can error out if the lambda has bad syntax, which can happen because it's just data that we are trying to print.
* compiler: eliminate block from recursive functions.Kaz Kylheku2021-02-122-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The block elimination logic doesn't work for self-recursive functions, even if they invoke no block returning, and use only system functions that don't have anything to do with block returns. This is because the recursive call is not recognized, and treated as a call to an unknown function. Let's put in a simple hack. The defun and defmacro operators will use a new secret special operator called sys:blk instead of block to generate the block. The compilation of sys:blk will assume that (sys:blk name ...) is only used in a defun or defmacro by that same name, and include name in the list of OK functions. So that functions created using the interpreter and then dynamically compiled will also benefit, we add this operator to the interpreter. * eval.c (sys_blk_s): New symbol variable. (op_defun): For defun and defmacro, use sys:blk for the block for the block (eval_init): Initialize sys_blk_s with the interned symbol sys:blk. Register the sys:blk operator. * share/txr/stdlib/compiler.tl (compiler compile): Recognize the sys:blk special form and handle via comp-block. (comp-block): If sys:blk is being compiled, then include the block name in the list of functions that do not perform block returns. (If this is false, other checks will fail before use that.) (expand-defun): Use sys:blk for defun and defmacro.
* doc: wording improvements in pattern matching intro.Kaz Kylheku2021-02-121-9/+20
|
* compiler/vm: more compact frame size for closures.Kaz Kylheku2021-02-115-130/+161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Closures do not share t-registers with surrounding code; they do not store a value into such a register that code outside the closure would read and vice versa. When compiling closures, we can can temporarily reset the compiler's t-register allocator machinery to get low t-register values. Then, when executing the closure, we reserve space just for the registers it needs, not based off the containing vm description. Here we make a backwards-incompatible change. The VM close instruction needs an extra parameter indicating the number of t-regisers. This is stored into the closure and used for allocating the frame when it is dispatched. * parser.c (read_file_common): We read nothing but version 6 tlo files now. * share/txr/stdlib/asm.tl (op-close asm): Parse new ntreg argument from close syntax, and put it out as an extra word. Here is where we pay for this improvement in extra code size. (op-close dis): Extract the new argument from the machine code and add it to the disassembled format. * share/txr/stdlib/compiler.tl (compile-in-toplevel): Save and restore the t-reg discards list also. Don't bother with a gensym for the compiler; the argument is always a symbol, which we can use unhygienically like in with-var-spy. (compile-with-fresh-tregs): New macro based on compile-in-toplevel: almost the same but doesn't reset the level. (comp-lambda-impl): Use compile-with-fresh-tregs to compile the entire closure with a minimized register set. Place the treg-cntr into the closure instruction to indicate the number of registers the closure requires. * vm.c (struct vm): New member, nreg. (vm_make_closure): New parameter, nreg, stored into the closure. (vm_close): Extract a third opcode word, and pull the nreg value from the bottom half. Pass this to vm_make_closure. (vm_execute_closure, vm_funcall_common): Calculate frame size based on the closur's nreg rather than the VM description's. * txr.1: Document that the upcoming version 252 produces version 6.0 object files and only loads version 6.
* compiler: frame-eliminating optimization.Kaz Kylheku2021-02-113-154/+265
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This optimization identifies let blocks whose variables are not captured by closures. The variables are relocated to registers and the frame M N ... end reg wrapping is removed. * parser.c (read_file_common): Load version 6 files. We remain backwards-compatible. * share/txr/stdlib/compiler.tl (var-spy, capture-var-spy): New structure types. (struct compiler): New slot, var-spies. (with-var-spy): New macro. (compiler (alloc-new-treg, unalloc-reg-count, push-var-spy, pop-var-spy)): New methods. (compiler (comp-atom, compt-setq, comp-list-setq, comp-lisp1-value)): Inform the spies in the spy notification stack about assignments and accesses. (compiler eliminate-frame): New method. (compiler comp-let): Use spies to determine which variables from this frame are captured, and if none are, then use eliminate-frame to rename all the variables to t-registers and drop the frame setup/teardown. (compiler comp-lambda): Set up a capture-var-spy which intercepts accesses and assignments within a lambda, and informs other spies about the captures. (%tlo-ver%): Bump compiled file version to to (6 0), because of some behavioral changes necessary in the VM. We might revert this if the issues are solved differently. * vm.c (vm_getz): Do not null out T registers. (vm_execute_toplevel, vm_execute_closure): Use zalloca to allocate the register part of the frame, so T registers are initialized to nil.
* compiler: use rewrite-case in dedup-labels.Kaz Kylheku2021-02-101-8/+6
| | | | | | | * share/txr/stdlib/optimize.tl (dedup-labels): Use rewrite-case macro defined in the same file instead of rewrite/lambda/match-case. Also change two-argument list* to cons.
* vm: remove hard-coded constants.Kaz Kylheku2021-02-103-6/+8
| | | | | | | | | | * genvmop.txr: Define VM_LEV_SIZE from %lev-size%. * vm.c (vm_make_desc): Use VM_MAX_LEV and VM_LEV_SIZE instead of incorrect hard-coded values of 256 that were right for an old version of the vm. * vmop.h: Regenerated.
* compiler: bug: trivial unwind-protect return valueKaz Kylheku2021-02-101-1/+1
| | | | | | | | | | | | | Bad test case: (unwind-protect 42 1 2 3) -> 3 ;; should be 42 * share/txr/stdlib/compiler.tl (compile comp-unwind-protect): In the case when the protected code compiles to zero code, because it is a simple variable or constant, the code that we return must still nominate the that fragment's output register as its output, and not the output register of the cleanup forms.
* matcher: diagnose syntax problems in hash pattern.Kaz Kylheku2021-02-091-1/+1
| | | | | | * share/txr/stdlib/match.tl (compile-hash-match): Use mac-param-bind instead of tree-bind, like in the other functions.
* compiler: rename variable in optimizer code.Kaz Kylheku2021-02-091-2/+2
| | | | | | * share/txr/stdlib/optimize.tl (basic-blocks peephole): Rename jlabel3 variable to jlabel2, so it is in sequence after jlabel0 and jlabel1.
* doc: fix broken my-cond example.Kaz Kylheku2021-02-091-4/+4
| | | | | * txr.1: Replace obsolete @[...] predicate notation in the my-cond example with working code.
* doc: fix lambda-mach typo.Kaz Kylheku2021-02-091-1/+1
|
* 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.