summaryrefslogtreecommitdiffstats
path: root/share
Commit message (Collapse)AuthorAgeFilesLines
* compiler: bug in new and expansion.Kaz Kylheku2021-01-201-3/+2
| | | | | | | | | | | | | | | * /share/txr/stdlib/compiler.tl (expand-and): The case with @(true-const-p) is wrongly ordered with respect to (and @a). The problem is that @rest can match a null terminator, and then we wrongly consume the constant; i.e. (and 42) calls (expand-and ^(and)) yielding t. Also, we eliminate the (and @a @b) case, because it is redundant with respect to (and @a . @rest). We adjust the latter to just output (if ...). And, lo and behold, now the function's cases map 1:1 to the ones in reduce-or. In fact reduce-or was originally produced from expand-and. I debugged it thoroughly, but neglected to backport to expand-and.
* Version 247txr-247Kaz Kylheku2021-01-191-1/+1
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped from incorrect 245 to 247. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* matcher: use mac-param-bind, not tree-bind.Kaz Kylheku2021-01-191-9/+9
| | | | | | | | | * share/txr/stdlib/match.tl (compile-struct-match, compile-predicate-match, compile-cons-structure, compile-require-match, compile-let-match, compile-loop-match, compile-parallel-match, compile-not-match, match-case): Use mac-param-bind for better error reporting against the original form when inner tree patterns don't match.
* matcher: fix broken @(some) test case.Kaz Kylheku2021-01-191-10/+14
| | | | | | | | | * share/txr/stdlib/match.tl (compile-loop-match): Introduce a new guard, and bind the pattern's variables there. The main compiled match now has an empty list of vars and var-exprs, so there is no length mismatch. The nreversing of the accumulated lists (only done in the @(and) case) is part of the test-expr now.
* matcher: fix broken test case.Kaz Kylheku2021-01-191-5/+7
| | | | | | | | | | | * share/txr/stdlib/match.tl (compile-parallel-match): The problem here is that vars in the new compiled-match being returned is not a list of the same length as var-exprs (that being empty). When this is embedded in other expressions, and the vars/var-exprs are appended together, this causes a mismatch, causing assignments to go to the wrong variables. The solution is to move the binding of all-vars into a new guard. Guards are not blindly combined by appending.
* compiler: improve code for and/or.Kaz Kylheku2021-01-181-9/+36
| | | | | | | | | | | | | | | | | | | | | Squeeze the constant and unreachable cases out of (and ...) and (or ...) forms, producing a more streamlined translation. This is the first appearance of structural pattern matching in the compiler! * share/txr/stdlib/compiler.tl (compiler compile): Handle and using new expand-and function, which translates it to if forms. Handle or via the renamed method comp-or. (compiler comp-and-or): Renamed to comp-or, since it handles only or. All the switching between or/and is eliminated. The or form is first reduced using simplify-or. We retain this function because one case in cond relies on or; or is a useful primitive because (or a b) evaluates a only once; whereas (if a a b) requires common-subexpression elimination to generate the same code as (or a b). (true-const-p, expand-and, flatten-or, reduce-or, simplify-or): New functions.
* matcher: add @(not) operator.Kaz Kylheku2021-01-181-0/+17
| | | | | | | * share/txr/stdlib/match.tl (compile-not-match): New function. (compile-match): Hook in not operator. * txr.1: Documented.
* matcher: fix semantics of variables in @(or)Kaz Kylheku2021-01-171-14/+19
| | | | | | | | * share/txr/stdlib/match.tl (cmopile-parallel-match): Rearrange the code and bind an all-vars local variable so that in submatch-fun we have access to the set of symbols. When compiling the @(or) operator, we use the list to null out all the variables that don't belong to the matching pattern.
* matcher: support loose mode for structures.Kaz Kylheku2021-01-171-20/+48
| | | | | | | | | * share/txr/stdlib/match.tl (compile-struct-match): Allow a pattern instead of a struct type name, in which case the object can be of any struct type which has the slots required by the pattern. * txr.1: Documented.
* matcher: add lambda-match and defun-matchKaz Kylheku2021-01-161-0/+10
| | | | | | | * lisplib.c (match_set_entries): New autoload triggers. * share/txr/stdlib/match.tl (lambda-match, defun-match): New macros.
* matcher: add if-match and match-case.Kaz Kylheku2021-01-151-0/+34
| | | | | | | | * lisplib.c (match_set_entries): Add match-case and if-match autoload trigger symbols. * share/txr/stdlib/match.tl (if-match, match-case): New macros.
* matcher: add support for @(op ...) predicate syntax.Kaz Kylheku2021-01-151-0/+6
| | | | | * share/txr/stdlib/match.tl (compile-op-match): New function. (compile-match): Route op operator to new function.
* matcher: support @(and pats ...) operator.Kaz Kylheku2021-01-151-16/+18
| | | | | | | | | | | | | | This is implemented using exactly the same code as @(or ...); the only difference is whether the and or or operator is used in the expression. * share/txr/stdlib/match.tl (compiile-or-match): Renamed to compile-or-parallel match. Some local variables are renamed to avoid being OR-specific. The operator is extracted from the pattern, and inserted into the guard expression. That one insertion is the only differnce between and and or. (compile-match): Route the or operator to the renamed function. Rout the new and operator to it also.
* matcher: remove useless code from @(some ...)Kaz Kylheku2021-01-151-8/+11
| | | | | | | | | * share/txr/stdlib/match.tl (compile-loop-match): Eliminate repeated (op eq 'some) tests by evaluating this once into the some-p variable. Do not wastefully generate the code that pushes values onto accumulation lists if we are translating the some operator; those lists are ignored. Don't generate those accumulation variables themselves at all.
* matcher: support @(or pats ..) operator.Kaz Kylheku2021-01-151-0/+17
| | | | | * share/txr/stdlib/match.tl (compile-or-match): New function. (compile-match): Route or operator to new function.
* matcher: support @(some pat) operator.Kaz Kylheku2021-01-151-4/+8
| | | | | | | | | | | | | | | | This is the existential quantifier to accompany @(all). * share/txr/stdlib/match.tl (compile-loop-match): Check for the some symbol in a few places and adjust the output. We don't need a local binding of the patter's variables, only the temps. The values go directly to the outer binding of the variables which are not shadowed now. We also don't need the nreverse logic to set the outer variables: var-exprs is nil at the outer level. The polarity of the loop termination test is reversed: we quit the loop on the first match, as is the polarity of the return value: if the loop is aborted early t is returned instead of nil. (compile-match): Wire in the some operator.
* matcher: some renaming in all match.Kaz Kylheku2021-01-151-10/+12
| | | | | | | | | | | | This is in anticipation of using the same function to compile other patterns that involve iteration. * share/txr/stdlib/match.tl (compile-all-match): Function renamed to compile-loop-match. The successful match and loop termination variables are renamed to different symbols. Also, test for the usr:all* symbol explicitly rather than all for making the test consp. (compile-match): Follow function rename.
* matcher: use flag to eliminate block.Kaz Kylheku2021-01-151-3/+4
| | | | | | | * share/txr/stdlib/match.tl (compile-all-match): We use a flag to break out of the loop instead of (return). The loop's block is thereby later eliminated by the compiler. For this we re-purpose the same all-match-p-var symbol.
* matcher: fix semantics of empty @(all ...) match.Kaz Kylheku2021-01-151-2/+4
| | | | | | | | | | | | * lisplib.c (match_set_entries): Ensure usr:all* is interned. * share/txr/stdlib/match.tl (compile-all-match): When the operator is the existing all, we must listp as a guard, not consp, because an empty list must match vacuously by virtue of not containing any counterexample to the pattern. For situations when a vacuous empty match is not desired, we support the all* alternative operator, which uses consp. (compile-match): Wire in the all* operator.
* matcher: support @(all pat) operator.Kaz Kylheku2021-01-151-0/+37
| | | | | * share/txr/stdlib/match.tl (compile-all-match): New function. (compile-match): Hook it in.
* matcher: allow omitted variabel in predicatesKaz Kylheku2021-01-151-1/+1
| | | | | | | | | | For instance @(oddp) instead of @(oddp x) to require an element to satisfy oddp without capturing it to a variable. * share/txr/stdlib/match.tl (compile-predicate-match): Make the symbolic argument optional, defaulting to nil. A nil symbol is already treated as pseudo-variable which consumes an item without binding to a variable.
* matcher: improve error reporting.Kaz Kylheku2021-01-151-12/+16
| | | | | | | | | | | | | | So quick and dirty; you have to love special variables. * share/txr/stdlib/match.tl (*match-form*): New special variable. (compile-var-match, compile-predicate-match, compile-let-match): Use compile-error instead of error, passing the value of *match-form* as the context. (compile-match): Ditto, and eliminate unreachable case from cond form. (when-match): Capture form directly into special variable using :form *match-form*.
* matcher: factor out vars into common base.Kaz Kylheku2021-01-141-18/+18
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/match.tl (match-vars): New struct. Holds vars and expressions, and provides the method to zipper them up into the assignments. (match-guard, compiled-match): Inherit from match vars. match-guard loses temps and temp-exprs. It now has vars and var-exprs from the base and those are used instead. (compiled-match get-temps): Follow temps vars rename. (compiled-match wrap-guards): Use assignments method inherited from base instead of assignments function. (assignments): Function removed. (compile-struct-match, compile-vec-match, compile-cons-structure): Follow vars temps rename in match-guard struct. (when-mach): Use assignments method of compiled-match instead of assignments function.
* new: structural pattern matching.Kaz Kylheku2021-01-141-0/+184
| | | | | | | | * lisplib.c (match_instantiate, match_set_entries): New static functions. (lisplib_init): Register autoload using new statics. * share/txr/stdlib/match.tl: New file.
* Copyright year bump 2021.Kaz Kylheku2021-01-1439-39/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * METALICENSE: 2020 copyrights bumped to 2021. Added note about SHA-256 routines from Colin Percival. * LICENSE, LICENSE-CYG, Makefile, alloca.h, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, chksum.c, chksum.h, chksums/crc32.c, chksums/crc32.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lex.yy.c.shipped, lib.c, lib.h, linenoise/linenoise.c, linenoise/linenoise.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/asm.tl, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/compiler.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/copy-file.tl, share/txr/stdlib/debugger.tl, share/txr/stdlib/defset.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/each-prod.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/param.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/quips.tl, share/txr/stdlib/save-exe.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/trace.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/vm-param.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, time.c, time.h, tree.c, tree.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, vm.c, vm.h, vmop.h, win/cleansvg.txr, y.tab.c.shipped: Copyright year bumped to 2021.
* quips: new entriesKaz Kylheku2021-01-071-0/+2
| | | | | * share/txr/stdlib/quips.tl (sys:%quips%): East Van cross and reference to urban myth regarding Sports Illustrated cover.
* quips: improve one about side-effects.Kaz Kylheku2021-01-051-1/+1
| | | | * share/txr/stdlib/quips.tl (sys:%quips%): Updated.
* awk: bugfix: load compiled verison of conv.tl.Kaz Kylheku2020-12-291-1/+1
| | | | | * share/txr/stdlib/awk.tl: Load "conv", not "conv.tl", so that if there is a .tlo present, it is loaded instead.
* awk: bugfix: fconv symbols not in usr package.Kaz Kylheku2020-12-291-12/+12
| | | | | | | * share/txr/stdlib/conv.tl (sys:conv-let): Use usr: package prefix on the conversion symbols i, o, x, b. They are being interned in the system package, which breaks the awk fconv macro.
* quips: use random-state argument in shuffle call.Kaz Kylheku2020-12-291-2/+1
| | | | | * share/txr/stdlib/quips.tl (quip): Don't bind *random-state*; pass an argument to shuffle.
* quips: new one.Kaz Kylheku2020-12-281-0/+1
| | | | * share/txr/stdlib/quips.tl (sys:%quips%); New entry.
* quip: function cycles through all quips.Kaz Kylheku2020-12-281-1/+6
| | | | | | * share/txr/stdlib/quips.tl (sys:%shuffled-quips%): New variable. (quip): Pop quips from the new variable. When the list is empty, populate it by shuffling the quips.
* Version 245txr-245Kaz Kylheku2020-10-101-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. Fixed repeated word in documentation under env-hash. * share/txr/stdlib/ver.tl: Bumped from incorrect 243 value to 245.
* New quip: inspired by dumb phone messages.Kaz Kylheku2020-12-101-0/+1
| | | | * share/txr/stdlib/quips.tl (sys:%quips%): New entry.
* quips: three new entries.Kaz Kylheku2020-11-161-0/+3
| | | | * share/txr/stdlib/quips.tl (sys:%quips%): Add new quips.
* compiler: bump up compiled file version to 5.1.Kaz Kylheku2020-10-091-1/+1
| | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (%tlo-ver%): Bump minor version from 0 to 1. Because the major version doesn't change, these files will be loaded by TXR 216 through 243, because those versions only look at the major number. The upcoming 244 will continue to do that. What the minor number increase indicates is that the compiled files do not use the deprecated movi instruction group. If a future version of TXR removes the instructions from the VM, it will then insist on only loading version 5 files if the minor number is at least 1. Version 5.0 files will be rejected, as will version 4 or lower.
* quips: four new entries.Kaz Kylheku2020-10-061-0/+4
| | | | * share/txr/stdlib/quips.tl (sys:%quips%): Add four quips.
* quips: two new entries.Kaz Kylheku2020-10-051-0/+2
| | | | * share/txr/stdlib/quips.tl (sys:%quips%): Add two quips.
* New: quip function for random humor.Kaz Kylheku2020-10-041-0/+73
| | | | | | | | | | | | Add this to your .txr_profile startup file. * lisplib.c (quips_instantiate, quips_set_entries): New static functions. (lisplib_init): Register autoloading of quip. * share/txr/stdlib/quips.tl: New file. * txr.1: Documented.
* compiler: don't use move immediate instructions.Kaz Kylheku2020-10-012-5/+0
| | | | | | | | | | | | * share/txr/stdlib/compiler.tl (comp-atom): Remove the special case for small fixnums and characters which encodes their value in a movi instruction as an immediate operand. This means that now these operands go into D registers, like all other literals. * share/txr/stdlib/vm-param.tl (%imm-width%): Remove this constant, reprensenting the maximum bit width of an immediate operand.
* vm: deprecate move-immediate instructions.Kaz Kylheku2020-10-011-0/+5
| | | | | | | | | | | | | | | | | | | The movrsi, movrmi and movrbi (move immediate {small, medium, big} to register) instructions are becoming deprecated. The reasoning is that character and fixnum operands can just go into a VM descriptor's data vector (D registers). Then they can be referenced directly without wastefully issuing an extra instruction. * genvmop.txr: Add a deprecated comment next to the enum constants of deprecated opcodes. * share/txr/stdlib/asm.tl (oc-base): Add Boolean property which indicates that an opcode is deprecated. This is a static class variable, defaulting to nil in the base class. (op-movrsi, op-movsmi, op-movrbi): Override base class deprecated property with a true value. * vmop.h: Regenerated.
* Version 243txr-243Kaz Kylheku2020-09-011-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Version 242txr-242Kaz Kylheku2020-08-141-1/+1
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* Version 241txr-241Kaz Kylheku2020-08-071-1/+1
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* New inaddr-str and in6addr-str functions.Kaz Kylheku2020-07-241-0/+114
| | | | | | | | | | | | | | | | | * lisplib.c (sock_set_entries): Register autoload entries for inaddr-str and in6addr-str. Register prefix symbol to be interned. * share/txr/stdlib/socket.tl (sockaddr-in, sockaddr-in6): Both structs get a new member, prefix, defaulting to the respective number of bits in the address. (inaddr-str, in6addr-str): New functions. * tests/014/iaddr-str, tests/014/inaddr-str.expected, tests/014/in6addr-str.tl, tests/014/in6addr-str.expected: New files * txr.1: Documented.
* New producting each operator family.Kaz Kylheku2020-06-281-0/+75
| | | | | | | | | | | | | * lisplib.c (each_prod_instantiate, each_prod_set_entries): New static functions. (lisplib_init): Register autoload of each-prod.tl via new functions. * share/txr/stdlib/each-prod.tl: New file. * txr.1: Documented. Also, under the existing collect-each family of operators, added the equivalence to mapping with lambda to help clarify the semantics.
* Version 240txr-240Kaz Kylheku2020-06-061-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* each: fix (each ()) segfault.Kaz Kylheku2020-06-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The (each ()) form should infinitely loop, and the compiled version does. The interpreter crashes, when that is a top-level form. The reason is that the underlying sys:each-op operator uses an empty list of variable names as an indication to use the bindings from the parent lexical environment. And in that particular case, the let is also empty. The whole thing looks like: (let () (sys:each-op each nil)) If this is a top-level expression, then op_let receives a null environment pointer. Since it has no bindings to add, it doesn't extend the environment chain and passes a null environment pointer down to op_each, which that tries to use, because it's told to reach into it for bindings. Let's use the t symbol for that instead, so then the above would look like: ;; the t and only the t means "access parent env" (let () (sys:each-op each t)) And then, let's also fix it so that t is never used in this case when there are no vars: ;; no t, and so don't access parent env. (let () (sys:each-op each nil)) * eval.c (op_each): Get the bindings from the parent environment if vars is t, rather than when it's null. (me_each): When the symbols are not being inserted into the sys:each-op form, then insert t to indicate that, rather than nil. If the source form specifies an empty list of bindings, then insert nil, not t. * share/txr/stdlib/compiler.tl (expand-each): Get the list of variable names from the parent lexical environment when vars is t, rather than when it's null.
* Convert each-family operators to use iter-begin.Kaz Kylheku2020-06-021-4/+5
| | | | | | | | | | | | | | | | | | | With this change we can do (each ((x vec)) ...) with reasonable efficiency, because we are no longer marching through the vector with cdr, copying the suffix. * eval.c (get_iter_f): New global variable. (op_each): Obtain iterators for all the objects with iter_begin, instead of treating them as lists. Probe the iterators for termination with iter_more, get the items with iter_item instead of car and step with iter_step instead of cdr. (eval_init): gc-protect the get_iter_f function and initialize it. * share/txr/stdlib/compiler.tl (expand-each): Replace the car/cdr and null testing with iter-init, iter-more, iter-item and iter-step.
* Version 239.txr-239Kaz Kylheku2020-06-021-1/+1
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.