summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* doc: formatting under Special Structure Functions.Kaz Kylheku2019-11-181-2/+2
| | | | | * txr.1: Use .mets instead of .meti on the syntax; this produces an indentation.
* New functions for buf <--> integer conversion.Kaz Kylheku2019-11-182-0/+192
| | | | | | | | | * buf.c (buf_int, buf_uint, int_buf, uint_buf): New static functions. (buf_init): buf-int, buf-uint, int-buf and uint-buf intrinsic functions registered. * txr.1: Documented.
* eval: bugfix: expansion wrongly always in null env.Kaz Kylheku2019-11-181-5/+34
| | | | | | | | | | | | | | | | | | | | | | The eval function uses a null macro environment for expanding a form, even when it's given an environment object. This causes spurious warnings about unbound variables/functions. For instance: (let ((env (make-env '((x . 42)) nil nil))) (eval '(+ x x) env)) ;; warning: unbound variable x To fix this, we have to create a macro version of the incoming environment and expand with that. * eval.c (env_to_menv): Take an evaluation environment chain and convert it to a (flattened) macro environment. (expand_eval): Take a macro environment parameter and use that for expanding the form to be evaluated, rather than nil. (eval_intrinsic): Calculate a macro environment corresponding to the given evaluation environment. Use that for the macroexpand call, and also pass it down to expand_eval to be used for the full expansion.
* gc: bugfix: maintain tail pointer in new sweep code.Kaz Kylheku2019-11-091-3/+2
| | | | | | | | | * gc.c (sweep): The new logic for removing a deleted heap's blocks from the free list must correctly maintain free_tail. Whenever a node is deleted which is the tail node, the tail pointer must move to the parent's tail field, or to the free_list pointer. We don't need to do anything afterward for the free_list == 0 case; that is taken care of.
* gc: recalculate heap bounding box when sweeping.Kaz Kylheku2019-11-081-0/+7
| | | | | | | | | | Since sweep can delete heaps now, it's possible that the bounding box may be tightened. Since we are iterating over all heaps, we can just recalculate it. * gc.c (sweep): Recalculate the heap boundaries using local variables, taking care to exclude any heap that is being deleted. Then update the globals.
* gc: free heaps that become empty.Kaz Kylheku2019-11-081-2/+41
| | | | | | | | | | | | | | | | | On glibc, our heap allocation requests are considered large and handled via mmap; when we free a heap, the memory is returned to the OS via munmap. * gc.c (sweep): If every object in a heap is freed, we free the entire heap, taking care to also reset the free list to the state before those objects were added to it. The free list may still contain objects from that same heap that were not just added to it (they were freed in a previous GC pass), so we must walk the free list to find the remaining objects and remove them. The Valgrind debugging logic (opening access and closing while walking the list) was too cumbersome so it's done in two passes: open access to the whole free list, process it, close off what is left.
* open-process: new variant, open-subprocess.Kaz Kylheku2019-11-072-14/+69
| | | | | | | | | | | | * stream.c (open_subprocess): new function, formed by adding fun argument to open_process. Since the program name can be nil now, in which case argv is not allocated, the code must be careful not to access argv if it is null. (open_process): Reduced to trivial wrapper around open_subprocess. (stream_init): open-subprocess intrinsic registered. * txr.1: Documented.
* open-process: I/O redirection feature.Kaz Kylheku2019-11-063-7/+196
| | | | | | | | | | | | | | | | | In the mode-string of open-process, I/O redirections can now be specified that are carried out in the child process. * stream.c (do_parse_mode): Parse the redirection syntax indicated by >, which has a short and long form. The redirections are entered into a small table in the mode structure. (open_process): In the child process, perform the redirection specified in the mode structure's redirection table. * stream.h (STDIO_MODE_NREDIRS): New preprprocessor symbol. (struct stdio_mode): New array member, redir. * txr.1: Documented.
* open-process: close-on-exec bugfix.Kaz Kylheku2019-11-061-2/+2
| | | | | | | | | | | | | This is a regression introduce in the 2019-06-09 commit 4f33b169dc547b7f9af6f2f1c173d36fc4d62fe8 "Adding fcntl interface." which changed HAVE_FCNTL_H to HAVE_FCNTL in the configure script, without making the same change in stream.c. * stream.c: Replace HAVE_FCNTL_H with the correct HAVE_FCNTL, so that we're once again actually including the <fcntl.h> header now, and setting the close-on-exec flag on the pipe in open-process.
* compiler: first use of .? notation.Kaz Kylheku2019-11-061-1/+1
| | | | | * share/txr/stdlib/compiler.tl (sys:env postinit): The the initialization of me.lev becomes more succinct.
* syntax: new .? operator for null-safe object access.Kaz Kylheku2019-11-055-58/+204
| | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (obj_print_impl): Render the new syntactic conventions introduced in qref/uref back into the .? syntax. The printers for qref and uref are united into a single implementation to reduce code proliferation. * parser.l (grammar): Produce new tokens OREFDOT and UOREFDOT. * parser.y (OREFDOT, UREFDOT): New terminal symbols. (n_expr): Handle .? syntax via the new OREFDOT and UOREFDOT token via qref_helper and uoref_helper. Logic for the existing referencing dot is moved into the new qref_helper function. (n_dot_expr): Handle .? syntax via uoref_helper. (uoref_helper, qref_helper): New static functions. * share/txr/stdlib/struct.tl (qref): Handle the new case when the expression which gives the object is (t expr). Handle the new case when the first argument after the object has this form, and is followed by more arguments. Both these cases emit the right conditional code. (uref): Handle the leading .? syntax indicated by a leading t by generating a lambda which checks its argument for nil. Transformations to qref handle the other cases. * txr.1: Documentation updated in several places.
* path-tests: bug in path-strictly-private-to-me-p.Kaz Kylheku2019-11-041-1/+1
| | | | | | | | | | * share/txr/stdlib/path-test.tl (path-strictly-private-to-me): Fix mistake in test whether the file is group readable/writable. The wrong flag is used for group readability test, which means that, at that point in the logic, if the file is merely not group writable, we jump to the conclusion that the file is strictly private, when in fact it may be group readable. Reported by user vapnik spaknik.
* path-tests: fix incorrect type tests.Kaz Kylheku2019-11-031-7/+11
| | | | | | | | | | | | | | Reported by user vapnik spaknik, who discovered the path-symlink-p function yielding a false positive on a regular file. The functions in this group are bit testing rather than extracting a bitfield and checking the enumerated value. * share/txr/stdlib/path-test.tl (sys:path-test-type): New function. (path-file-p, path-dir-p, path-symlink-p, path-blkdev-p, path-chrdev-p, path-sock-p, path-pipe-p): Use sys:path-test-type rather than sys:path-test-mode.
* hash: new hash-reset function.Kaz Kylheku2019-11-023-1/+43
| | | | | | | | | * hash.c (hash_reset): New function. (hash_init): hash-reset intrinsic registered. * hash.h (hash_reset): Declared. * txr.1: Documented.
* lib: use stack-allocated hash iterators everywhere.Kaz Kylheku2019-11-016-41/+72
| | | | | | | | | | | | | | | | | * eval.c (op_dohash): Use hash_iter instead of consing up heap-allocated hash iterator. * filter.c (trie_compress, regex_from_trie): Likewise. * hash.c (hash_equal_op, hash_hash_op, hash_print_op): Likewise. * lib.c (package_local_symbols, package_foreign_symbols, find_max, find_if, rfind_if, populate_obj_hash): Likewise. * parser.c (circ_backpatch, get_visible_syms): Likewise. * struct.c (method_name, get_slot_syms): Likewise.
* hash: expose new iterator interface.Kaz Kylheku2019-11-012-11/+15
| | | | | | | | | | * hash.c (struct hash): Declaration removed from here. (hash_iter_init, us_hash_iter_init, hash_iter_next, hash_iter_peek): Functions switched to external linkage. * hash.h (struct hash): Declared here now. (hash_iter_init, us_hash_iter_init, hash_iter_next, hash_iter_peek): Declared.
* hash: improve new hash_iter interface.Kaz Kylheku2019-11-011-16/+22
| | | | | | | | | | | | | | | | | | | | | Most calls to hash_iter_next are passing a null parameter for the object; only hash_next uses that parameter. Let's make hash_iter_next a wrapper which doesn't have that parameter. This interface will soon be exposed to other source files, so it's important to streamline it. * hash.c (hash_iter_next_impl): New function, exact copy of hash_iter_next. (hash_iter_next): Reduced to wrapper for hash_iter_next_impl, with one less argument. (hash_next): Call hash_iter_next_impl instead of hash_iter_next. (maphash, group_by, group_reduce, hash_uni, hash_diff, hash_symdiff, hash_isec, hash_subset, hash_update, hash_revget, hash_invert): Remove null argument from hash_iter_next calls.
* lib: don't assume time_t is signed.Kaz Kylheku2019-10-315-21/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | We introduce the function c_time to convert a Lisp integer to time_t, and num_time to do the reverse conversion. The FFI type time-t already does this right. (See registration of time-t in ffi_init_extra_types). * hash.c (gen_hash_seed): The first value out of time_sec_usec corresponds to a time_t value. We now convert this to C number using c_time rather than c_num. Also, while we are touching this code, the microseconds value can convert directly to ucnum with c_unum. * lib.c (time_sec_usec): Use num_time for seconds. (time_string_local, time_string_utc, time_fields_local, time_fields_utc, time_struct_local, time_struct_utc): Use c_time. (make_time_impl, time_parse_utc): Use num_time instead of num. * signal.h (getitimer_wrap, setitimer_wrap): Convert tv_sec members of struct timeval using c_time and num_time. * sysif.c (c_time, num_time): New functions. (stat_to_struct): Convert st_atime, st_mtime and st_ctime to Lisp using num_time instead of num. * sysif.c (c_time, num_time): Declared.
* expander: bogus undefined warnings from lisp1 values.Kaz Kylheku2019-10-301-8/+5
| | | | | | | | | | | | | Issue: (sys:lisp1-value x) throws a warning even if x is a predefined library function. This is caused by naively using expand to attempt to expand it as a symbol macro. * eval.c (expand_lisp1_value): Use expand_lisp1 instead of expand, just like expand_forms_lisp1. Because I didn't notice this problem when adding those two functions, expand_lisp1 is farther down the file and we need a forward declaration. (expand_lisp1_setq): Likewise, and eliminate the unbound variable check which is done by expand_lisp1.
* hash: stack-allocated iterators.Kaz Kylheku2019-10-291-62/+105
| | | | | | | | | | | | * hash.c (hash_iter_init, us_hash_iter_init, hash_iter_next, hash_iter_peek): New static functions, made from hash_begin, hash_next and hash_peek internals. (hash_begin, hash_next, hash_peek): Turned into wrappers for hash_iter_init, hash_iter_next, hash_iter_peek. (maphash, group_by, group_reduce, hash_uni, hash_diff, hash_symdiff, hash_isec, hash_subset, hash_update, hash_revget, hash_invert): Use stack-allocated struct hash_iter instead of heap allocated object from hash_begin.
* stat: support high resolution time stamps.Kaz Kylheku2019-10-295-7/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | * configure (have_sys_stat): New variable. Set to y when our test detects <sys/stat.h>. New test added for the presence of high resolution time stamps in struct stat. If we have these, we #define HAVE_STAT_NSEC 1 in config.h. * share/txr/stdlib/path-test.tl (path-newer): Compare nanosecond parts of the modification time if the seconds are equal, improving the resolution of the test. * sysif.c (atime_nsec_s, mtime_nsec_s, ctime_nsec_s): New symbol variables. (stat_to_struct): If nanosecond resolution is available, set the new nanosecond slots from the three tv_nsec fields in struct stat. Otherwise, set the new slots to zero. (sysif_init): Initialize the new symbol variables. Add the three new slots to the stat struct. * sysif.c (atime_nsec_s, mtime_nsec_s, ctime_nsec_s): Declared. * txr.1: Documented new atime-nsec, mtime-nsec and ctime-nsec slots of stat structure. Added note to path-newer mentioning high resolution support.
* naming: get the -func out, at least some of it.Kaz Kylheku2019-10-295-40/+40
| | | | | | | | | | | | | | | | | | | | The code base contains a lot of irksome _func which should be _fun, and also the public functions func-get-form and func-get-name are irksomely named. As a first step, we can fix parameters which carry this suffix. * glob.c (global_wrap): errfunc argument renamed to errfun. * glob.h (global_wrap): Likewise. * hash.h (hash_uni, hash_isec): join_func argument renamed to joinfun. * hash.h (hash_uni, hash_isec): Likewise. * txr.1: fixed gen-func typo. Arguments renamed in descriptions of hash-uni, hash-isec, iff, iffi, glob, and ftw.
* expander: allow TTY interrupt.Kaz Kylheku2019-10-281-0/+2
| | | | | * eval.c (expand): Call sig_check_fast so that if the expander gets into some kind of loop, it is interruptible.
* doc: bad expression under hash-list.Kaz Kylheku2019-10-281-1/+1
| | | | | | * txr.1: The example apply call wouldn't work as written because hash is looked up in the variable namespace. We must use DWIM brackets.
* New function: hash-invert.Kaz Kylheku2019-10-283-0/+127
| | | | | | | | | * hash.c (hash_invert): New function. (hash_init): hash-invert intrinsic registered. * hash.c (hash_invert): Declared. * txr.1: Documented.
* New function: identity*Kaz Kylheku2019-10-284-5/+25
| | | | | | | | | | | | | | | An version of identity with lax argument conventions. * eval.c (eval_init): Register identity* intrinsic. * lib.c (identity_star_f): New symbol variable. (identity_star): New function. (obj_init): gc-protect identity_star_f variable, and initialize it. * lib.h (identity_star_f): Declared. * txr.1: Documented.
* doc: bogus paragraph removed under vec-push.Kaz Kylheku2019-10-281-7/+0
| | | | | * txr.1: There is no relationship between vec-push and ref; nonsense paragraph removed.
* Version 227.txr-227Kaz Kylheku2019-10-264-5/+15
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* configure: stray exitKaz Kylheku2019-10-261-3/+0
| | | | | * configure: remove stray exit statement added while debugging memalign test on Solaris.
* Version 226.txr-226Kaz Kylheku2019-10-257-953/+1035
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* configure: memalign fixes.Kaz Kylheku2019-10-252-2/+24
| | | | | | | | | | | | | | | | | | | | | This fixes build problems on Mac OS and Solaris due to the introduction of the use of memalign. * configure: After detecting that __EXTENSIONS__ is required on Solaris and adding that to lang_flags, we must call gen_config_make so that it becomes available to subsequent configure tests. On Solaris, memalign is just in <stdlib.h>, so let's test for that first, then test for a memalign in <malloc.h>, and in that case add HAVE_MALLOC_H into config.h. Also, fixing two bugs here. Firstly, the memalign test used inverted logic, causing HAVE_MEMALIGN to be defined on platforms that don't have it. Secondly, the dummy while loop that is just supposed to be a control structure for forward breaks turned infinite due to a missing break at the bottom. * lib.c: if HAVE_MALLOC_H is defined and nonzero, then include <malloc.h>.
* fixparam: signed/unsigned warning from GNU C++.Kaz Kylheku2019-10-252-2/+2
| | | | | | | * lib.h (FIXPARAM_MAX): Switch constant to signed type. * lib.c (func_vm): Use num instead of unum on FIXPARAM_MAX, since we are making it signed.
* hashing: partially revert 63feff9c.Kaz Kylheku2019-10-251-4/+4
| | | | | | | | | Mixing the hash seed with the hashes for characters, fixnums and pointers by multiplication doesn't make sense. It doesn't perturb the hash sufficiently. * hash.c (equal_hash): Do not multiply the hash by the seed for CHR, NUM, SYM, PKG and ENV.
* genvmop: bugfix: unbound variable.Kaz Kylheku2019-10-251-1/+1
| | | | | | | * genvmop.txr: The supposedly unused %oc-list% symbol macro that was removed from the assembler internals is in fact referenced here, causing a failure. We macro-replace this remaining instance of it by hand.
* parser: use faster, unsafe nreverse.Kaz Kylheku2019-10-253-5/+20
| | | | | | | | | | * lib.c (us_nreverse): New function. * lib.h (us_nreverse): Declared. * parser.y (clauses_opt, n_exprs, r_exprs): Use us_nreverse instead of nreverse to rorder lists built in reverse into final shape.
* circle notation: use faster access in backpatch.Kaz Kylheku2019-10-251-7/+5
| | | | | | * parser.c (circ_backpatch): Since we know that we have a CONS or VEC object, use direct access instead of going through type-safe accessors.
* circle notation: recycle conses in backpatching.Kaz Kylheku2019-10-241-2/+8
| | | | | | * parser.c (circ_backpatch): Recycle the conses belonging to the temporary linked list allocated during hash table and tree backpatching.
* stdlib: remove unneeded macros from compiled image.Kaz Kylheku2019-10-243-40/+44
| | | | | | | | | | | | | | | | | | A few macros in the library are local; they are needed only inside functions in the same module. This means they are not referenced by anything once those functions are compiled; we should not be carrying the compiled versions of these macros into the image. We wrap these macro definitions with eval-only, telling the compiler not to emit their compiled version into the output file. * share/txr/stdlib/asm.tl (with-lev-idx, defopcode, defopcode-derived): Wrap macro with eval-only. * share/txr/stdlib/compiler.tl (compile-in-toplevel): Likewise. * share/txr/stdlib/path-test.tl (sys:path-test): Likewise.
* New macro: ldo.Kaz Kylheku2019-10-233-1/+42
| | | | | | | | | | This is a left-argument-inserting syntactic sugar for do. * lisplib.c (op_set_entries): Add auto-load entry for ldo. * share/txr/stdlib/op.tl (ldo): New macro. * txr.1: Documented.
* op/do: clean up documentation-implementation problem.Kaz Kylheku2019-10-232-65/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was reported by astute user vapnik spaknik that the documentation says thing about the do operator which are not actually true in the implementation. I've decided that one of them should be true, and so both implementation and documentation are changing. The documentation claims that (do set x) will produce a function that can be called with one argument; that argument will be assigned to x. That doesn't work, but this commit will make it work. The documentation has this example transformation: (do + foo) -> (lambda rest (+ foo . rest)) that cannot be made to work because do works with macros and special operators to which arguments can't be dynamically applied. This patch will not make the above work; instead the example is corrected. How do is going to work inow is that (do sym ...) syntax in which no implicit variables appear will be equialent to (do sym ... @1). The generated variadic function has one required argument which is implicitly added to the syntax. Obviously, that only works if that positon of the syntax is an evaluated form or place. Values of the -C option equal to 225 or less will restore the old do behavior. * share/txr/stdlib/op.tl (sys:op-expand): Support the new style of do, subject to backward compatibility. A hack is required here. We cannot discover the @1, @2 .. variables in the syntax until we fully expand it. But that code walk requires the syntax to be valid. For instance if (do set x) is specified, with the expectation that it is equivalent to (do set x @1), we cannot process that by code walking (set x). (set x) is invalid syntax. What we do is to *try* expanding it as (set x). If that doesn't work, we add a dummy gensym to the form to produce (set x #:gNNNN) and try expanding that. In that case, rather than adding @1 to the form, we replace the dummy gensym with @1. The algorithm is careful not to accidentally conceal real syntax errors in the form. If the form without the dummy gensym fails to expand, and the one with the dummy gensym expands fine but contains references to implicit parameters (@1, @2, ... @rest), we expand it again without the gensym and allow the error to propagate. Other aspects of this change are fairly trivial. Because the do logic possibly introduces a @1 that doesn't exist, near the end of this function we have to bind another metas variable which has an up-to-date copy of the gens slot. (op-ignerr): New macro; we can't use ignerr because that will create a bootstrapping cycle; ignerr expands to catch, and the catch macro uses do. Wrapping this in eval-only, since we don't need an op-ignerr macro in the compiled image. * txr.1: Documentation revised and updated. Differences between do and op put clarified and put into point form. Bad do examples corrected. Syntax of do now shown as having a required parameter that is an operator. Compat notes added.
* mpi: memory leak in mp_bit.Kaz Kylheku2019-10-221-1/+6
| | | | | | * mpi.c (mp_bit): If the argument is negative, and we have produced a temporary mp_int, we must clear it before returning.
* circle notation: some backpatching optimizations.Kaz Kylheku2019-10-211-6/+13
| | | | | | | * parser.c (circ_backpatch): For hashes and trees, if the count has not changed while traversing the elements, then it means nothing was backpatched: there is no need to do the extra expensive step of rebuilding the hash or tree.
* hash: observe count in eql-based hash.Kaz Kylheku2019-10-211-0/+3
| | | | * hash.c (eql_hash): Decrement count and bail if zero.
* hash: rename hash_rec_limit.Kaz Kylheku2019-10-181-10/+10
| | | | | | | | | | | | | | hash_rec_limit isn't a limit on recursion depth but on the elements traversed. * hash.c (hash_rec_limit): Variable renamed to hash_traversal_limit. (gethash_c, gethash_e, remhash, hash_equal): Use new name. (set_hash_rec_limit): Function renamed to set_hash_traversal_limit. (hash_init): set-hash-rec-limit intrinsic renamed to set-hash-traversal-limit. This function is undocumented, so no backward compatibility is provided.
* hash: get rid of hash_str_limit.Kaz Kylheku2019-10-181-18/+13
| | | | | | | | | | | | | | hash.c (hash_str_limit): Variable removed. (hash_c_str): Take count parameter. Observe the limit and update it. The count is scaled by 4 for strings: four characters for one count. (hash_buf): Likewise. (equal_hash): Pass count to hash_c_str and hash_buf. Use the count to determine how far to force a lazy string for hashing. (set_hash_str_limit): Static function removed. (hash_init): Removed sys:set-hash-str-limit intrinsic. This was used in genman.txr once, but that use was removed a year and a half ago.
* hash: observe count limit for vectors and hash tables.Kaz Kylheku2019-10-181-1/+3
| | | | | | * hash.c (equal_hash): Break out of hashing a vector when the count is exceeded. (hash_hash_op): Likewise for traversing a hash table.
* functions: provide accessors for basic properties.Kaz Kylheku2019-10-184-0/+124
| | | | | | | | | | | | | | * eval.c (eval_init): Register intrinsic functions fun-fixparam-count, fun-optparam-count, fun-variadic. * lib.c (get_param_counts): New static function. (fun_fixparam_count, fun_optparam_count, fun_variadic): New functions. * lib.h (fun_fixparam_count, fun_optparam_count, fun_variadic): Declared. * txr.1: Documented.
* doc: bitfield allocation rules: endiannness.Kaz Kylheku2019-10-171-4/+27
| | | | | * txr.1: Add discussion about endinanness to Bitfield Allocation Rules for completeness.
* compiler: warn on too many lambda args.Kaz Kylheku2019-10-172-0/+4
| | | | | | | | | * share/txr/stdlib/vm-param.tl (%max-lambda-fixed-args%): New symbol macro. * share/txr/stdlib/compiler.tl (compiler comp-lambda): If the nubmer of fixed parameters exceeds %max-lambda-fixed-args%, then issue a warning.
* vm: prevent overflow of fixparam field in function.Kaz Kylheku2019-10-172-11/+22
| | | | | | | | | | | | | Functions can only have 127 fixed parameters; some code ignores this when assigning to the bitfield. * lib.h (FIXPARAM_BITS, FIXPARAM_MAX): New preprocessor symbols. (struct func): Use FIXPARAM_BITS for defining fixparam and optargs bitfields instead of hard-coded 7. * lib.c (func_vm): Sanity check the fixparam and reqags parameters: 0 <= reqargs <= fixparam <= FIXPARAM_MAX.