summaryrefslogtreecommitdiffstats
path: root/share
Commit message (Collapse)AuthorAgeFilesLines
* awk: implement ranges right using functions.Kaz Kylheku2017-10-291-53/+111
| | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk%--rng, sys:awk%--rng-, sys:awk%rng+, sys:awk%-rng+, sys:awk%--rng+): New functions. (sys:awk-mac-let): Rewritten range expander. The four basic ranges rng, rng-, -rng and -rng- are handled with in-line expansion, because by doing that we avoid unnecessarily evaluating the from-expression. The remaining cases expand to function calls to the new functions, which receive the flag vector, the index position in that vector and the values of the from and to expressions. The behavior change is that that the -- forms now do the right thing: they hide all leading records that satisfy the from-expression, right to the last record of the range if necessary. * tests/015/awk-rng.expected: Updated. * txr.1: Revise semantic description the -- range types, plus minor fixes.
* New convenience I/O functions for buffers.Kaz Kylheku2017-10-271-0/+32
| | | | | | | | | | | | | * lisplib.c (getput_set_entries): New autoload entries for file-get-buf, file-put-buf, file-append-buf, command-get-buf and command-put-buf. * share/txr/stdlib/getput.tl (sys:get-buf-common): New function. (file-get-buf, file-put-buf, file-append-buf, command-get-buf, command-put-buf): New functions. * txr.1: Documented.
* awk: fix buggy handling of new -- ranges.Kaz Kylheku2017-10-271-21/+17
| | | | | | | | | | | | The problem is that when records appear in the middle of the range which again match from-expr, they get suppressed. * share/txr/stdlib/awk.tl (sys:awk-mac-let): Get rid of the flag-mid variable. It cannot work because middle is a state in its own right that cannot be inferred from the existing states (nil, t, :end) and the value of from-expr. We get rid of the flag and introduce a :mid state value.
* op/do: nice error if arguments are not provided.Kaz Kylheku2017-10-261-0/+2
| | | | | | | | * share/txr/stdlib/op.tl (sys:op-expand): Throw error if argument list is empty. We refer to the compile-error function by quote to avoid triggering the auto-load of the module which defines it, due to the circular dependency on op.
* awk: bugfix: lack of hygiene in range implementation.Kaz Kylheku2017-10-261-9/+10
| | | | | | | | | | | | | The code is using a non-hygienic variable called flag as a placelet alias. This binding is visible to range expressions. For instance (rng #/x/ flag) actually references the range expression's internal flag, rather than producing a warning about an unbound variable. * share/txr/stdlib/awk.tl (sys:awk-mac-let): Allocate a gensym for the flag. Then use ,flag throughout the code templates rather than flag to insert the gensym wherever the symbol flag previously appeared.
* awk: retrieve range flag vector once per iteration.Kaz Kylheku2017-10-251-4/+6
| | | | | | | | | | | | | | | | | | | | | This is an improvement in the code generation related to awk range expressions. Previously, on each iteration, for each range expression, the awk state structure is accessed to retrieve the flag vector, which is then kept in a lexical variable. With this change, the retrieval is done once for all the range expressions, which share the same variable to access it. * share/txr/stdlib/awk.tl (sys:awk-compile-time): New slot, rng-vec-temp. (sys:awk-mac-let): Alias the flag variable to a simplified vecref expression which accesses the vector assumed to have been retrieved and bound to the variable named by the rng-vec-temp gensym. (awk): Add one more variable binding into the scope of the ranges: the binding of the variable named by the rng-vec-temp gensym, to an expression which retrieves the rng-vec from the Awk run-time state structure.
* awk: five new range operators.Kaz Kylheku2017-10-251-12/+63
| | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys;awk-mac-let): Provide the implementation for the local macros --rng, --rng-, rng+, -rng+ and --rng+. * tests/015/awk-rng.tl: New file. * tests/015/awk-rng.expected: New file. * txr.1: Documented.
* New variant of op: lop.Kaz Kylheku2017-10-191-5/+16
| | | | | | | | | | * lisplib.c (op_set_entries): Add lop to auto-load list. * share/txr/stdlib/op.tl (sys:op-expand): Recognize lop and implement its transformation. (lop) New macro. * txr.1: Documented.
* Version 186.txr-186Kaz Kylheku2017-09-161-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* places: use Lisp-1 macroexpansion where needed.Kaz Kylheku2017-09-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | A test case for this very subtle bug is this: (let ((v (list 1 2 3))) (symacrolet ((x v)) (flet ((x () 42)) (set [x 0] 0)))) Because x is being evaluated in the DWIM brackets which flatten the two namespaces into one, it must be treated as a reference to the flet, and so [x 0] denotes the function call. The assignment is erroneous. The incorrect behavior being fixed is that the places code macro-expands x in the Lisp-2 style under which the symacrolet is not shadowed by the flet. The substitution of v takes place, and the assignment assigns to [v 0]. * share/txr/stdlib/place.tl (sys:l1-setq, sys:l1-val): Use macroexpand-lisp1 rather than macroexpand.
* Version 185.txr-185Kaz Kylheku2017-08-301-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* bugfix: places: handling of lisp1 contexts.Kaz Kylheku2017-08-301-3/+3
| | | | | | | | | * share/txr/stdlib/place.tl (sys:l1-val): Use the expanded version of the place in the resulting form, because some of the operators like sys:lisp1-value will not expand it. Previously we were getting away with (sys:l1-val @1) expanding to (sys:lisp1-value @1) because the op expander would traverse through this blindly and replace @1.
* Rewriting op/do macros in Lisp.Kaz Kylheku2017-08-291-0/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new implementation treats the @1, @2 ... @rest op arguments as local macros, leveraging the power of the macro expander to perform the substitution which renames these to gensyms. As a result, the implementation is correct. The old implementation blindly walks the tree structure doing the substitution, so that @1 is substituted even though it is in a quoted literal: [(op list '(@1)) 42] -> ((#:arg-01-0166)) under the new implementation, '(@1) is left alone: [(op list '(@1)) 42] -> ((@1) 42) * eval.c (expand_quasi): Because the new op macro doesn't rudely reach into quasi forms to substitute sys:var elements, relying on macro expansion, we must now macro-expand sys:var elements. The sys:var macro created by op is smart enough to skip the compound ones that have modifiers; they are handled via the inner expansion of the symbol. That is to say, `@@1` contains the structure (sys:var (sys:var 1)). The sys:var macro ignores the outer sys:var. But existing behavior in expand_quasi expands the inner (sys:var 1), so the substitution takes place. (eval_init): Do not register the hacky old op and do macros, except in compatibility mode with 184 or older. * lisplib.c (op_set_entries, op_instantiate): New functions. (dlt_register): Register auto-loads for op and do macros via new functions, except when in compatibility mode with 184 or older, in which case we want the old build-in hacky op to be used. * share/txr/stdlib/op.tl: New file. * txr.1: Fixed or removed no-longer-true text which hints at special hacks implemented in the op expander. Added compatibility notes for all new compat-switched op behaviors.
* Version 184.txr-184Kaz Kylheku2017-08-231-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* buf: new buffer stream.Kaz Kylheku2017-08-141-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * buf.c (struct buf_strm): New struct type. (buf_strm_mark, int buf_strm_put_byte_callback, buf_strm_put_string, buf_strm_put_char, buf_strm_put_byte, buf_strm_get_byte_callback, buf_strm_get_char, buf_strm_get_byte, buf_strm_unget_char, buf_strm_unget_byte, buf_strm_seek, buf_strm_truncate, buf_strm_get_prop, buf_strm_set_prop, buf_strm_get_error, buf_strm_get_error_str): New static functions. (buf_strm_ops): New static struct. (buf_strm): New static function. (make_buf_stream, get_buf_from_stream): New functions. (buf_init): Register new intrinsic functiions make-buf-stream and get-buf-from-stream. Call fill_stream_ops on new buf_strm_ops to fill default operations in place of function pointers that have been left null. * buf.h (make_buf_stream, get_buf_from_stream): Declared. * lisplib.c (with_stream_set_entries): Add with-out-buf-stream and with-in-buf-stream to auto-load symbols for with-stream.tl module. * share/txr/stdlib/with-stream.tl (with-out-buf-stream, with-in-buf-stream): New macros. * txr.1: New section about buffer streams.
* Evaluate doloop forms in an implicit tagbody.Kaz Kylheku2017-07-311-1/+1
| | | | | | | | | | This eliminates one incompatibility between doloop and ANSI CL do. * share/txr/stdlib/doloop.tl (sys:expand-doloop): Wrap body in tagbody form. * txr.1: Documentation updated.
* Small code cleanup in tagbody.Kaz Kylheku2017-07-311-4/+3
| | | | | | | * share/txr/stdlib/tagbody.tl (tagbody): Reduce unnecessary use of DWIM brackets to parentheses in calculation of bblocks. Remove entry-lbl local variable, propagating its initform to its one and only use site.
* bugfix: tagbody mustn't expose anonymous block.Kaz Kylheku2017-07-301-8/+9
| | | | | | | | * share/txr/stdlib/tagbody.tl (tagbody): Use progn for the trivial case, and in the ordinary case, the sys:for-op special form directly rather than the for loop maro. sys:for-op doesn't introduce a block; the for macro is doing that.
* Optimize trivial tagbody.Kaz Kylheku2017-07-301-35/+37
| | | | | | | | | * share/txr/stdlib/tagbody.tl (tagbody): If the body contains no labels, then emit a simple block. Note that we should just be emitting a progn here; however, there is a bug in tagbody in that there is an anonymous block. This is not documented, and a consequence of the looping construct used. So for now we preserve that behavior in the reduced case.
* New macros doloop and doloop*.Kaz Kylheku2017-07-301-0/+54
| | | | | | | | | | * lisplib.c (doloop_set_entries, doloop_instantiate): New functions. (lisplib_init): Register autoload for doloop macros. * share/txr/stdlib/doloop.tl: New file. * txr.1: Documented.
* Version 183.txr-183Kaz Kylheku2017-07-191-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* new function: nthKaz Kylheku2017-07-181-0/+3
| | | | | | | | | | | | | | | | Just the ANSI CL nth for lists. * eval.c (eval_init): Register nth intrinsic. * lib.c (nth): New function. * lib.h (nth): Declared. * share/txr/stdlib/place.tl (nth): New place macro, trivially takes care of making nth an accessor. Place macros are terrific! * txr.1: Documented.
* getopts: New argument type :text.Kaz Kylheku2017-07-161-2/+4
| | | | | | | | | | * share/txr/stdlib/getopts.tl (opt-desc): New entry in valid-types, :text symbol. (sys:opt-parsed convert-type): Handle :text case. This is a no-op since :text applied no treatment. (opthelp): Provide help text for :text type. * txr.1: Documented :text getopts option type.
* getopts: Fix broken custom function option type.Kaz Kylheku2017-07-161-2/+2
| | | | | | This was broken on 2016-11-03 by the commit "Support simple list arguments in getopts." The sys:opt-parsed type has no type slot.
* global environment accessors can now create bindings.Kaz Kylheku2017-07-161-8/+6
| | | | | | | | | | | | | | The accessors symbol-value, symbol-function and symbol-macro can now be used to store a value to nonexistent bindings, which brings those bindings into existence. * share/txr/stdlib/place.tl (sys:ge-fun-getter-setter, sys:get-vb): Don't throw exceptions for nonexistent binding lookups: create and return the bindings instead. For methods, use static-slot-ensure rather than static-slot-set. Thus new methods can be defined by setting to a (meth ...) place. * txr.1: Doc updated.
* trace: allow format and * functions to be traced.Kaz Kylheku2017-07-161-2/+5
| | | | | | | | * share/txr/stdlib/trace.tl (sys:tr*, sys:trfm): New variables, holding the * and format functions. (sys:trace-enter, sys:trace-leave): Use format and * through the aliases, so we don't trigger infinite recursion if these are traced.
* Remove unused variable in placelet implementation.Kaz Kylheku2017-07-151-1/+1
| | | | | * share/txr/stdlib/place.tl (sys:placelet-1): Remove the genyms called steal-getter which is not referenced.
* Version 182.txr-182Kaz Kylheku2017-07-091-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* places: remove superfluous @1.Kaz Kylheku2017-07-091-2/+2
| | | | | | * share/txr/stdlib/place.tl (sys:get:fun-getter-setter): Remove superfluous @1 from op macro syntax, on the basis that (op function @1) is equivalent to (op function).
* structs: improve access to initfun and postinitfun.Kaz Kylheku2017-07-092-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this change, a struct type's initfun and postinitfun become mutable. This is achieved by modeling them as the pseudo-static-slots :initfun and :postinitfun. Effectively these now behave as reserved names which do not denote static slots but these special functions. * eval.c (lookup_fun): When (meth type slot) syntax is encountered, treat the slot names :init and :postinit specially: retrieve these special functions instead of accessing static slots. * share/txr/stdlib/place.tl (sys:get-fun-getter-setter): Similarly, when handling (meth type slot) syntax, return the alternative getter/setter functions for the special functions, not the static slot accessing functions. Also, getting rid of a useless @1 here in existing code, since (op foo @1) is equivalent to (op foo). * share/txr/stdlib/struct.tl (sys:defmeth): Check for the special names :init and :postinit, handling these through the appropriate setter functions rather than static-slot-ensure. * struct.c (init_k, postinit_k): New keyword symbol variables. (struct_init): Initialize init_k and postinit_k. Register intrinsics struct-get-initfun, struct-set-initfun, struct-get-postinitfun and struct-set-postinitfun. * (struct_get_initfun, struct_set_initfun, struct_get_postinitfun, struct_set_postinitfun): New functions. (method_name): For each struct type visited, check whether the function is the initfun or postinitfun and return the appropriate meth syntax if so. * struct.h (init_k, postinit_k, struct_get_initfun, struct_set_initfun, struct_get_postinitfun, struct_set_postinitfun): Declared. * txr.1: Documented. Updated description of method-name, defmeth, and documented new functions.
* ffi: new make-zstruct function and znew macro.Kaz Kylheku2017-07-021-0/+7
| | | | | | | | | | | | | * ffi.c (make_zstruct): New function. (ffi_init): Register make-zstruct instrinsic. * ffi.h (make_zstruct): Declared. * lisplib.c (ffi_set_entries): Add znew to autload list. * share/txr/stdlib/ffi.tl (znew): New macro. * txr.1: Documented make-zstruct and znew.
* Version 181.txr-181Kaz Kylheku2017-07-011-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: new macro, deffi-sym.Kaz Kylheku2017-06-261-0/+12
| | | | | | | | * lisplib.c (ffi_set_entries): Add deffi-sym to autload list. * share/txr/stdlib/ffi.tl (deffi-sym): New macro. * txr.1: Documented.
* Version 180.txr-180Kaz Kylheku2017-06-251-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* awk macro: bugfix: non-use of redirection mode strings.Kaz Kylheku2017-06-191-5/+3
| | | | | | | | | | | | | | | | The problem here is that ensure-stream ignores the mode argument and decides between "r" and "w". That is incorrect; the mode could be "a" for append. The second problem is that the ignored mode strings are also wrong. For an input pipe, "w" is specified rather than "r". * share/txr/stdlib/awk.tl (sys:awk-state ensure-stream): Use the mode argument. The cases consolidate, because all that need be distinguished here is file versus pipe. (sys:awk-mac-let): for the <! redirection (input from pipe), the mode must be "r", not "w".
* awk macro: bugfix: :output file stream not closed.Kaz Kylheku2017-06-191-1/+3
| | | | | | | | | | | | | | | | | | In the case when the :output clause of the awk macro opens a stream, it isn't closing it. Why don't we treat such a stream uniformly with redirections. * share/txr/stdlib/awk.tl (sys:awk-state :postinit): If a file is opened for output, then don't just install this file as self.output. Also place it into the self.streams hash, identified by using the key (:outf <name>), just like a (-> "name") redirection. This ensures that it will be closed when the awk macro terminates. It's also potentially useful in that output redirections referring to the name will use the same stream. * txr.1: Documented that streams opened by :output are closed, and that they are treated uniformly with redirections.
* Version 179.txr-179Kaz Kylheku2017-06-181-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: turn carray-sub into accessor.Kaz Kylheku2017-06-131-0/+3
| | | | | | | | | | | | | | | | * lisplib.c (ffi_set_entries): Register carray-sub for autoload. * share/txr/stdlib/ffi.tl (carray-sub): New place macro, aliases to sub. This is not 100% correct since that means it will admit non-carray objects, but the alternative is to clone the entire sub expander with a few changes, or else factor out sub expansion into a shared routine. Bleh ... * txr.1: Documented. We don't cover up the ruse we perpetrated, and reveal that it's just a place macro targetting sub.
* bugfix: autoload syntactic places.Kaz Kylheku2017-06-131-2/+6
| | | | | | | | | | | | | | | | | | | | | | | TXR Lisp doesn't autoload the definition of places. For instance if a (set (foo x) y) appears out of the blue and foo is keyed for autoload, it doesn't happen. The right place to fix this is to do the autload check in the place macro expander, since every place form is tried as a macro. We need to expose the lisplib_try_load function as a Lisp intrinsic. * lisplib.c (lisplib_init): Register sys:try-load intrinsic, mapped to lisplib_try_load. * share/txr/stdlib/place.tl (sys:get-place-macro): New function. (sys:pl-expand): Use sys:get-place-macro instead of direct lookup in *place-macro* hash. The new function tries to autoload the symbol if it finds no place macro for it.
* Version 178.txr-178Kaz Kylheku2017-06-121-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* awk macro: new fconv conversions c and cz.Kaz Kylheku2017-06-121-0/+4
| | | | | | | | | | * share/txr/stdlib/conv.tl (sys:conv-let): New local functions c and cz, using the new #\c radix conversion. * txr.1: Documented new extension under the fconv awk macro. Also fixed a typo here; the b conversion was exemplified as (c str).
* awk macro: fix broken rng.Kaz Kylheku2017-06-071-9/+15
| | | | | | | | | | | | | | | Bug: rng fails to activate when the to and from condition are true for the same record. * share/txr/stdlib/awk.tl (sys:awk-mac-let): Rename the flag-new gensym holder to flag-act, since it indicates whether the range is active, either from before or due to being activated by the current record. A new gensym is added to indicate whether the range is being deactivated in this record. The inclusive rng range refers to this variable rather than flag-old. But a bug emulation is provided to refer to the wrong variable. * txr.1: Added compatibility note.
* Version 177.txr-177Kaz Kylheku2017-06-071-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: functions and macros for basic type properties.Kaz Kylheku2017-06-021-0/+15
| | | | | | | | | | | | | | | | | | * ffi.c (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): New functions. (ffi_init): Registered intrinsics ffi-alignof, ffi-offsetof, ffi-arraysize, ffi-elemsize, ffi-elemtype. * ffi.h (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): Declared. * lisplib.c (ffi_set_entries): New autoload entries alignof, offsetof, arraysize, elemsize, elemtype. * share/txr/stdlib/ffi.tl (alignof, offsetof, arraysize, elemsize, elemtype): New macros. * txr.1: Documented new functions and macros.
* Version 176.txr-176Kaz Kylheku2017-05-211-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: new macro, deffi-var.Kaz Kylheku2017-05-201-0/+15
| | | | | | | | * lisplib.c (ffi_set_entries): Autload entry for "deffi-var". * share/txr/stdlib/ffi.tl (deffi-var): New macro. * txr.1: Documented.
* ffi: deffi generates fixed-arg defun.Kaz Kylheku2017-05-201-10/+10
| | | | | | | * share/txr/stdlib/ffi.tl (deffi): Since the arity of a foreign function is fixed, generate a fixed-argument defun. This provides a better check on the number of arguments than letting ffi-call detect it.
* ffi: overhaul ffi-call API and document it.Kaz Kylheku2017-05-201-1/+1
| | | | | | | | | | | | | | | * ffi.c (ffi_call_wrap): Take struct args * parameters rather than a list. Check that number of arguments matches required number from call desc. No need to build argument array any more; we just refer to the one in args. Also, the first two parameters are reversed for consistency with other functions. (ffi_init): Update registration of ffi-call to reflect type change. * ffi.h (ffi_call_wrap): Declaration updated. * txr.1: Documented ffi-call.
* ffi: turn carray-ref into accessor.Kaz Kylheku2017-05-201-0/+2
| | | | | | | | | | * lisplib.c (ffi_set_entries): Add carray-ref to list of autoload names. * share/txr/stdlib/ffi.tl (carray-ref, carray-refset): Registered function pair as a simple accessor. * txr.1: Updated carray-ref doc.
* awk: new feature: again operator.Kaz Kylheku2017-05-191-3/+3
| | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): Wrap a loop around around the two forms that split the record into fields and dispatch the main rule function. The loop repeats if the named block returns :awk-again. (sys:awk-mac-let): New local macro (again) which bails out of the :awk-rec block just like (next) does, but specifies :awk-again as the return value. * txr.1: Documented.