summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* ffi: closure: clear stale saved exit point.Kaz Kylheku2019-02-071-0/+2
| | | | | | | | | | | | | | | | | What happens if a FFI closure intercepts an exception, returns to the foreign code, but that caller does not return to Lisp where the exception will continue? Suppose the caller invokes another closure. In that situation, the lingering value of the s_exit_point variable causes problems for FFI calls. An example of this is callbacks from an event dispatching framework such as a GUI. When these callback closures return, control returns to the event loop, which itself doesn't immediately return to Lisp code. Rather, it processes more events and invokes more callbacks. * ffi.c (ffi_closure_dispatch_safe): One thing we can do is clear s_exit_point whenever we dispatch a closure.
* ffi: use padded return size in closure dispatch.Kaz Kylheku2019-02-071-2/+3
| | | | | | | * ffi.c (ffi_closure_dispatch_safe): When initially clearing a return value that has release semantics, use the padded size, not the nominal size. Let's get calculate this once and put it in a local.
* ffi: don't pad void return size to sizeof (ffi_arg).Kaz Kylheku2019-02-071-1/+1
| | | | * ffi.c (pad_retval): If the size is zero, don't pad it.
* bugfix: ffi-make-closure safe-p param.Kaz Kylheku2019-02-061-1/+1
| | | | | | * ffi.c (ffi_make_closure): Fix wrong argument defaulting on safe_p_in parameter, which leaves it always true, preventing unsafely dispatched closures from being created.
* doc: formatting under ffi-make-closure.Kaz Kylheku2019-02-061-2/+2
| | | | * txr.1: Run-on period on identifier; extra words.
* bugfix: deffi-cb-unsafe not autoloaded.Kaz Kylheku2019-02-061-0/+1
| | | | | * lisplib.c (ffi_set_entries): Add missinig autoload entry for deffi-cb-unsafe.
* ffi: make-zstruct must ignore padding slots.Kaz Kylheku2019-02-061-2/+4
| | | | | | | * ffi.c (make_zstruct): Don't convert zeros to a Lisp type and don't try to set the slot, if the slot name is nil. That's a padding slot which doesn't exist in the Lisp type; the slotset will blow up on it.
* ffi: whitespace fix.Kaz Kylheku2019-02-061-1/+1
| | | | * ffi.c (make_zstruct): space around assignment operator.
* parser: security: UTF-8 and NUL handling in literals.Kaz Kylheku2019-02-053-13/+14
| | | | | | | | | | | | | | | | | A null byte in regex and string literals is being processed as a #\nul instead of correctly turning into #\pnul. Bad UTF-8 is not being rejected. * parser.l (REGCHAR, LITCHAR): Use utf8_from_buffer to properly convert yytext using its true length, rather than utf8_from which assumes a null-terminated string. Thus null bytes (including the case of a yytext being single NUL) are handled properly. Check that the result is exactly one character (null-terminated buffer, two characters wide). * utf8.c (utf8_from): Unused function removed. * utf8.h (utf8_from): Declaration removed.
* linenoise: bugfix: caret notation in insert-at-end.Kaz Kylheku2019-02-051-1/+10
| | | | | | | * linenoise.c (edit_insert): In the optimized insertion case at the end of the buffer in multi-line mode, we must render control characters in the same manner as in the slow refresh case: namely, with the caret notatiion: ^@, ^A, ...
* linenoise: bugfix: caret notation for NUL.Kaz Kylheku2019-02-051-2/+2
| | | | | | | * linenoise/linenoise.c (sync_data_to_buf): The null character appears from the stream as 0xDC00. We must test for that and render it as ^@, counting a a width of two, rather than sending it to the terminal, counting as width of 1.
* linenoise: bugfix: regression in mlmode line wrap.Kaz Kylheku2019-02-051-1/+6
| | | | | | | | | | | | | | | | | | | | | The following problem happens: when charaters are inserted past the end of the line such that it wraps, hitting backspace or any cursor movement causes a spurious scroll. This was caused on Nov 1 2018 by bf85503b (linenoise: avoid refresh for new text in multi-line mode). The reason is that the maxrows variable isn't updated when we trivially add a character without repainting. * linenoise/linenoise.c (lino state): Document special value for need_refresh: when it is 2, the refresh doesn't perform a any output, but recalculates maxrows. (refreh_multiline): If need_refresh is 2, bail after updating maxrows. (edit_insert): When trivially adding a character at the end and just outputting it, if in multi-line mode, set need_refresh to 2.
* sum and prod take keyfun argument.Kaz Kylheku2019-02-024-21/+66
| | | | | | | | | | | | | * eval.c (eval_init): Adjust registrations of sum and prod to be binary functions with an optional argument. * lib.c (nary_op_keyfun, sumv, prodv): New static functions. (sum, prod): Implement optional keyfun argument via sumv and prodv helpers. * lib.h (sum, prod): Declarations updated. * txr.1: Documentation updated.
* pattern lang: diagnose undefined function facing EOF.Kaz Kylheku2019-02-011-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | This addresses the following issue. Suppose the query is something like this: @abc @(nonexistent) and there is one line of data. In this case, there is no error about a nonexistent function. The function lookup fails in vertical mode, so horizontal mode fallback takes place. But that just concludes that there is no data, and reports a failed match. But the programmer might have intended to invoke some function or directive that doesn't need to match anything, but rather has an important effect. In this patch we fix that. As part of the change, we disallow functions from shadowing horizontal directives. * match.c (match_files): Do not look up sys:var and sys:text through the directive table, but check for these. If the directive is not found in the vertical table, check the horizontal table; if found there, don't try it as a function but go to horizontal processing. Then if the function lookup fails, we diagnose a failed lookup; don't fall through to horizontal processing.
* style: convert assignment to initialization.Kaz Kylheku2019-02-011-3/+1
| | | | | | * match.c (match_files): Change pointless two-step initialization of a variable by assignment into straight initialization.
* compiler: new dump-compiled-objects function.Kaz Kylheku2019-02-013-7/+124
| | | | | | | | | | | | | * lisplib.c (compiler_set_entries): Register dump-compiled-objects for auto-loading. * share/txr/stdlib/compiler.tl (usr:dmp-to-tlo): New function. (compile-file): Code to be shared with dump-compiled-objects moved into dump-to-tlo function. (usr:dump-compiled-objects): New function. * txr.1: Documented.
* doc: document string and bignum merging.Kaz Kylheku2019-01-311-0/+55
| | | | * txr.1: New section on Treatment of literals.
* compiler: de-dupe strings and bignum literals.Kaz Kylheku2019-01-311-11/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Let's squash duplicate strings and bignum integers in the virtual machine data tables. We can safely do it for these objects. For lists and vectors, things are tricky because these aggregates can contain circularity; so we leave those alone for now. Text processing code can generate a lot of duplicate strings. For instance `@a @b @c` generates three copies of the " " literal. * share/txr/stdlib/compiler.tl (*dedup*): New special variable. This is our de-dupe table, but it is globally nil, so that we don't retain cruft between compile jobs. (dedup): New function. (get-dreg): Map the incoming object through dedup. (dreg-key): New function. This converts a literal object to key for the dreg hash. Objects that can be de-duped represent themselves. Objects that cannot be de-duped are keyed by a gensym. (compiler get-dreg): Use dreg-key to reduce the incoming object to a key, and work with that, with the effect that strings, characters and numbers in the data table get de-duped: multiple occurrences of a character, string or number in the code get the same dreg. (usr:compile-toplevel, usr:with-compilation-unit): Establish a dedup hash for the dynamically enclosed compile job. If one is already established by the surroundign dynamic environment, then use that one, otherwise create a new hash.
* caseql: generate better code.Kaz Kylheku2019-01-301-9/+7
| | | | | | | | | | | * eval.c (me_case): Replace a code generation pattern of the (if (and x y) z) with the equivalent (and x y z). The motivation behind this is that it effectively coaxes a jump-threading optimization out of our simplistic compiler. The failure cases out of a single *and* all jump past the entire code block, whereas with the cascaded if + and we get a double test of the same failed value threading through two branches.
* Version 208.txr-208Kaz Kylheku2019-01-284-4/+28
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* @(next): Cover Lisp expressions with :nothrow.Kaz Kylheku2019-01-281-10/+57
| | | | | | | | | | | | | | We would like @(next (open-directory "nonexistent") :nothrow) to act as a failed match, rather than for the exception to propagate (and likely terminate TXR). The problem is that only file sources are treated with :nothrow. * match.c (tleval_nothrow, tleval_144_nothrow): New static functions. (v_next_impl): Use tleval_nothrow for all Lisp evaluation. If nothrow is requested and Lisp evaluation returns the colon symbol (which tleval_nothrow produces in the case of an exception), then treat the situation as a failed match.
* @(next): Diagnose source combined with source-giving option.Kaz Kylheku2019-01-281-3/+3
| | | | | | | | * match.c (v_next_impl): The check against the presence of multiple of source-specifying keyword options must also consider the base source as part of the mutual exclusion, so that syntax like @(next "file" :string "str") is also ruled out.
* @(next): bugfix: nothrow not causing failed match.Kaz Kylheku2019-01-281-6/+14
| | | | | | | | | | * match.c (v_next_impl): Contrary to the documentation and to "classic" TXR behavior exhibited in compatibility mode, when @(next "file" :nothrow) fails to open "file", it treats the situation as a cue to read from standard input, rather than to treat the situation as a failed match. This is because complex_open returns nil, and when that is passed to lazy_stream_cons, that function defaults to standard input.
* command line: support -f in Hash Bang Null Hack.Kaz Kylheku2019-01-282-3/+63
| | | | | | | | | | | | * txr.c (txr_main): In processing the -f option, if there is already an input source, but its name exactly matches the argument of the -f option, then ignore the -f and its option intead of terminating with a diagnostic. This allows the user to use -f in the Null Hack to achieve the usual trick of allowing the script to take options passed through to the interpreter. * txr.1: Documented.
* command line: improve -c option diagnostic.Kaz Kylheku2019-01-281-2/+2
| | | | | | | * txr.c (txr_main): Fix misleading message formatting here. The spec_file string is irrelevant; we must show the argument to -c which is in arg. The name of the input source is spec_file_str; let's show that.
* command line: better diagnosis for --args and --eargsKaz Kylheku2019-01-281-3/+15
| | | | | | | | | * txr.c (txr_main): Diagnose accurately when --args or --eargs is specified without any of the required trailing syntax, instead of complaining about --args or --eargs being an unknown option. Also, fix the error message about --eargs not having an argument, such that it doesn't insinuate that there exists an --eargs=value syntax.
* copy-hash: showstopper: seed must be copied.Kaz Kylheku2019-01-281-0/+1
| | | | | | * hash.c (copy_hash): Fix failure to initialize seed member in the duplicated hash structure. This regression was introduced along with seeded hashing.
* Version 207.txr-207Kaz Kylheku2019-01-264-5/+23
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* configure: problems with 128 bit integer detection.Kaz Kylheku2019-01-262-12/+13
| | | | | | | | | | | * configure: we can't assume that we can just edit "int" to "uint" in forming the superulong_t type. Let's consolidate the detection of the signed and unsigned superlong. Only if both are available, then emit material into config.h, along with a single constant: HAVE_SUPERLONG_T. * mpi/mpi-types.h: Don't refer to removed HAVE_USUPERLONG_T. Change superulong_t to usuperlong_t.
* disassemble: tidier data table.Kaz Kylheku2019-01-261-1/+1
| | | | | | * share/txr/stdlib/asm.tl (dissassemble-cdf): Print the rows of the data table with simple numeric offsets, with no d prefix or leading zeros.
* streams: use Boolean return value for stdio_fseek.Kaz Kylheku2019-01-253-6/+5
| | | | | | | | | | | | | | * stream.c (stdio_seek): Handle new-style Boolean return from stdio_fseek. * sysif.c (stdio_fseek): Return an int indication that is 1 for success, 0 for failure. There was a mistaken assumption here that fseeko returns the file offset, and the return value in the fseek case was mistakenly harmonized, using a wasteful call to stdio_ftell. The only call to this function relies only on a Boolean success/fail indication. * sysif.h (stdio_fseek): Declaration updated.
* install: broken when using separate build dir.Kaz Kylheku2019-01-251-2/+1
| | | | | | | | * Makefile (install): Drop the $(top_srcdir) prefix from share/txr/stdlib materials. This fails for the .tlo files which are only found in the build directory, not the source directory. The .txr and .tl files are found in both, thanks to symlinks; for those it works either way.
* mul: add forgotten MPI error check.Kaz Kylheku2019-01-251-1/+4
| | | | | | * arith.c (mul): In code that is only compiled when HAVE_DOUBLE_INTPTR_T is missing/zero, we need to test the return value of MPI's mp_mul.
* sysif: take advantage of i64_t in off_t handling.Kaz Kylheku2019-01-251-10/+4
| | | | | | * sysif.c (num_off_t): Remove #ifdef here and just use num_64 if off_t fits into 64 bits. Now this code compiles even if HAVE_DOUBLE_INTPTR_T is missing.
* ffi: use enhanced 64 bit support in itypes.c.Kaz Kylheku2019-01-251-155/+24
| | | | | | | | | * ffi.c (ffi_be_i64_put, ffi_be_i64_get, ffi_be_u64_put, ffi_be_u64_get, ffe_le_i64_put, ffi_le_i64_get, ffi_le_u64_put, ffi_le_u64_get): Functions simplified by using u64_t and i64_t types and functions from itypes.c. Conditional compilation and range tests are no longer required.
* itypes: take advantage of double_intptr_t.Kaz Kylheku2019-01-252-1/+54
| | | | | | | | | | | | | | | | | If double_intptr_t is at least 64 bits wide (which is always going to be true) we can take advantage of it. * itypes.c (c_i64, c_u64): Provide implementations that use the new dbl_intptr_t and dbl_uintptr_t infrastructure. The fallback implementation that uses ash and logior is basically not used now. (num_64, unum_64): New functions for obtaining a Lisp value from a 64 bit number, abstracting whether this is done via the cnum or dbl_cnum route. * itypes.h (u64_t, i64_t): Define in terms of double_uintptr_t and double_intptr_t, if no other 64 bit type is available. (num_64, unum_64): Declared.
* Extend infrastructure for double_intptr_t.Kaz Kylheku2019-01-256-1/+151
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We support an unsigned version of the type, and add functions for converting between Lisp values and both types. * arith.c (bignum_dbl_uipt): New function, unsigned companion to existing bignum_dbl_ipt. (c_dbl_num, c_dbl_unum): New functions. * arith.h (bignum_dbl_uipt, c_dbl_num, c_dbl_unum): Declared. * configure (superulong_t, SIZEOF_DOUBLE_INTPTR, DOUBLE_INTPTR_MAX, DOUBLE_INTPTR_MIN, DOUBLE_UINTPTR_MAX, double_uintptr_t): New definitions going into config.h. * lib.h (dbl_cnum, dbl_ucnum): New typedefs: double-sized analogs of cnum and ucnum. * mpi/mpi.c (mp_set_double_uintptr, mp_get_double_uintptr, mp_get_double_intptr): New functions. (s_mp_in_big_range): New static function. (mp_in_double_intptr_range, mp_in_double_uintptr_range): New functions. * mpi/mpi.h (mp_set_double_uintptr, mp_get_double_intptr, mp_get_double_uintptr, mp_in_double_intptr_range, mp_in_double_uintptr_range): Declared.
* Provide faster bignum-in-fixed-integer range tests in MPI.Kaz Kylheku2019-01-254-40/+37
| | | | | | | | | | | | | | | | | | | | | | | * mpi/mpi.c (mp_in_range, mp_in_intptr_range, mp_in_uintptr_range): New functions. * mpi/mpi.h (mp_in_range, mp_in_intptr_range, mp_in_uintptr_range): Declared. * arith.c (NUM_MAX_MP, INT_PTR_MAX_MP, UINT_PTR_MAX_MP, INT_PTR_MAX_SUCC_MP): Static variables removed. Note that INT_PTR_MAX_MP was not used at all! (normalize): Use mp_in_range instead magnitude comparison to NUM_MAX_MP. (in_int_ptr_range, in_uint_ptr_range): Static functions removed. (c_unum): Use mp_in_uintptr_range instead of in_uint_ptr_range. (arith_init): Remove initializations of removed variables. (arith_free_all): Remove cleanup of removed variables, leaving function empty. * lib.c (c_num): Use mp_in_intptr_range instead of in_int_ptr_range.
* lib: revise wording of integer range errors.Kaz Kylheku2019-01-242-8/+10
| | | | | | | | * arith.c (c_unum): Fix misleading error message, and instead specify the range that was violated. * lib.c (c_num): Similar change: don't refer to a 'cnum range' which means nothing to the user.
* ffi: fix range checks in be/le i64 put ops.Kaz Kylheku2019-01-241-4/+4
| | | | | | | | | * ffi.c (ffi_be_i64_put, ffi_le_i64_put): Fix incorrect range check, causing most negative two values to be rejected. The aim here is to accept the #x-80..00 most negative two's complement value. We can't express that directly using the C expression -0x8000000000000000 because it's not a simple constant; it's the unary minus applied an unsigned number.
* ffi: incorrect big endian int64 get.Kaz Kylheku2019-01-241-2/+2
| | | | | * ffi.c (ffi_le_i64_get): Fix wrong array indices, causing lower half of 64 bit word to be taken as the upper half.
* ffi: almost bug: 64 bit signed big/little endian type.Kaz Kylheku2019-01-231-4/+4
| | | | | | | | | | | | | | * ffi.c (ffi_be_i64_get, ffi_le_i64_get): The code here for 32 bit platforms is fishy: it is using the signed cnum type for the low 32 bits, when that should be ucnum. We are actually okay because ths code would only be executed on a platform where cnum is 32 bits. We are saved by the fact that we are doing left shifts (no sign extension), that shifting a 1 into a sign bit is harmless on two's complement machines, and that the lo32 value is ultimately passed to unum whereby it is coerced to a ucnum argument type (which preserves the bit representation) and prevents logior from seeing a negative value.
* Fix some instances of 4 bytes = 32 bits assumption.Kaz Kylheku2019-01-237-42/+48
| | | | | | | | | | | | | | | | | * hash.c (equal_hash, eql_hash, cobj_eq_hash_op, hash_hash_op): Multiply object size by CHAR_BIT and switch on number of bits, rather than bytes. * sysif.c (off_t_num): Likewise. * arith.c, ffi.c, itypes.c, rand.c: In numerous #if directive, fix size tests from bytes to bits. * configure: in the test that detects integer types, and in the test for enabling large file offsets, detect one more variable from the system: the value of CHAR_BIT. This turns into SIZEOF_BYTE. We use that value instead of a hard-coded 8.
* sysif: use double-intptr function from arith.Kaz Kylheku2019-01-233-5/+6
| | | | | | | | | | | * arith.c (bignum_dbl_ipt): Change internal function to external linkage. * arith.h (bignum_dbl_ipt): Conditionally declared. * sysif.c (num_off_t): Use bignum_dbl_ipt instead of open-coding exactly the same thing that bignum_dbl_ipt does. Abort is changed to same internal_error as in off_t_num.
* sysif: remove low-level MPI code for off_t conversion.Kaz Kylheku2019-01-232-50/+12
| | | | | | | | | | | * sysif.c (off_t_num): Retarget to just use c_i32 or c_i64 from ctypes.c, depending on which of these types is the same width as off_t. (stdio_fseek): Pass identifying "self" string to off_t_num. Don't use off_t_num for fseek's offset argument which is of type long; for that we can use c_long from ctypes.c. * sysif.h (off_t_num): Declaration updated.
* mpi: put access macros into mp_ namespaceKaz Kylheku2019-01-225-26/+34
| | | | | | | | | | | | | | | | | | * mpi/mpi.h (mp_sign, mp_isneg, mp_used, mp_alloc, mp_digits, mp_digit): New macros, based on renaming SIGN, ISNEG, USED, ALLOC, DIGITS and DIGIT. (mp_set_prec): Use mp_digits instead of DIGITS. * mpi/mpi.c (SIGN, ISNEG, USED, ALLOC, DIGITS, DIGIT): Macros defined here now, as local aliases for their namespaced counterparts. * arith.c (signum, floordiv): Replace ISNEG with mp_isneg. * rand.c (random): Replace ISNEG with mp_isneg. * sysif.c (off_t_num): Replace USED, DIGITS and ISNEG with mp_used, mp_digits and mp_isneg.
* doc: review of Lisp CompilationKaz Kylheku2019-01-201-3/+14
| | | | | | | | * txr.1: eval mistakenly referred to instead of compile-file under Compile File. Spurious pluralization of literals fixed. New "Bound symbols in dwim" heading to separate text from discussion of unbound symbols in dwim. Clarifying text added about compile-toplevel's treatment of form.
* Version 206.txr-206Kaz Kylheku2019-01-186-186/+206
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* mpi: some params should be mp_size, not mp_digit.Kaz Kylheku2019-01-182-9/+9
| | | | | | | | | * mpi/mpi.c (s_mp_2expt, mp_trunc_comp, mp_trunc, mp_bit): Arguments that give a number of bits or bit position should be mp_size; they are not related to digit values. * mpi/mpi.h (mp_trunc_comp, mp_trunc, mp_bit): Declaration updated.
* mpi: remove unused mplogic module.Kaz Kylheku2019-01-181-1/+1
| | | | * Makefile (MPI_OBJ_BASE): remove mplogic.o.