summaryrefslogtreecommitdiffstats
path: root/stdlib
Commit message (Collapse)AuthorAgeFilesLines
* compiler: code clean-up in peephole optimizer.Kaz Kylheku2021-09-281-5/+5
| | | | | | | | | | | * stdlib/optimize.tl (basic-blocks peephole-block): When we match a branching instruction, including jend, we know that's the end of the basic block. So there is no need to splice the (rest insns) into the output; let's get rid of that. On the other hand, there is also no need to have a specific pattern match for the end of the list such as ((jmp @label)). This costs extra cycles to validate. Let's consistently match these basic-block terminating instructions using prefix patterns like ((jmp @label) . @nil)).
* quips: one in French.Kaz Kylheku2021-09-261-0/+1
| | | | * quips.tl: New quip.
* New variable: *child-env*.Kaz Kylheku2021-09-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This specifies the environment to be used for executing programs. * stream.c (open_subprocess, run): Check *child-env* variable and if other than t, then install the environment before execvp. In the spawn-based version of run, we save and restore the environment around the spawn call, if *child-env* is in effect. * sysif.c (child_env_s): New symbol variable. (exec_wrap): If *child-env* is other than t, then save the environment in a list, and install the specified environment before calling execvp. If that function returns, restore the environbment. * sysif.h (child_env_s): Declared. (child_env): New macro. * tests/018/process.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: replace-env.Kaz Kylheku2021-09-251-0/+1
| | | | | | | | | | | | | | | | | | | Using this new function together with env, it's now possible to save the set of environment variables, clobber it to a specified set (possibly empty) and then restore it. Useful for improved security in running child processes. * lib.[ch] (chk_substrdup_utf8): New function. * sysif.c (replace_env): New function. (sysif_init): Register replace-env intrinsic. * sysif.h (replace_env): Declared. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* path access tests: use real credentials.Kaz Kylheku2021-09-251-13/+13
| | | | | | | | | | | | | | | | | The various accessibility functions like path-writable-to-me should use the real credentials, the same way that the POSIX access function does. This makes them much more useful and secure in setuid programs, since they answer the question "does the underlying user, without these elevated privileges, have this access". * stdlib/path-test.tl (path-mine-p): Use getuid, not geteuid. (path-my-group-p): Use getgid, not getegid. (sys:path-access, path-private-to-me, path-strictly-private-to-me): Use getuid, getgid and rename euid variable to uid. * txr.1: Updated.
* path-search: rewrite in C with saner semantics.Kaz Kylheku2021-09-251-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | The new function: - just returns the name if it contains path name components. - returns nil if the name is "." or "..". - tests for existence only, not permission to execute. * lisplib.c (path_test_set_entries): Do not auto-load path-test module on the path-search symbol, since it is no longer implemented there. * stdlib/path-test.tl (path-search): Function removed. * stream.c (path_var_sep_char): New global variable. (path_search): New function. (detect_path_separators): Also set path_var_sep_char to semicolon on Cygnal. (stream-init): Register path-search intrinsic here now. * stream.h (path_var_sep_char, path_search): Declared. * tests/018/path-test.tl: New tests. * txr.1: Documentation revised for path-search.
* New variants of each operator for sum and product.Kaz Kylheku2021-09-233-1/+92
| | | | | | | | | | | | | | | | | | | | | | | | | * lisplib.c (arith_each_instantiate, arith_each_set_entries): New functions. (each_prod_set_entries): Add sum-each-prod, sum-each-prod*, mul-each-prod and mul-each-prod* as autoload triggers for each-prod.tl, where those macros are now defined. (lisplib_init): Register autoloading of arith-each.tl via the two new functions. * stdlib/arith-each.tl: New file. * stdlib/each-prod.tl (sys:expand-each-prod*): Handle sum-each-prod* and mul-each-prod* in the same way, by mapping to their parallel binding counterparts. (sys:expand-arith-each-prod): New function. (sym-each-prod, mul-each-prod, sum-each-prod*, mul-each-prod*): New macros. * tests/016/arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* math: quantile estimator using P-Squared algorithm.Kaz Kylheku2021-09-221-0/+1
| | | | | | | | | | | | | | | | | | | * Makefile (psquare.o): New object file. * arith.c (psq_ops): New static structure. (quant_fun): New static function. (quantile): New function. (arith_init): Register quantile intrinsic. * arith.h (quantile): Declared. * psquare.c, psquare.h: New files. * tests/016/arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* compiler: reduce single-arg logior and logand.Paul A. Patience2021-09-141-1/+1
| | | | | * stdlib/compiler.tl (compiler comp-fun-form): Reduce single-argument logior and logand calls to just the argument.
* defset: add set-mask and clear-mask.Paul A. Patience2021-09-145-24/+35
| | | | | | | | | | | | | | | | | | | | * stdlib/defset.tl (set-mask, clear-mask): New update macros. * stdlib/optimize.tl (calc-liveness): Use the new macros. * stdlib/socket.tl (sys:str-inaddr-net-impl, str-in6addr-net): Same. * stdlib/termios.tl (set-iflags, set-oflags, set-cflags, set-lflags, clear-iflags, clear-oflags, clear-cflags, clear-lflags): Same. * lisplib.c (defset_set_entries): Add set-mask and clear-mask to autoload symbols for defset. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* compiler: fix random perturbance in reg allocation.Kaz Kylheku2021-09-141-2/+2
| | | | | | | | | | | | | | | At optimization level 2 or higher, an issue occurs whereby code generation exhibits instabilities. The same code is compiled slightly differently (but not incorrectly) depending on irrelevant circumstances, due to some different registers being used. * stdlib/compiler.tl (compiler eliminate-frame): Do not free the newly allocated t-registers inside a dohash loop. We have a separate list of them in order; just hand that off to free-tregs. The dohash loop is not ordered, because it traverses a hash, which is keyed by object identities; i.e. machine addresses assigned by memory allocation.
* ffi, sockets: add sock-opt and sock-set-opt.Paul A. Patience2021-09-122-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new sock-opt and sock-set-opt functions are wrappers around getsockopt and setsockopt, respectively. All POSIX socket options are registered. Platform-specific options may be added in the future. * ffi.c (sock_opt, sock_set_opt): New functions. (ffi_init): Register sock-opt, sock-set-opt, sol-socket, ipproto-ip, ipproto-ipv6, ipproto-tcp, ipproto-udp, so-acceptconn, so-broadcast, so-debug, so-dontroute, so-error, so-keepalive, so-linger, so-oobinline, so-rcvbuf, so-rcvlowat, so-rcvtimeo, so-reuseaddr, so-sndbuf, so-sndlowat, so-sndtimeo, so-type, ipv6-join-group, ipv6-leave-group, ipv6-multicast-hops, ipv6-multicast-if, ipv6-multicast-loop, ipv6-unicast-hops, ipv6-v6only, tcp-nodelay. * lisplib.c (sock_set_entries): Add sock-opt and sock-set-opt. * stdlib/socket.tl (sock-opt): Define as syntactic place. * tests/014/socket-misc.tl: New cases, for sock-opt. (set-and-get): New macro. * txr.1: Documented. Also, mention that sock-bind enables so-reuseaddr. * stdlib/doc-syms.tl: Updated.
* sockets: remove excess apostrophe in sock-peer.Paul A. Patience2021-09-111-1/+1
| | | | | * stdlib/socket.tl (sock-peer): Remove excess apostrophe in getter.
* matcher: use function for match and match-ecase error.Kaz Kylheku2021-09-101-2/+8
| | | | | | | * stdlib/match.tl (match-pat-error, match-error): New functions. (match, match-ecase): Generate more compact code which just calls match-pat-error rather than throwf, and doesn't contain any string literals.
* exceptions: hack to store errno in string object.Kaz Kylheku2021-09-071-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Basic idea: when we throw an exception that pertains to a system error which has an errno code, we can stick the errno into the memory area of the character string, into the wchar_t that immediately follows the null terminator. We can do this because strings track their actual allocation size. A pair of setter/getter functions to set and retrieve this value are provided, and all functions in the code which can set such a code are updated to do so, simply by calling the newly added uw_ethrowf that drop-in replaces for uw_throwf. * lib.[ch] (string_set_code, string_get_code): New functions. * unwind.[ch] (uw_ethrowf): New function. * eval.c (eval_init): Register string-set-code and string-get-code intrinsics. * ftw.c (ftw_wrap): Switch to uw_ethrowf. * parser.c (open_txr_file): Likewise. * socket.c (dgram_overflow): Store the ENOBUFS error in errno, and use uw_ethrowf instead uw_throwf. (dgram_get_byte_callback, dgram_flush, sock_bind, to_connect, open_sockfd, sock_connect, sock_listen, sock_accept, sock_shutdown, sock_timeout, socketpair_wrap): Switch to uw_ethrowf. * stream.c (dev_null_get_fd, stdio_maybe_read_error, stdio_maybe_error, stdio_close, pipe_close, open_directory, open_file, open_fileno, open_tail, fds_subst, open_subprocess, open_command, remove_path, rename_path, tmpfile_wrap, mkdtemp_wrap, mkstemp_wrap): Switch to uw_ethrowf. * sysif.c (mkdir_wrap, ensure_dir, chdir_wrap, getcwd_wrap, rmdir_wrap, mknod_wrap, mkfifo_wrap, chmod_wrap, do_chown, symlink_wrap, link_wrap, readlink_wrap, close_wrap, val exec_wrap, stat_impl, do_utimes, pipe_wrap, poll_wrap, getgroups_wrap, setuid_wrap, seteuid_wrap, setgid_wrap, setegid_wrap, setgroups_wrap, getresuid_wrap, setresuid_wrap, setresgid_wrap, crypt_wrap, uname_wrap, opendir_wrap, getrlimit_wrap, setrlimit_wrap): Likewise. * termios.c (tcgetattr_wrap, tcsetattr_wrap, tcsendbreak_wrap, tcdrain_wrap, tcflush_wrap, tcflow_wrap): Likewise. * tests/018/errno.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* string-finish: new function.Kaz Kylheku2021-09-071-0/+1
| | | | | | | | | | | | * eval.c (eval_init): Register string-finish intrinsic. * lib.c (string_finish): New function. * lib.h (string_finish): Declared. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* ffi: ffi macro uses load-time.Kaz Kylheku2021-09-061-1/+1
| | | | | | | | | | | | | | | A number of functions take an argument which is a ffi type. Typically, this argument is produced using by a ffi-type-compile call which is produced by the ffi macro. But this ffi-type-compile call is invoked at run time, each time such a function is called. A solution for this is to have the ffi macro hoist the compilation to load time. * stdlib/ffi.tl (ffi): Add load-time wrapping to generated expression. * txr.1: Updated correspondence between (ffi ...) form and equivalent (ffi-type-compile form).
* ffi: add socklen-t type.Paul A. Patience2021-09-061-17/+18
| | | | | | | | | | * ffi.c: Include <sys/socket.h> if we HAVE_SOCKETS. (ffi_init_extra_types): Initialize socklen-t type if we HAVE_SOCKETS. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* load: new macros push-after-load and pop-after-load.Kaz Kylheku2021-09-031-0/+2
| | | | | | | | | | | | | * eval.c (me_push_after_load, me_pop_after_load): New static functions. (eval_init): Register push-after-load and pop-after-load intrinsic macros. * tests/019/load-hook.tl: Tests for correct expansion. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: delcons.Kaz Kylheku2021-09-021-0/+1
| | | | | | | | | | | | * eval.c (eval_init): Register delcons intrinsic. * lib.[ch] (delcons): New function. * tests/010/cons.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* load: new *load-hooks* feature.Kaz Kylheku2021-09-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | *load-hooks* lets a .txr, .tl or .tlo file specify actions to be taken when the loading of that file completes, whether normally or via an exception. They are also honored by process exit. For instance, with this, we can have a Lisp file that behaves like a script which cleans up after itself (e.g. removing temporary files) even if it is not run as a stand-alone program, but invoked via (load ...). Because it's not a stand-alone program, it cannot simply use the at-exit-call mechanism. The unwind-protect operator could be used, but it's inconvenient because it protects a single form. The *load-hooks* feature in effect protects all the top level forms of a load, similarly to unwind-protect. Also, unwind-protect does not guard against a process exit. (However, *load-hooks* does not guard against an abnormal exit, only normal termination). * eval.c (load_hooks_s): New symbol variable. (run_load_hooks): New function. (run_load_hooks_atexit): New static function. (load): bind *load-hooks* to nil around load. Implement the hooks processing via run_load_hooks, taking care to pass the load-time dynamic environment that has already been undone. (eval_init): Initialize load_hooks_s and register the *load-hooks* variable. Register run_load_hooks_atexit with atexit, so the current value of *load-hooks* is processed on process exit. * eval.h (load_hooks_s, run_load_hooks): Declared. * match.c (v_load): Similar changes as in load. * txr.c (txr_main): Run the load hooks with run_load_hooks immediately after processing the .txr or .tl file, before entering the listener. * tests/019/load-hook.tl: New directory and file * tests/load-hook.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* compiler: fix output path of compiled files.Paul A. Patience2021-09-011-1/+1
| | | | | | | | | | | The open-compile-streams function was calling trim-right with the arguments in the wrong order, resulting in an output path equal to the suffix of the input path. Regression introduced in 8d8fee2e506806d9c117b17432ef3a5ec0d6f457. * stdlib/compiler.tl (open-compile-streams): Swap in-path and suff arguments in trim-right call.
* Version 270.txr-270Kaz Kylheku2021-08-301-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date.
* buf, carray: remove de trop binding in accessors.Paul A. Patience2021-08-291-6/+2
| | | | | | | | They were forgotten in commit 1fb6f6691d5b6fb6b037bb14073694f651f2b9fc. * stdlib/ffi.tl (carray-sub, sub-buf): Remove binding which ensures the new value is evaluated only once (defset does this already).
* Version 269.txr-269Kaz Kylheku2021-08-281-1/+1
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* rand: provide random-buf function.Kaz Kylheku2021-08-261-0/+1
| | | | | | | | | | | * rand.c (random_buf): New function. (rand-init): random-buf intrinsic registered. * rand.h (random_buf): Declared. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* ffi: provide mmap through carray.Kaz Kylheku2021-08-221-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure: configure test for mmap depositing HAVE_MMAP into config.h. * ffi.c (struct carray): Subject to HAVE_MMAP, new mm_len member which keeps track of the size of an underlying mapping so that we can unmap it, as well as peform operations like msync on it. (make_carray): Initialize mm_len to 0. (MAP_GROWSDOWN, MAP_LOCKED, MAP_NORESERVE, MAP_POPULATE, MAP_NONBLOCK, MAP_STACK, MAP_HUGETLB, MAP_SHARED, MAP_PRIVATE, MAP_FIXED, MAP_ANON, MAP_HUGE_SHIFT, MAP_HUGE_MASK, PROT_READ, PROT_WRITE, PROT_EXEC, PROT_NONE, PROT_GROWSDOWN, PROT_GROWSUP, MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, MADV_WILLNEED, MADV_DONTNEED, MADV_FREE, MADV_REMOVE, MADV_DONTFORK, MADV_DOFORK, MADV_MERGEABLE, MADV_UNMERGEABLE, MADV_HUGEPAGE, MADV_NOHUGEPAGE, MADV_DONTDUMP, MADV_DODUMP, MADV_WIPEONFORK, MADV_KEEPONFORK, MADV_HWPOISON, MS_ASYNC, MS_SYNC, MS_INVALIDATE): #define as 0 if missing. (carray_munmap_op): New static function. (carray_mmap_ops): New static structure. (mmap_wrap, munmap_wrap): New functions. (mmap_op): New static function. (mprotect_wrap, madvise_wrap, msync_wrap): New functions. (ffi_init): Register mmap, munmap, mprotect, madvise and msync as well as numerous integer variables: map-growsdown, map-locked, map-noreserve, map-populate, map-nonblock, map-stack, map-hugetlb, map-shared, map-private, map-fixed, map-anon, map-huge-shift, map-huge-mask, prot-read, prot-write, prot-exec, prot-none, prot-growsdown, prot-growsup, madv-normal, madv-random, madv-sequential, madv-willneed, madv-dontneed, madv-free, madv-remove, madv-dontfork, madv-dofork, madv-mergeable, madv-unmergeable, madv-hugepage, madv-nohugepage, madv-dontdump, madv-dodump, madv-wipeonfork, madv-keeponfork, madv-hwpoison, ms-async, ms-sync, ms-invalidate, page-size. * ffi.h (mmap_wrap, munmap_wrap, mprotect_wrap madvise_wrap, msync_wrap): Declared. * tests/017/mmap.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* matcher: rename error-throwing macros.Kaz Kylheku2021-08-192-9/+9
| | | | | | | | | | | | | | | * stdlib/match.tl (must-match): Renamed to just match. It's just when-match without the "when". (must-match-case): Renamed to match-ecase, consistent with the case -> ecase naming scheme. * lisplib.c (match_set_entries): Names updated here. * tests/011/patmatch.tl: Test cases updated. * txr.1: Names updated here. * stdlib/doc-syms.tl: Updated.
* New ecase macros.Kaz Kylheku2021-08-181-0/+6
| | | | | | | | | | | | | | | | | | | | Even prior to discovering the recent defect in deffi, which was caused by a missing case in caseql, combined with poor testing, I was already thinking about adding ecase macros. The introduction of must-match and must-match-case also shows my motivation. That deffi bug convinced me to take action and implement these. * eval.c (case_error_s) New symbol variable. (me_ecase): New static function. (eval_init): Register new intrinsic macros ecaseq, ecaseql, ecasequal, ecaseq*, ecaseql* and ecasequal*. Intern case-error and initialize case_error_s. * txr.1: Documented. Also updated Exception Hierarchy diagram with match-error and case-error. * stdlib/doc-syms.tl: Updated.
* ffi: fix broken deffi support for variadic functions.Kaz Kylheku2021-08-171-1/+2
| | | | | | | | * stdlib/ffi.c (sys:analyze-argtypes): Add missing fallback case in filtering loop. This wouldn't have happened if we had a ecaseql macro, and used it. Or if we had coverage of this in tests. * tests/017/variadic.tl, tests/017/variadic.expected: New files.
* license: reformat to fit 80 columns.Kaz Kylheku2021-08-1642-546/+546
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile, alloca.h, args.c, args.h, arith.c, arith.h, buf.c, buf.h, chksum.c, chksum.h, chksums/crc32.c, chksums/crc32.h, combi.c, combi.h, 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, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, socket.c, socket.h, stdlib/asm.tl, stdlib/awk.tl, stdlib/build.tl, stdlib/compiler.tl, stdlib/constfun.tl, stdlib/conv.tl, stdlib/copy-file.tl, stdlib/debugger.tl, stdlib/defset.tl, stdlib/doloop.tl, stdlib/each-prod.tl, stdlib/error.tl, stdlib/except.tl, stdlib/ffi.tl, stdlib/getopts.tl, stdlib/getput.tl, stdlib/hash.tl, stdlib/ifa.tl, stdlib/keyparams.tl, stdlib/match.tl, stdlib/op.tl, stdlib/optimize.tl, stdlib/package.tl, stdlib/param.tl, stdlib/path-test.tl, stdlib/pic.tl, stdlib/place.tl, stdlib/pmac.tl, stdlib/quips.tl, stdlib/save-exe.tl, stdlib/socket.tl, stdlib/stream-wrap.tl, stdlib/struct.tl, stdlib/tagbody.tl, stdlib/termios.tl, stdlib/trace.tl, stdlib/txr-case.tl, stdlib/type.tl, stdlib/vm-param.tl, stdlib/with-resources.tl, stdlib/with-stream.tl, stdlib/yield.tl, 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.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, vm.c, vm.h, vmop.h: License reformatted. * lex.yy.c.shipped, y.tab.c.shipped, y.tab.h.shipped: Updated.
* quips: new system-programming-related quips.Kaz Kylheku2021-08-161-0/+2
|
* doc-syms: update.Kaz Kylheku2021-08-151-3/+5
|
* getaddrinfo: implement canonname.Kaz Kylheku2021-08-151-1/+2
| | | | | | | | | | | | | | | | Paul A. Patience noted that the canonname_s variable is not used in the C code. This indicates that the AI_CANONNAME functionality of getaddrinfo isn't implemented. Let's do that. * stdlib/socket.tl (sockaddr): New slot, canonname. (addrinfo): Default canonname to nil, not 0, since it is a string that may be absent. * socket.c (getaddrinfo_wrap): If the first address object has a non-null ai_canonname and it was requested via the flags, then stick that name into every returned structure. * txr.1: Documented.
* doc: improve.Paul A. Patience2021-08-141-2/+3
| | | | | | | | | | | | * RELNOTES: Fix various minor issues and stylistic issues. * configure: Remove repeated word and add missing word. * txr.1: Fix various minor, not-so-minor and stylistic issues. In particular, struct-from-args was misspelled in the .mets line and open-subprocess was missing from the .coNP line. * stdlib/doc-syms.tl: Updated.
* matcher: new must-match and must-match-case macros.Kaz Kylheku2021-08-131-0/+15
| | | | | | | | | | | | | * lisplib.c (match_set_entries): Intern the match-error symbol. Register autoloads for must-match and must-match-case. * stdlib/match.tl (match-error): Register exception symbol, as subtype of match-error. (must-match, must-match-case): New macros. * tests/011/patmatch.tl: Test cases. * txr.1: Documented.
* Version 268.txr-268Kaz Kylheku2021-08-071-1/+1
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* txr: @(eof) takes argument for binding termination status.Kaz Kylheku2021-08-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We extend the matching context structures to keep track of the underlying stream from which lines are being taken via the lazy list. Then the implementation of the @(eof) directive, when it hits the eof condition, can use this stream to gain access to the termination status. * match.c (match_line_ctx, match_files_ctx): New member, stream. (ml_all): Take stream argument and initialize new member. (h_call, do_match_line): Pass stream argument to h_call. (mf_all, mf_file_data): Take stream argument and initialize new member. (mf_from_ml): Propagate stream from line context to file context. (freeform_prepare, v_next_impl, match_filter, match_fun, extract): Pass stream argument where now needed. (v_eof): Implement termination status binding via the stream stored in the context. (open_data_source): Store stream in match files context. * tests/010/eof-status.txr: New file. * tests/010/eof-status.expected: New file. * Makefile (tst/tests/010/eof-status.ok): -B option for new test. * txr.1: Documented eof directive, argument and all. * stdlib/doc-syms.tl: Updated.
* oop: fix infelicity in new* and lnew* macros.Kaz Kylheku2021-07-311-9/+12
| | | | | | | | | | * stdlib/struct.tl (sys:new-expander): If the argument of new* or lnew* is dwim, then treat that as an expression, rather than as a boa-style construction. * tests/012/oop.tl: Tests for new* focusing on this issue. * txr.1: Documented.
* doc: *read-bad-json* fix and doc-syms update.Kaz Kylheku2021-07-311-0/+1
| | | | | | * txr.1: Fix code -> codn. * stdlib/doc-syms.tl: Updated.
* quips: new one.Kaz Kylheku2021-07-281-0/+1
| | | | * stdlib/quips.tl (sys:%quips%): New entry.
* Version 267.txr-267Kaz Kylheku2021-07-261-1/+1
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* op: set nested flag in correct context.Kaz Kylheku2021-07-191-10/+20
| | | | | | | | | | | | * stdlib/op.tl (sys:op-meta-p): Return an extended Boolean value: a true result is an integer indicating the depth of the variable. For instance @1 is depth 0, @@1 is depth 1 and so on. (sys:find-parent): New function. (sys:op-alpha-rename): When processing a nested meta, do not set the nested flag in the immediate parent. Use find-parent to go up to the correct level to which the meta belongs and set the flag there. * tests/012/op.tl: New test cases which depend on this.
* op: rename argument for consistency.Kaz Kylheku2021-07-191-2/+2
| | | | | | * stdlib/op.tl (sys:op-meta-p): Rename expr argument to exp. The symbol is not causing an issue here, but it's good to rename it for consistency with sys:op-rec-p and to thwart future problems.
* op: consolidate testing for @rec/@(rec ...)Kaz Kylheku2021-07-191-6/+6
| | | | | | | | | * stdlib/op.tl (sys:op-rec-p): Test for both the variable @rec and the expresson @(rec ...). Also, the expr argument of the function is renamed to exp because it causes a problem, due to that symbol, sys:expr, being the meta indicator. (sys:op-ensure-rec): Remove one test for (sys:var usr:rec), since sys:op-rec-p does it. Convert one equal-test to a call to sys:op-rec-p.
* op: fix bug in do.Kaz Kylheku2021-07-191-32/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The June 30 09e70c914ca83b5c7405aa633864db49f27efa05, subject "op: refactor do handling", introduced a regression breaking the tags.tl program. An implicit argument gets inserted twice: [[(do op list @1)] 'x] -> (x x) ;; incorrect/weird This was spotted by Paul A. Patience while working on extending tags.tl for Emacs. It's not exactly a regression because the original behavior is not documented or tested, and has issues; we simply cannot roll back the commit; a proper fix is required. How the above call is now supposed to work is that: - the @1 parameter belongs to the op, not to the do. - the do therefore has no explicitly given parameters of its own. - therefore the do inserts its parameter. In other words (do op list @1) is formally equivalent to (do op list @1 @@1). Both levels of function indirection require an argument: [[(do op list @1) 'x] 'y] -> (y x) [[(do op list @1 @@1) 'x] 'y] -> (y x) * stdlib/op.tl (sys:op-ctx): The structure gets a new slot, nested, which is a flag indicating whether unprocessed nested metas occur. This is critically needed because the sys:op-alpha-rename passes which are called with do-nested-metas being false do not insert nested metas into the gens list; they transform them and leave them in the syntax. Yet we must make decisions based on their presence. Conretely, we must be able to tell that (do op list @@1) has a meta against the outer (do ...), while we are just processing the do. (sys:op-alpha-rename): When replacing a nested meta syntax with the macro invocation, we set the nested flag of the parent context true. (sys:op-expand): Bring back the do-gen; we need it. We cannot simply insert @1 into the syntax, because that is not lexically transparent. If we add @1 to (do op ...) then that @1 is interpreted as belonging to the op, not to the do. We must also check the new Boolean flag nested to properly detect whether we have metas, including unexpanded nested metas. * tests/012/op.tl: New test cases combining (do op ...).
* New functions: getrlimit, setrlimit.Kaz Kylheku2021-07-131-0/+6
| | | | | | | | | | | | | | | | * stdlib/doc-syms.tl: Updated. * sysif.c (rlim_s, cur_s, max_s): New symbol variables. (rlim_st): New variable. (getrlimit_wrap, setrlimit_wrap): New functions. (sysif_init): gc-protect rlim-st. Initialize symbol vsariables. Create rlim struct type. Register getrlimit and setrlimit intrinsics. Register variables rlim-saved-max, rlim-saved-cur, rlim-infinity, rlimit-core, rlimit-cpu, rlimit-data, rlimit-fsize, rlimit-nofile, rlimit-stack and rlimit-as. * txr.1: Documented under new Unix Resource Limits section.
* Version 266.txr-266Kaz Kylheku2021-07-041-1/+1
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* compiler: disallow trailing slashes in path.Kaz Kylheku2021-07-101-1/+3
| | | | | * stdlib/compiler.tl (open-compile-streams): If in-path end in a path separator character, throw an error.
* doc-lookup: ignore BROWSER when empty.Paul A. Patience2021-07-101-8/+8
| | | | | | | | | * stdlib/doc-lookup.tl (open-url): Treat empty BROWSER variable as if it were unset (i.e., ignore it). Otherwise the doc function silently fails rather than falling back to alternative URL-opening methods. * txr.1: Documented.