summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* save-exe: new function.Kaz Kylheku2019-02-174-80/+86
| | | | | | | | | | | | | | * lisplib.c (save_exe_instantiate, save_exe_set_entries): New static functions. (lisplib_init): Register auto-load of save-exe module, keyed to save-exe symbol. * share/txr/stdlib/save-exe.tl: New file. * txr.1: Removing txr-embedded-arg.txr documentation and documenting save-exe in its place. * txr-embedded-arg.txr: File removed.
* scan-until-match, count-until-match: new functions.Kaz Kylheku2019-02-163-9/+83
| | | | | | | | | | | | | * regex.c (scan_until_common): New static function, made from read_until_match. (read_until_match): Now just wrapper for scan_until_common. (scan_until_match, count_until_match): New functions. (regex_init): Registered new intrinsics scan-until-match and count-until-match. * regex.h (read_until_match, scan_until_match): Declared. * txr.1: Documented.
* fill-buf-adjust: new function.Kaz Kylheku2019-02-163-1/+34
| | | | | | | | | * stream.c (fill_buf_adjust): New function. (stream_init): Register fill-buf-adjust intrinsic. * stream.h (fill_buf_adjust): Declared. * txr.1: Documented.
* buf-alloc-size: new function.Kaz Kylheku2019-02-163-0/+18
| | | | | | | | | * buf.c (buf_alloc_size): New function. (buf_init): buf-alloc-size intrinsic registered. * buf.h (buf_alloc_size): Declared. * txr.1: Documented.
* buf: fix wrong function name string.Kaz Kylheku2019-02-161-1/+1
| | | | * buf.c (length_buf): Replace incorrect name.
* sysrooting: trailing slash needed on directory.Kaz Kylheku2019-02-161-0/+4
| | | | | | | | | * txr.c (sysroot_init): prog_dir is missing a trailing slash, and this breaks the fallback case when we're running a renamed txr executable in the build directory. The presence of the trailing slash had also been documented for the txr-path variable, which is now obsolescent and undocumented. That is hereby fixed.
* txr-exe-path: New variable.Kaz Kylheku2019-02-152-4/+4
| | | | | | | | | * txr.c (sysroot_init): Make prog_path available via the txr-exe-path variable. The txr-path variable becomes obsolescent. * txr.1: Documented txr-exe-path; removed documentation for txr-path.
* linenoise: preserve too-large-to-read file.Kaz Kylheku2019-02-151-2/+11
| | | | | | * linenoise.c (edit_in_editor): If we can't read the file, then preserve the file, and replace the command line buffer with an error message in which the name of that file appears.
* listener: fix buffer overflow reading external file.Kaz Kylheku2019-02-151-6/+1
| | | | | | | | | When an external file is edited, and is longer than the listener's buffer allows, the buffer overflows, trashing the other fields in the linenoise structure, and memory beyond. * parser.c (lino_gets): Decrement nchar in the loop. Also, eliminate useless return case.
* linenoise: bugfix: vertical skip problem.Kaz Kylheku2019-02-141-1/+3
| | | | | | | | | | | | | | | | | | | | | This relates to the optimized insert at the end of the line. The following bug manifests itself. When the cursor is not at the bottom of the screen (e.g. fresh terminal after a clear screen), if blank lines are added to the buffer and then backspace is hit, the cursor strangely jumps down by multiple lines prior to the refresh. In a Windows CMD.EXE window, this shows up even at the bottom of the screen, because the CMD.EXE console responds to a downward movement (ESC[<n>B) beyond the bottom row by scrolling the screen, rather than clipping the movement. * linenoise/linenoise.c (refresh_multiline): When doing the elided refresh (l->need_refresh == 2), we must update not only l->maxrows but also l->oldrow. Otherwise when we do the real update, it will think that the cursor is on the first line, and try to move down to the last line.
* structs: derive type id from pointer.Kaz Kylheku2019-02-151-54/+8
| | | | | | | | | | | | | | | * struct.c (uptopow2_0, uptopow2_1, uptopow2_2, uptopow2_3, uptopow2_4, uptopow2_5, uptopow2): New macros. (struct struct_id_recycle): Declaration removed. (struct_id_counter, struct_id_stack): Static variables removed. (get_struct_id, recycle_struct_id): Static functions removed. (struct_type_finalize): No need to recycle struct ID; don't call removed recycle_struct_id function. (make_struct_type): Don't call removed get_struct_id to allocate ID. Rather, cast the struct_type handle pointer to unsigned integer, and divide by the next smallest power of two.
* structs: fix poorly maintained bitfield size.Kaz Kylheku2019-02-151-1/+1
| | | | | | | | * struct.c (struct struct_inst): When the dirty flag was added, the id field was not decreased by one bit to make space, so the desired packing is not being achieved any more. Let's just use TAG_SHIFT to reserve the maximum bits that will still let us fit a fixnum into id.
* structs: recycle IDs of dead struct types.Kaz Kylheku2019-02-151-7/+71
| | | | | | | | | | | | | * struct.c (nelem): New macro. (struct struct_id_recycle): New struct type. (struct_id_counter): Initialize to 1 instead of zero. (get_struct_id, recycle_struct_id): New static functions. (struct_type_finalize): From each slot symbol, remove the struct type's ID from it slot cache, and finally recycle the struct type ID. (make_struct_type): Use get_struct_id to obtain an ID for the new struct type, rather than directly incrementing the global counter.
* Version 210.txr-210Kaz Kylheku2019-02-146-619/+642
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* linenoise: fix multi-line mode regression.Kaz Kylheku2019-02-141-5/+16
| | | | | | | | | When Enter is input in multi-line mode, a ^M appears instead of advancing to the next line. When the display is refreshed, the ^M's are properly treated as line breaks. * linenoise.c (edit_insert): Let's restructure the conditional ladder here into a switch and handle ENTER by issuing CR-LF.
* Optimize hash operation with unsafe car/cdr.Kaz Kylheku2019-02-147-115/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The associative lists that make up the chains of a hash table are guaranteed to be made of conses. We can use unsafe versions of car, cdr, rplaca and rplacd to speed up hash operations. * eval.c (op_dohash): Use unsafe operations on hash cell. * filter.c (trie_compress, regex_from_trie): Likewise. * hash.c (hash_equal_op, hash_print_op, hash_mark, hash_grow, hash_assoc, hash_assql, copy_hash_chain, gethash, inhash, gethash_n, sethash, remhash, hash_next, maphash, do_weak_tables, group_by, group_reduce, hash_keys_lazy, hash_keys, hash_values_lazy, hash_values, hash_pairs_lazy, hash_pairs, hash_alist_lazy, hash_uni, hash_diff, hash_symdiff, hash_isec, hash_subset, hash_update, hash_update_1, hash_revget): Likewise. * lib.c (us_rplaca, us_rplacd): New functions. (package_local_symbols, package_foreign_symbols, where, populate_obj_hash, obj_hash_merge): Use unsafe operations on hash cell * lib.h (us_rplaca, us_rplacd): Declared. * parser.c (circ_backpatch, get_visible_syms): Use unsafe operations on hash cell. * struct.c (method_name, get_slot_syms): Likewise.
* gethash_c: review uses and improve or replace.Kaz Kylheku2019-02-145-35/+32
| | | | | | | | | | | | | | | | | | | | * eval.c (env_fbind, env_vbind, reg_symacro): Use gethash_l instead of gethash_c to eliminate repeated cdr operations on the same cell. * hash.c (sethash): Since new_p is never used, eliminated it and use nulloc. (group_reduce): Use gethash_l instead of gethash_c. * lib.c (obj_init): Replace rplacd(gethash_c(...)) pattern whose return value is not used with with sethash. We lose some diagnosability here since sethash doesn't take a "self" argument. (obj_print_impl, obj_hash_merge): Use gethash_l instead of gethash_c. * parser.y (ensure_parser, parser_circ_def, get_visible_syms, rlset): Use gethash_l instead of gethash_c.
* gethash_f: removing function.Kaz Kylheku2019-02-143-45/+33
| | | | | | | | | | | | | | | | Uses of gethash_f can be replaced with gethash_e, which returns the hash cell directly rather than through a loc argument. Code that needs the value can call cdr itself. * hash.c (inhash, hash_isec, hash_update_1): Replace gethash_f with gethash_e. (gethash_f): Function removed. * hash.h (gethash_f): Declaration removed. * lib.c (use_sym, unuse_sym, find_symbol, unintern, intern_fallback, in, sel, populate_obj_hash): Replace gethash_f with gethash_e.
* symdiff: new function.Kaz Kylheku2019-02-144-9/+70
| | | | | | | | | | | | * eval.c (eval_init): Register symdiff intrinsic. * lib.c (symdiff): New function. * lib.h (us_car_p, us_cdr_p): New inline functions. (symdiff): Declared. * txr.1: Documented, also fixing issues not related to symdiff doc.
* optimizing diff, isec and uni for non-lists.Kaz Kylheku2019-02-134-41/+109
| | | | | | | | | | | | | | | Also, these functions now support hashes. * eval.c (eval_init): Register only the deprecated set-diff to the set_diff function. The diff intrinsic is now going to the new function named diff. * lib.c (diff): New function. (isec, uni): Rewritten to use seq_iter_t. * lib.h (diff): Declared. * txr.1: Documentation updated.
* num: reduce duplicate code.Kaz Kylheku2019-02-131-3/+1
| | | | | * lib.c (num): Use num_fast instead of an expression that is identical to the body of that inline function.
* Framework for iterating over sequences.Kaz Kylheku2019-02-132-0/+94
| | | | | | | | | | | | | | | | This has been needed for a while. While we have seq_info for classifying sequences to nicely dispatch code into various cases, those cases duplicate code. The code base could benefit from generic traversal. * lib.c (seq_iter_get_nil, seq_iter_get_list, seq_iter_get_vec, set_iter_get_hash): New static functions. (seq_iter_rewind, seq_iter_init): New functions. * lib.h (struct seq_iter, seq_iter_t): New struct type and its typedef name. (seq_iter_init, seq_iter_rewind): Declared. (seq_get): New inline function.
* hash-from-alist: new function.Kaz Kylheku2019-02-133-1/+33
| | | | | | | | | * hash.c (hash_from_alist_v): New function. (hash_init): Register hash-from-alist intrinsic. * hash.h (hash_from_alist_v): Declared. * txr.1: Documented.
* hash-symdiff: new function.Kaz Kylheku2019-02-133-1/+57
| | | | | | | | | * hash.c (hash_symdiff): New function. (hash_init): hash-symdiff intrinsic registered. * hash.h (hash_symdiff): Declared. * txr.1: Documented.
* hash-uni: bugfix.Kaz Kylheku2019-02-131-2/+6
| | | | | | | | * hash.c (hash_uni): The join function must only be called for the values of keys that exist in both hashes. The broken logic here unconditionally calls the join function for all keys in the left hash (using nil as the right join value when the key doesn't exist in the right hash).
* doc: fix reference to nonexistent load-value.Kaz Kylheku2019-02-111-2/+2
| | | | | | * txr.1: In Notes under load-time, the function is once referred to as load-value; also the phrase load-time value is used that can just be load-time.
* Version 209.txr-209Kaz Kylheku2019-02-086-551/+626
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* build: get rid of .tlo2 files.Kaz Kylheku2019-02-081-12/+3
| | | | | | | | | | | | | | | After the defvar bugfix in the previous commit, the only differences between .tlo and .tlo2 files are the names of a few gensyms here and there. In other words, they are identical code; therefore, there is no point in compiling them. * Makefile (STDLIB_TLOS2): Variable removed. (%.tlo2): Implicit rule removed. (stage1 stage2): Phony targets removed. (all): Directly depends on $(STDLIB_TLOS) without stage1 intermediary. (clean-tlo): Don't remove $(STDLIB_TLOS2).
* defvar: spectacular bug causing wrong compile.Kaz Kylheku2019-02-081-2/+6
| | | | | | | | | | | The defvar/defparm macro expander marks symbols special only at macro-expansion time, without actually generating code in the macro expansion to do this. This means that the compiled versions of defvar and defparm forms will code will neglect to create a dynamically scoped variable! * eval.c (me_def_variable): Add code to the output to mark the symbol special, for defvar or defparm.
* 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.