summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* New functions: long-suffix, short-suffix.Kaz Kylheku2021-06-225-0/+116
| | | | | | | | | | | | | | * stream.c (short_suffix, long_suffix): New functions. (stream_init): short-suffix and long-suffix intrinsics registered. * stream.c (short_suffix, long_suffix): Declared. * tests/018/path.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* doc: formatting in quasiquote pattern matching.Kaz Kylheku2021-06-221-1/+1
| | | | | | * txr.1: Remove stray space in marking up the JSON hash pattern syntax. This space has no ill effect when reading the man page via nroff, but messes up HTML rendering.
* Dubious new functions cxr/cyr.Kaz Kylheku2021-06-216-0/+141
| | | | | | | | | | | | | | * lib.c (cxr, cyr): New functions. * lib.h (cxr, cyr): Declared. * eval.c (eval_init): Intrinsics cxr and cyr registered. * tests/012/cadr.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* lib: remove useless coerce.Kaz Kylheku2021-06-211-1/+1
| | | | | * lib.c (string): chk_strdup returns the wchar_t * type already; there is no need to coerce.
* subprocesses: cygwin fixes.Kaz Kylheku2021-06-202-5/+11
| | | | | | | | | | | | | | * stream.c (fds_subst, fds_swizzle, fds_restore): These functions are used on Cygwin by some functions that are based on spawn, and so must be avaiable. * tests/018/process.tl: Two fixes here. Firstly, the 1>&1 redirection in one of the tests should be 1>&2 on all platforms. That a temporary edit left behind from massaging the tests and the code. Secondly, some weird results are observed on Cygwin. The communication with the child sees an extra carriage return and space sneak in. I'm just codifying this as Cygwin's way of passing the test case; it's likely unfixable at the application level.
* glob: support sequence of patterns argument.Kaz Kylheku2021-06-202-12/+53
| | | | | | | | | | | * glob.c (glob_wrap): Negate the GLOB_WRAP flag should it be present on input. If the input is a string, process it much like before. Otherwise loop over the pattern and call globl multiple times, adding the GLOB_APPEND flag for the second and subsequent times, and breaking out of the loop if a control transfer is detected. * txr.1: Document.
* doc: recent typo.Kaz Kylheku2021-06-201-1/+1
| | | | | | * txr.1: Fix typo introduced during recent work related to txr-case. aspell caught this but I overwrote the fix with a stale edit buffer.
* subprocesses: a few test cases.Kaz Kylheku2021-06-201-0/+18
| | | | * tests/018/process.tl: New file.
* read/get-json: reject trailing junk in string input.Kaz Kylheku2021-06-204-4/+106
| | | | | | | | | | | | | | | | | * parser.c (lisp_parse_impl): If parsing from string, check for trailing junk and diagnose. JSON parsing doesn't use lookahead because it doesn't have a.b syntax, so the recent_tok gives the last token that actually went into the syntax, and not a lookahead token. So in the case of JSON, we call yylex to see if there is any trailing token. * tests/010/json.tl: Extend get-json tests to more kinds of objects, and then replicate with trailing whitespace and trailing junk to provide coverage for these cases. * tests/012/parse.t: Slew of new read tests and iread also. * txr.1: Documented.
* streams: pipe streams not needed if we have fork.Kaz Kylheku2021-06-192-3/+7
| | | | | | | | | | * stream.c (se_pclose, make_pipe_stream): define only if !HAVE_FORK_STUFF. (pipe_close): Don't call se_pclose in HAVE_FORK_STUFF build. The pipe_ops are no longer shared between popen pipes and open-process pipes. * stream.h (make_pipe_stream): Conditionally declare.
* system: stop using popen if we have fork.Kaz Kylheku2021-06-193-35/+62
| | | | | | | | | | | | | | | | | | | | | | | | On all the platforms on which TXR is regularly built, there is fork, including the Windows port via Cygwin. We therefore don't have to be using popen for the open-command function. The handling the stream redirection will be more efficient if we implement open-command in terms of open-process, and the special mode string extensions for redirection like ">21" will work, too. * stream.c (fds_subst, fds_swizzle): Define these functions only for !HAVE_FORK_STUFF platforms. (open_command): popen-based implementation moved down into a section of code for !HAVE_FORK_STUFF platforms. A separate implementation is written for HAVE_FORK_STUFF platforms which passes the command to an appropriate Windows native or POSIX interpreter. * utf8.c (w_popen): Nothing but open-command calls this function, so we don't need it on HAVE_FORK_STUFF platforms. Wrap with #if. * utf8.h (w_popen): wrap with #if.
* Version 263txr-263Kaz Kylheku2021-06-177-828/+882
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* sysif: define passwd_s if we have <grp.h>.Kaz Kylheku2021-06-171-1/+5
| | | | | | * sysif.c (passwd_s): Define for either HAVE_PWUID or HAVE_GRGID, since this symbol variable is referenced in code protected by either preprocessor symbol.
* android: fix compiler noise about __ANDROID_API__Kaz Kylheku2021-06-171-1/+1
| | | | | | | | * configure: Termux's gcc now defines __ANDROID_API__ which clashes with our definition. We cannot remove our definition because Termux's uses a uselessly low, conservative value. Thus, add a -U to undefine it before our -D redefinition.
* op: add comment why cadr is not used.Kaz Kylheku2021-06-171-0/+1
| | | | | | | * share/txr/stdlib/op.tl (sys:op-expand): Comment added. We cannot use cadr because that triggers autoload of cadr.tl, which uses defplace, which requires place.tl, which requires op, which is what we are in the middle of defining.
* doc: bad grammar under FFI ptr typeKaz Kylheku2021-06-171-1/+1
| | | | * txr.1: "update *the* datum".
* doc: formatting of meta-symbols under op.Kaz Kylheku2021-06-171-16/+26
| | | | | | * txr.1: Fix the typesetting of @rest, @rec, @num, @n and @n-1 in the op macro section. Missing word inserted: "recursive call *to* the function".
* op: tests, and fix (op progn ...) situationKaz Kylheku2021-06-172-1/+73
| | | | | | | | | | * share/txr/stdlib/op.tl (op-expand): For the sake of special processing applied to support the lop operator, the code assumes that the expanded syntax-2 is a list with at least two elements, such that we can do (cddr syntax-2). This is not true for instance in (op progn). * tests/012/op.tl: New file.
* New macro: flow.Kaz Kylheku2021-06-164-1/+45
| | | | | | | | | | | | | | | There has been interest in the community in a threading macro; a triviality which which applies the opip syntax to a value. Eschewing unusual glyph combinations like ->> and whatnot, I've chosen the English word flow for this. * share/txr/stdlib/op.tl (flow): New macro. * lisplib.c (op_set_entries): Set up autoload for flow. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* listener: new --noprofile option.Kaz Kylheku2021-06-164-2/+16
| | | | | | | | | | | | | * parser.c (repl): Set the rcfile variable to nil if opt_noprofile is true, to suppress reading it. * txr.c (op_noprofile): New global variable. (help): Add help text. (txr_main): Recognize noprofile option and set variable. * txr.h (opt_noprofile): Declared. * txr.1: Documented.
* txr-case: upkeep.Kaz Kylheku2021-06-164-5/+48
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/txr-case.tl (txr-case-impl): If the input is a stream, then convert it to a lazy list of lines, so that running multiple functions against it produces sane, backtracking behavior, like a @(cases) construct. * tests/011/txr-case.expected: Updated. * tests/011/txr-case.txr: Now actually contains a test case for txr-case. * txr.1: Address an issue reported by Paul A. Patience: the input to match-fun, txr-if and txr-when may be a stream. That has always been the case in the implementation. Also document that when the input is a single string, it is treated as a list. Document the new requirement in txr-case that a stream is converted into lazy list of lines.
* math: forbid dubious inequality comparisons.Kaz Kylheku2021-06-153-1/+71
| | | | | | | | | | | | | | | | | | | The issue, reported by Paul A. Patience, is that code like (< 1 "abc") is successfully producing a result. The root cause is that 1 is an iterable object, and so is treated as a sequence opposite to the "abc" operand. We should allow only true sequences in this situation. * arith.c (seq_lt_compat_check): New static function. Checks that neither of two sequences is SEQ_NOTSEQ or SEQ_HASHLIKE. (seq_lt, seq_le): Use seq_lt_compat_check to reject dubious inputs. * txr.1: Minor wording change in the related documentation, removing a gratuitous adjective. * tests/016/arith.tl: Inequality tests.
* subprocesses: don't bother saving descriptors.Kaz Kylheku2021-06-151-2/+21
| | | | | | | | | | * stream.c (fds_subst_nosave): New static function. (fds_clobber): New static function. Like fds_swizzle, without the saving. (open_subprocess, run): Use fds_clobber instead of fds_swizzle in the child process. It makes no sense to use fds_swizzle, which saves duplicates of the old descriptors, if fds_restore is not going to be called.
* subprocesses: move fds_swizzle to child process.Kaz Kylheku2021-06-151-29/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In all cases in which we control fork and exec, we should be doing the fds_swizzle setup in the child process. This has several benefits. We do not disturb the file descriptor layout of the parent. We don't have to set up a catch to do the cleanup. We don't have to do the clean-up in the child either; but just let it terminate. * stream.c (struct save_fds): New members subin, subout and suberr to hold the substitute file descriptors. The reason for this is so that we can calculate these in the parent process so that all the error checking is done in the parent and and carry them over to the child somehow. This structure is the natural place for that. (fds_getfd): New static function: just does the job of fetching and validating the file descriptor from the given stream: the first part of fds_subst. This will be done in the parent. (fds_subst): Now just does the substitution using a given file descriptor. Done in the child. Some variable renaming here; a better name for fd_orig is fd_sub, the substitute descriptor. (fds_prepare): New function: called in the parent process, it obtains the three file descriptors from the streams. (fds_swizzle): Just do fd_subst with the ready-made file descriptors, not dealing with the streams. Called in the child. (open_command): Add fds_prepare call that is now needed. (open_subprocess, run): Get rid of catch frame. Just call fds_prepare where fds_swizzle was previously called, and only call fds_swizzle in the child process.
* expander: bug: atoms in quasiliteral.Kaz Kylheku2021-06-152-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Via macros, atoms can sneak into a quasiliteral which then blow up because they get treated as strings without being converted. Example: (defmacro two () 2) `@(two)xyz` -> ;; error The expansion produces the invalid form, in which the 2 is subsequently treated as a string. (sys:quasi 2 "xyz") On the other hand, symbol macros don't have this problem: (defsymacro two 2) `@{two}xyz` -> "2xyz" The reason is that the (sys:var two) syntax will expand to (sys:var 2), and not 2. The straightforward, consistent fix is to ensure that the first case will also go to (sys:var 2). * eval.c (expand_quasi): If the expanded form is an atom which is not a bindable symbol, wrap it in a sys:var. * tests/012/quasi.tl: Test cases added. Also adding a compilation test for this file, cribbed from patmatch.tl.
* defsymacro: regression: don't expand replacement.Kaz Kylheku2021-06-153-26/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a regression that was introduced in 191. The change in 191 was trying to prevent defsymacro from being expanded immediately by the expander except in 190 compatibility. Unfortunately, this caused the whole defsymacro block not to be entered unless in 190 compatibility, otherwise taking the common exit which returns form_ex, containing the expanded replacement form. * eval.c (do_expand): Split up implementation of defvarl and defsymacro. In the defsymacro block, do not do any expanding on entry. Absent of compatibility mode, we just do some sanity checks and pass the entire form through. In 262 compatibility, we do the expansion to obtain form_ex. Then all the previous compat logic is wrapped in that block. * tests/011/macros-3.tl: Add a test case which confirms that symbol macros are lazily expanded. Weakness in the test suite is how these regressions creep in. * txr.1: Improve defsymacro documentation, spelling out clearly that the unexpanded replacement form is associated with the symbol. Eliminate obsolescent text suggesting that defsymacro is evaluated at macro time.
* txr.1: Correction to compat note for 190.Kaz Kylheku2021-06-151-1/+14
| | | | | | | | * txr.1: When writing up the compatibility notes for version 190, I missed the change that defmacro and defsymacro were switched away from instant evaluation by the macroexpander. That change introduced a regression which I just noticed, and this is noted also.
* doc: problems in mkstempKaz Kylheku2021-06-151-3/+3
| | | | | * txr.1: mkstemp: fix formatting problem in heading, and incorrect reference to mkdtemp with bad grammar.
* subprocesses: diagnose streams with no fileno.Kaz Kylheku2021-06-151-3/+9
| | | | | | | | * stream.c (fds_subst): Check that stream_fd returns a non-integer; if so, put out a more meaningful diagnostic, rather than allowing c_num to generate a "nil is not an integer" error. Also, let's incorporate the self string into the existing failed dup diagnostic.
* vim: recognize #/.../ inside brace variables.Kaz Kylheku2021-06-151-1/+1
| | | | | | * genvim.txr (bvar): Add tl_regex as a constituent. This occurs in quasiliteral pattern matching syntax, like `...@{a #/regex}...`.
* unwind: unbind dyn env when diagnosing unhandled exception.Kaz Kylheku2021-06-141-0/+2
| | | | | | | | | | * unwind.c (uw_unwind_to_exit_point): The error reporting relies on the *stderr* stream, but that stream may be bound in some funny way in a context where an exception has happened, without anything around it to restore that during unwinding. Before diagnosing, we should reset the dynamic environment to the top level, so that the global values of all dynamic variables are revealed.
* streams: *stdnull* lazily opens /dev/nullKaz Kylheku2021-06-142-9/+75
| | | | | | | | | | | | | | | | | | | | | The *stdnull* stream has been purely a stream-level abstraction. To make it useful for redirecting real file descriptors around the execution of external programs, we endow it with the ability to open /dev/null when it is asked to provide its file descriptor. * stream.c (struct dev_null): New structure. (dev_null_close, dev_null_get_fd, dev_null_get_prop): New static functions. (null_ops): Wire in the above functions instead of null_close, null_get_fd and null_get_prop. We need new functions because null_close and others do not belong to just the null stream; they are base operations used by other streams as default implementations for some kinds of unimplemented functions. (make_null_stream): Alocate a struct dev_null instead of a struct strm_base. Set the fd to -1. * txr.1: Documented.
* pic: take advantage of recent format work.Kaz Kylheku2021-06-141-7/+2
| | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num): format can now do everything internally that is required of a 0####.## type pattern; we don't have to generate the if logic with the gensym.
* pic: do mkstring cat macro time.Kaz Kylheku2021-06-141-1/+1
| | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num): The ##...## string that indicates an overflowing field can be created by the macro and inserted into the code as a literal object, rather than inserted as a mkstring call which calculates it run time each time the code is executed.
* format: revise numeric handling.Kaz Kylheku2021-06-143-85/+232
| | | | | | | | | | | | | | | | | | | | | | | There are a number of issues, such as left adjustment not working and such. This needs a better treatment from the requirements level, through to a set of test cases. * stream.c (max, min): Macros macros added, in their usual form. (vformat_num): Implement new rules which suppress the zero and space characters used in place of a sign if they overflow the field width. (formatv): Clamp integer precision field to width - 1 for integers, for consistency with floating-point handling. For floating-point values under ~a and ~s, do not force the second stage precision to width - 1; only clamp it if it is greater. * format.tl: Numerous new tests. * txr.1: Significant redocumenting of this area. The handling of numbers is described as a two stage process, clarifying the changing role of "precision" in the two stages.
* format: new precision - character for zero.Kaz Kylheku2021-06-143-0/+20
| | | | | | | | | | | * stream.c (formatv): The - precision option character produces a "sign" that is a zero. If this is used with leading zeros, it will avoid generating a space. The requirements can use improvement here, but one step at a time. * tests/018/format.tl: Some tests. * txr.1: Documented.
* doc: remove hyphenation.Kaz Kylheku2021-06-141-4/+4
| | | | * txr.1: non-negative changed to nonnegative.
* Version 262txr-262Kaz Kylheku2021-06-118-1262/+1349
| | | | | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise. * y.tab.c.shipped: Regenerated. Good catch! forgot to do this for most recent change to parser.y.
* doc: add pic examples.Kaz Kylheku2021-06-111-0/+37
| | | | * txr.1: Examples added.
* pic: support quasiliteral as format string.Kaz Kylheku2021-06-113-22/+80
| | | | | | | | | | | | * share/txr/stdlib/pic.tl (pic): Refactor string compilation code into local function which has access to the overall argument list. Recognize the quasiliteral case and translate by compiling all the string parts, then forming a recombined quasiliteral where the compiled parts are substituted. * tests/018/format.tl: test case for this. * txr.1: Documented.
* doc: codify optional alternatives notation.Kaz Kylheku2021-06-111-1/+7
| | | | | | | * txr.1: The notation [ a | b | c | .. ] is used throughout the document, but the Conventions paragraph describes only square brackets around a single optional element. The notation is now officially codified.
* pic: allow trailing exclamation.Kaz Kylheku2021-06-113-16/+31
| | | | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num, expand-pic, pic): Allow ### to be followed by a single !. This is not counted toward the field width. * tests/018/format.tl: Cover with some tests. * txr.1: Doc updated.
* pic: clarification and tests.Kaz Kylheku2021-06-112-3/+13
| | | | | | | | * tests/018/format.tl: Add tests which combine overflow flagging with +/-. The space generated by - contributes to overflow. * txr.1: Clarify overflow issue in documentation.
* tests: remove *stderr* to *stdnull* redirection.Kaz Kylheku2021-06-113-17/+7
| | | | | | | | | | | | | | The recent commit 225ff2fa2fdb9e5169db5e2c06dc3b0053b775bb titled "errors: avoid premature release of deferred warnings." obviates the need for dealing with noise when detecting errors from test cases. * patmatch.tl: Remove macro-time-let around several test cases. * tests/012/ifa.tl: Likewise. * tests/common.tl (macro-time-let): Macro removed.
* pic: test cases and fixes.Kaz Kylheku2021-06-112-8/+98
| | | | | | | | | | | | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num): Bug: when a field overflows, the (rest ...) call truncates the leftmost digit. A failing test case is (pic "#.#" 12) which produces "2.0" instead of "12.0". Firstly, we only need that logic at all in the zero padding case. When the number is positive, we stick in the + request, so we are sure to get a + character. The rest call then predictably chops off the + rather than a digit. (pic-join-opt): Fix two bugs here in the string-string combine case: using s2 instead of s1, and not splicing in rest. (expand-pic, pic): Implement tightening for escape sequences. If ~ is not followed by anything, or not followed by the documented characters for escaping, it is erroneous. * format.tl: Battery of new tests.
* tests: support testing for warnings.Kaz Kylheku2021-06-111-5/+15
| | | | | | | | * tests/common.tl (error-to-sym): Catch warnings, and convert to :warning symbol. (vtest): Support new kinds of expected value: :warning. The test is satisfied if it throws a warning at expansion time or during evaluation.
* errors: avoid premature release of deferred warnings.Kaz Kylheku2021-06-112-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | We don't want to be unconditionally releasing deferred warnings when error exceptions occur in evaluation or compilation. The reason is that the error might be handled, for instance by a speculative expansion. Then unwanted noise occurs, because deferred warnings have been released prematurely. * eval.c (eval_exception): Do not call uw_release_deferred_warnings here. (error_trace): But do call uw_release_deferred_warnings here, before printing anything else. We want to preserve the behavior that when error information is actually being printed to a stream, any deferred warnings are dumped first because they might pertain to the error. (I may revisit this requirement; perhaps deferred warnings rarely, if ever, pertain to an error). * share/txr/stdlib/error.tl (compile-error): Do not dump deferred warnings unconditionally. Only dump them if we are also printing the error message to stderr. Secondly, do not output the error message at all, unless there is no handler for the error.
* doc: document pic macro.Kaz Kylheku2021-06-102-0/+194
| | | | | | * txr.1: pic macro documented. * share/txr/stdlib/doc-syms.tl: Updated.
* format: fix precision field leading zero problems.Kaz Kylheku2021-06-102-8/+27
| | | | | | | | | | | | | | | | | * stream.c (formatv): Do not recognize multiple leading zeros as a single one; once the zero flag is set, if another zero is seen, it must be treated as one of the digits specifying the precision value. New requirement: before processing a format specifier, check for the situation that the leading zero has been specified, but no precision. Convert this situation to that of a precision of zero being given, with no leading zero. * txr.1: Document the ambiguity around the leading zero and how it is being handled when only the leading zero flag is given, and no actual precision. Add a note about what happens when zero precision is specified in ~a in conjunction with a floating-point value. Misspelled "pas" word fixed.
* New macro: pic.Kaz Kylheku2021-06-102-0/+125
| | | | | | | | | * lisplib.c (pic_instantiate, pic_set_entries): New static functions. (lisplib_init): Register autoloading of pic.tl module via new functions. * share/txr/stdlib/pic.tl: New file.