summaryrefslogtreecommitdiffstats
path: root/share
Commit message (Collapse)AuthorAgeFilesLines
* symbol-function: support lambda expressions.Kaz Kylheku2019-09-271-2/+6
| | | | | | | | | | | | | | | | | * eval.c (lookup_fun): Check for a lambda expression and return a faked binding containing the interpreted function. (do_eval, op_fun): Remove checks for lambda that are now being done in lookup_fun. In many other places where lookup_fun is used, we still need lambda checks, like in the expander. * share/txr/stdlib/place.tl (sys:get-fun-getter-setter): Take form argument. Diagnose assignments to lambda, and to unknown function place syntax. (defplace symbol-function): Pass sys:*pl-form* to sys:get-fun-getter-setter as form argument. * txr.1: fboundp and symbol-function doc updated.
* stdlib: fix incorrect uses of compile-error.Kaz Kylheku2019-09-274-40/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Oops! We have many instances of compile-error being called in the old way with a format string as its first agument, instead of a context argument. * share/txr/stdlib/ifa.tl (ifa): Take :form argument, pass to compile-error. Let's call this "fix M". (sys:if-to-cond): Add form parameter, pass to compile-error. Let's call this let's call this "fix F". (conda, condlet): Fix M. * share/txr/stdlib/place.tl (sys:*pl-form*): New special variable. We need this in order to communicate the real place form to the place expander, similarly to how we communicate the original environment using sys:*pl-env*. (call-update-expander, call-clobber-expander, call-delete-expander): Bind sys:*pl-form* to the unexpanded place. (shift, lset): Fix M. (defplace fun): Arrange for value of sys:*pl-form* to be passed to compile-error. Let's call this "Fix P". (sys:get-mb): Fix F. (defplace symbol-macro): Fix P. (placelet*, placelet): Fix M. * share/txr/stdlib/txr-case.tl (txr-case-impl): Fix M. * share/txr/stdlib/with-resources.tl (with-resources): Fix M.
* op: eliminate useless quasiquote.Kaz Kylheku2019-09-151-1/+1
| | | | | * share/txr/stdlib/op.tl (sys:op-expand): Replace ^(,*args) with just args.
* Version 225.txr-225Kaz Kylheku2019-09-111-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* list-builder: remove wasteful slot accesses.Kaz Kylheku2019-09-101-11/+11
| | | | | | | * share/txr/stdlib/build.tl (list-builder add, list-builder pend, list-builder pend): Refer to previously cached variable holding self.head or self.tail, instead of re-accessing the slot.
* list-builder: simplify circularity check in pend.Kaz Kylheku2019-09-101-4/+1
| | | | | * share/txr/stdlib/build.tl (list-builder pend): Use tailp instead of last and eq.
* tests: add tests for list-builder and fix bug.Kaz Kylheku2019-09-101-1/+1
| | | | | | | * share/txr/stdlib/build.tl (list-buider pend*): Fix typo: apply should be append. Funny, this didn't propagate to ncon*. * tests/012/seq.tl: Some list-builder tests via build macro.
* list-builder: rewrite of basic methods.Kaz Kylheku2019-09-091-38/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewriting be addition, pending and nconcing methods of list-builder to avoid loops and rely on lower list processing functions. This cleans up the semantics and error messages. Some examples of behavioral changes: (build (pend "abc") (add #\d)) now returns "abcd", consistent with (append "abc" '(#\d)). Previously it returned '(#\d). (build (add 1) (pend 2) (pend 3)) now produces a "cannot append to 2" error. Previously it produced "copy: cannot copy object of type fixnum". * share/txr/stdlib/build.tl (list-builder add): Don't use copy-list; rather the idiom for copying a sequence in preparation for appending to it is (append x nil). This will blow up nicely if x is an atom other than nil. We use this trick twice. (list-builder add*): Simplify with append. (pend, pend*, ncon): Rewrite. (ncon*): Use nconc once on a combined argument list: this is borrowed from the rewritten pend*. * txr.1: Documentation updated with clarifications, particularly in the area of the requirements regarding destructive manipulation and substructure sharing.
* list-builder: use copy-list, not copy.Kaz Kylheku2019-09-031-6/+6
| | | | | | | * share/txr/stdlib/build.tl (list-buider add, list-builder add*, list-builder pend, list-builder pend*): Use copy-list rather than copy. This copies terminating atoms without complaining.
* list-builder: bugfix: broken self-appending.Kaz Kylheku2019-09-031-4/+7
| | | | | | | | | | | | | | | | | | | | The list builder is failing on the documented example (build (add 1 2) (pend (get)) (pend (get))) -> (1 2 1 2 1 2 1 2) wrongly constructing an infinite list. * share/txr/stdlib/build.tl (list-builder pend): When destructively appending the next argument, check whether the current tail is a tail of that object. If so, copy the object to prevent a cycle from forming. (list-builder pend*): When appending the old head to the catenated list, do the tail check and copy the object if necessary to prevent the creation of a cycle.
* Version 224.txr-224Kaz Kylheku2019-08-291-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* compiler: mac params: eliminate plen variable.Kaz Kylheku2019-08-291-10/+9
| | | | | | | | * share/txr/stdlib/compiler.tl (expand-bind-mac-params): Remove the plen gensym. We don't need to store the form length in a variable, because the generated length check code references the value exactly once. Let's just propagate that the length calculating expression into that code.
* compiler: elide nil var intializaton.Kaz Kylheku2019-08-281-2/+6
| | | | | | | | | | | | Virtual machine local variables registers don't require nil initialization. In cases when a complex variable initializer is known to return nil, we can elide the move instrution which moves that nil into the register. * share/txr/stdlib/compiler.tl (null-reg): New function. (compiler comp-let): Don't move the value of the output register of the init fragment into the variable, if that register is the null register t0.
* compiler: mac params: simplify optional presence indicators.Kaz Kylheku2019-08-281-15/+21
| | | | | | | | * share/txr/stdlib/compiler.tl (expand-bind-mac-params): Generate better Lisp code when presence indicating variables on optional parameters are not used. It's possible to bind the variable directly, instead of binding to nil and assigning it. The cases are split accordingly.
* compiler: mac params: late allocation for cursors.Kaz Kylheku2019-08-281-68/+69
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (expand-bind-mac-params): Allocate the curs gensym only when about to recurse over a nested parameter list, rather than unconditionally. Otherwise, we always end up allocating one more gensym than we actually use, for a lower nesting level that might not be there. Don't use unwind-protect for returning the cursor variable to the free-list; it makes no sense to be recovering that since any exception will be abandoning this function entirely.
* trace: bugfix: trace-redefine-check doesn't untrace.Kaz Kylheku2019-08-281-3/+3
| | | | | | | * share/txr/stdlib/trace.tl (sys:trace-redefine-check): Move the sys:untrace call before the warning throw. That throw doesn't return; it ends up transferring control to the continue catch, and so the untrace is skipped.
* compiler: bugfix: incorrect scoping in macro param binding.Kaz Kylheku2019-08-281-65/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The destructuring binder binds all of the variables in the template to nil values and then assigns to them as it walks the object that is being destructured. Unfortunately, this results in incorrect treatment of init-forms, which are evaluated in the wrong scope. They are actually evaluated in completely the wrong scope due to the use of up:env, but the problem can't be fixed by removing up:env. The approach here is to generate a big let* construct that binds the variables in sequence, rather than assigning to them. * share/txr/stdlib/compiler.tl (expand-bind-mac-params): The basic structure of the code remains the same, but the details are rewritten. Instead of emitting a body of forms, we emit let* bindings. Because some of the logic requires imperative statements, like stepping pointers through the destructured object, these are mixed into the variable initializations via progn. The local functions emit-stmt and emit-var provide the interface for doing this. There is a bit of trickery in the situation that an optional parameter also has the presence-indicator variable. We must bind the parameter in an environment in which that presence-indicator variable is not yet visible. This is achieved by binding the variable to a nil value, and then binding the presence indicator to an expression which sets the variable's value as a side effect, and yields a Boolean value that initializes the indicator.
* compiler: bugfix: colon keyword bungle in macro params.Kaz Kylheku2019-08-281-9/+7
| | | | | | | | | | | | | | | When the (set arg :) form is processed by a compiled version of the set operator, it blows up with "set: arguments must be pairs". This is because the compiled destructuring code is wrongly trying to apply special treatment to a colon symbol argument to an optional parameter. It is documented that such such treatment only happens in function calls, and not in the binding of macro parameter lists. Interpreted macro param binding gets it right. * share/txr/stdlib/compiler.tl (expand-bind-mac-params): Do not treat a : element in the structure as a missing optional argument, but as an ordinary value.
* compiler: relate mac bind error to right substructure.Kaz Kylheku2019-08-271-1/+1
| | | | | | | | * share/txr/stdlib/compiler.tl (expand-bind-mac-params): A nested destructuring error must be reported against the local parameter list, not the top-level one. The bind-mac-check call muts use the local par-syntax, not the original top-level params.
* compiler: for: bugfix: dangling label reference.Kaz Kylheku2019-08-261-1/+1
| | | | | | | | | | | An infinite for loop in which the test is explicitly given as nil rather than omitted fails to compile. A minimal repro test case for this is (compile-toplevel '(for () (nil) ()))). Spotted this while reading the compiler code. * share/txr/stdlib/compiler.tl (compiler comp-for): Test the test-p variable, not test, to determine whether or not to generate the loop skip label.
* list-builder: inserter methods return nil.Kaz Kylheku2019-08-171-7/+12
| | | | | | | | | * share/txr/stdlib/build.tl (list-builder): Methods add, add*, pend, pend*, ncon and ncon* return nil. * txr.1: Updated documentation to state that these methods return nil, rather than an unspecified return value. Improvements in build macro documentation.
* list-builder: dequeue capabilities with del/del* operators.Kaz Kylheku2019-08-171-5/+45
| | | | | | | | | | | | | | | * lisplib.c (build_set_entries): Add buildn for autload, and intern del and del* symbols. * share/txr/stdlib/build.tl (list-builder): New methods del and del*. (sys:list-builder-flets): Generate flet for del*. (sys:build-expander): New function, consisting of expansion logic previously in build function. Macrolet added for del. (build): Call sys:build-expander. (buildn): New macro. * txr.1: Documented.
* compile-file: include load-time as top-level form.Kaz Kylheku2019-08-161-0/+4
| | | | | | | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): recognize sys:load-time-lit as a top-level form and recurse through to compiling its constituent form. We check the flag whether the syntax had already been processed by the evaluator, though that currently cannot possibly happen for a form that has just been parsed from a file by compile-file itself. * txr.1: Defintion of top-level form (from compile-file POV) updated. Documentation of load-time updated.
* Version 223: ten years!txr-223Kaz Kylheku2019-08-141-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* compiler: inline-lambda: optimize constant apply list.Kaz Kylheku2019-08-091-65/+75
| | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (comp-inline-lambda): Pass nil to new argument of lambda-apply-transform, indicating top-level call. (lambda-apply-transform): Takes new argument indicating whether it's a recursive call. If the apply list expression is constant, then it is evaluated and treated as a list of arguments which are then turned into quoted constants individually and passed as fixed args in a recursive call. This eliminates the generation of code dealing with run-time evaluation and destructuring of the apply arguments.
* compiler: inline-lambda: optimize generated let.Kaz Kylheku2019-08-081-3/+8
| | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): We conditionally generate the outer let as an alet, if there are no shadowing issues. The shadowing test is very conservative: the intersection between the argument expressions and the lambda symbols must be empty. Also, we move the gensym for the apply list expression into the let*, because we need a real storage location that we can pop.
* pop: improve expansion.Kaz Kylheku2019-08-081-1/+1
| | | | | | * share/txr/stdlib/place.tl (pop): Use alet for binding the temporary rather than let, so that if (,getter) expands to a symbol, it will disappear.
* compiler: bugfix: eval order in inline lambda.Kaz Kylheku2019-08-071-52/+54
| | | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): The expander fails to observe left-to-right evaluation because if the trailing argument form is present, it is evaluated first, even though it is the last argument. Also, the argument evaluations are wrongly interleaved among the default expressions for optional arguments; they must be evaluated firt. We fix all this by allocating gensyms for all of the fixed argument forms, and binding these via an extra let wrapped around the output let* form. When generating the let* we refer to the gensyms instead of the original fixed arguments. This extra let needs optimizing, but it can't just be converted to an alet because of scoping issues.
* compiler: bugfix: scoping issue in inline lambda.Kaz Kylheku2019-08-071-1/+1
| | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): The gensym for binding the trailing argument expression must be bound before any of the parameters, otherwise the expression is exposed to the scope of the parameters that have been emitted so far. We use add* to put it at the front.
* compiler: inline lambda: incomplete opt param support.Kaz Kylheku2019-08-071-9/+20
| | | | | | | | | | | | | | The compilation of lambdas that are immediately called or applied is missing the support for the Boolean parameters that indicate whether optional arguments are present. * share/txr/stdlib/compiler.tl (lambda-apply-transform): Check whether the opt parameter items from the fun-param-parser object have a third element, the indicator variable, and emit the binding for it. This has to be done in all three cases: optional parameter statically present, statically missing, and dynamically determined from run-time apply list of unknown length.
* compiler: remove one-argument or.Kaz Kylheku2019-08-061-1/+1
| | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): Remove useless one-argument use of or operator.
* Version 222.txr-222Kaz Kylheku2019-07-301-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.
* Version 221.txr-221Kaz Kylheku2019-07-231-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* ffi: two-argument form of sizeof.Kaz Kylheku2019-07-111-2/+6
| | | | | | | | | | | | | | | If sizeof is given an extra argument (an expression which evaluates to an object), it can calculate the dynamic size of the FFI type in relation to representing that object. * ffi.c (dyn_size): New static function. (ffi_init): Register sys:dyn-size intrinsic. * share/txr/stdlib/ffi.tl (sizeof): Support additional argument, avoiding run-time compilation of the type expression with the help of load-time. * txr.1: Update documentation for sizeof macro.
* Version 220.txr-220Kaz Kylheku2019-07-081-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* compile-file: elide top-level atoms.Kaz Kylheku2019-07-071-1/+1
| | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): If a top-level form is compiled that is an atom, don't emit the translation, since it has no effect (beyond interning the symbol).
* compile-file: don't ignore atomic forms.Kaz Kylheku2019-07-071-22/+22
| | | | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): do not silently ignore forms that (after macroexpansion) are atoms; treat them like any other forms. This is mostly useless, but if unbound variables are used as top-level forms, it is diagnosed, and keeps the file compilation behavior closer to interpreted semantics.
* Version 219.txr-219Kaz Kylheku2019-07-011-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* stdlib: pass env to constantpKaz Kylheku2019-06-292-8/+8
| | | | | | | * share/txr/stdlib/except.tl (catch**): Obtain macro environment and pass to constantp. * share/txr/stdlib/place.tl (last, butlast): Likewise.
* keyparams: bugfix: key list order scrambled.Kaz Kylheku2019-06-291-17/+11
| | | | | | | | | | | | When the keyword parameter list contains a mixture of constant and non-constant default value expressions, the order of the extracted keys is scrambled, so values go to the wrong variables. * share/txr/stdlib/keyparams.tl (sys:build-key-list): Renamed to build-key-list-expr and rewritten to preserve the key order. (:key): Follow rename of build-key-list.
* keyparams: use environment for constantp.Kaz Kylheku2019-06-291-3/+3
| | | | | | * share/txr/stdlib/keyparams.tl (sys:build-key-list): Take macro environment parameter, and pass to constantp. (:key): Pass macro environment to sys:build-key-list.
* defset: small code improvement.Kaz Kylheku2019-06-291-15/+14
| | | | | | * share/txr/stdlib/defset.tl (defset-expander): Move with-gensyms to outermost scope so we can include nvsym in it, avoiding the explicit (nvnsm (gensym)) binding.
* defset: bind new-val-sym to temporary variable.Kaz Kylheku2019-06-281-11/+11
| | | | | | | | | | | | | | | | | | | | | | Users of defset no longer have to ensure that in the store form, the symbol which gives the new value to be stored is inserted only once. * share/txr/stdlib/defset.tl (defset-expander): Transform the store form by inserting a temporary variable using alet. (sub-list, sub-vec, sub-str): These place forms no longer require a local gensym. * txr.1: Updated doc. * tests/012/defset.tl: The expected output for the inc case now incorporates a gensym that comes from the compiled defset macro. Since we can't control that by means of the gensym counter, we resort to extracting it from the expansion itself, then check the test case against a template which incorporates that gensym. We check that the extracted item really is a gensym: it's a symbol with no home package whose name starts with "g".
* lnew: two regressions fixed.Kaz Kylheku2019-06-241-2/+2
| | | | | | | | | * share/txr/stdlib/struct.tl (sys:new-expander): The syntax (lnew (type boa args ...)) is not being handled at all due a typo in the case. Moreover, the syntax (lnew type slot0 val0 slot1 val1 ...) is broken due to a missing unquote on the type gensym in the output template.
* dump-to-tlo: move to sys package.Kaz Kylheku2019-06-201-1/+1
| | | | | | * share/txr/stdlib/compiler.tl (usr:dump-to-tlo): This function has no reason to be named by a usr package symbol. Renaming to sys:dump-to-tlo.
* Version 218.txr-218Kaz Kylheku2019-06-191-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.
* sub-list, sub-vec, sub-str: becoming accessors.Kaz Kylheku2019-06-171-0/+15
| | | | | | | | | | | * lisplib.c (defset_instantiate): Add sub-list, sub-vec and sub-str symbols as autoload triggers for defset.tl. * share/txr/stdlib/defset.tl (sub-list, sub-vec, sub-str): New syntactic places defined with defset. * txr.1: sub-list, sub-vec and sub-str documented as accessors.
* buf, carray: accessors must eval new value once.Kaz Kylheku2019-06-171-2/+6
| | | | | | * share/txr/stdlib/ffi.tl (carray-sub, sub-buf): Unfortunately, defset doesn't arrange for the new value to be evaluated once; we must do it.
* defset: code tidying.Kaz Kylheku2019-06-171-1/+1
| | | | | | * share/txr/stdlib/defset.tl (defset-expander): Reduce (,*params) to ,params, which is parallel with the ,args that it matches.
* defset: fix non-hygienic Lisp-1 evaluation.Kaz Kylheku2019-06-171-7/+7
| | | | | | | | * share/txr/stdlib/defset.tl (defset-expander): In code that binds user-supplied variables and contains a user-supplied form that refers to those variables, we can't use code like (op list (gensym)) or [mapcar car ...]. These are susceptible to capture of the symbols list and car.