summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* ffi: remove useless locals from enum constructor.Kaz Kylheku2021-10-091-8/+1
| | | | | * ffi.c (make_ffi_type_enum): the variables lowest, highest and count do not serve any purpose; they are hereby removed.
* ffi: insufficient format args in enum error handling.Kaz Kylheku2021-10-091-2/+2
| | | | | * ffi.c (make_ffi_type_enum): Add missing argument to two uw_throwf calls. Reported by Paul A. Patience.
* ffi: C++ upkeep.Kaz Kylheku2021-10-081-3/+3
| | | | | | * ffi.c (sock_opt, sock_set_opt): Fix a few integer conversions to use convert (mapping to static_cast) rather than coerce (reinterpret_cast).
* Version 271.txr-271Kaz Kylheku2021-10-057-1351/+1435
| | | | | | | | | | | | | | * 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.
* unix: fix sock-opt test case.Kaz Kylheku2021-10-051-2/+2
| | | | | | | | | | | | | | | On systems with true Unix heritage, like Solaris, MacOS/Darwin, and undoubtedly various BSDs, getsockopt is returning a bitmask value for some options , rather than 1. For instance if we enable SO_REUSEADDR, and then read back the value of the option, we get 4 and not 1. This is because the value of the SO_REUSEADDR symbol itself is 4; it is a mask. The kernel code is evidently just masking out the desired option out of the option mask, and returning the mask value without reducing it to 0 or 1. * tests/014/socket-misc.tl: Test the result of sock-opt for nonzero using nzerop rather than testing specifically for 1.
* cygwin: environment-related fixes.Kaz Kylheku2021-10-052-15/+16
| | | | | | | * stream.c (run): replace_env takes only one argument. * tests/018/process.tl: *child-env* tests are reporting some extra environment variables on Windows; let's just disable them.
* awk: :fields specifies conversions.Kaz Kylheku2021-10-044-74/+185
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * stdlib/awk.tl (sys:awk-compile-time): Slot field-names renamed to field-name-conv. (sys:awk-expander): Parse the new syntax which allows (sym fn) pairs with optional fn, creating a list of normalized items in the field-name-conv slot of the compile-time structure. (sys:awk-symac-let): Adjust the code to the pair representation in field-name-conv. (sys:awk-field-name-code): New function for generating the field conversion code. (awk): Now that we have two optional pieces of code to wrap around p-actions form, we factor that out of the awk-lambda, to a series of conditional assignments. Here we handle the generation of the field conversionns. * conv.tl (sys:conv-expand-sym): New macro, used in sys:awk-field-name-code and sys:conv-let. (sys:conv-let): Simplify with sys:conv-expand-sym. Drop optional argument from i; it connects with no documented feature, and is not usable from fconv. * tests/015/awk-fields.tl: New tests. * txr.1: Updated, including cruft in fconv documentation. Change-Id: Ie42819f58af039fdbcdb1ae365c89dc1add55c93
* doc: fix trivial typos and stylistic issues.Paul A. Patience2021-10-041-73/+71
| | | | * txr.1: Fix typos and stylistic issues.
* doc: fix refs to inexistent fill- and put-array.Paul A. Patience2021-10-041-8/+8
| | | | | | | * txr.1: fill-array -> fill-carray, put-array -> put-carray. Refer to fill-buf and put-buf with .code (or .codn). Use .code when referring to a carray object rather than an argument called carray.
* exceptions: fix leftover uw_throwfs with errno.Paul A. Patience2021-10-042-6/+6
| | | | | | * ffi.c (mmap_wrap, mmap_op): Switch to uw_ethrowf. * sysif.c (getresgid_wrap): Same.
* ffi: add cptr-carray function.Paul A. Patience2021-10-024-0/+47
| | | | | | | | | | | * ffi.c (cptr_carray): New function. (ffi_init): Register cptr-carray intrinsic. * ffi.h (cptr_carray): Declared. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* awk: new :fields feature for named fields.Kaz Kylheku2021-10-013-30/+100
| | | | | | | | | | | | | * stdlib/awk.tl (sys:awk-compile-time): New slot, field-names. (sys:awk-expander): Validate and store field-names into compile-time structure. (sys:awk-symac-let): New macro. (awk): Wrap sys:awk-symac-let around code to generate field name macros. * tests/015/awk-fields.tl: New file. * txr.1: Documented.
* compiler: peephole: recalc and rescan in a few more cases.Kaz Kylheku2021-09-301-0/+9
| | | | | | * stdlib/optimize.tl (basic-block peephole-block): In a few more cases, we should be setting the recalc flag to recalculate liveness, and adding some block to the rescan list.
* compiler: fix up linkage and recalc liveness in one peephole case.Kaz Kylheku2021-09-301-8/+11
| | | | | | | | * stdlib/optimize.tl (basic-blocks peephole-block): Rearrange the code a bit so we don't calculate the xbl, which potentially performs the cut-block, if there is no ybl. We set the bb.recalc flag since we may have cut a block into two and have redirected a jump, and also update the links for that reason.
* compiler: eliminate some redundant hash lookups.Kaz Kylheku2021-09-301-11/+12
| | | | | | | * stdlib/optimize.tl (basic-blocks thread-jumps-block, basic-blocks peephole-block): Streamline various cases of [bb.hash jlabel] being wastefully called twice to look up the same block referenced by the same label.
* compiler: eliminate basic-block next-block method.Kaz Kylheku2021-09-301-23/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The next-block method performs a linear search through the basic block list, which is physically ordered, to find the physically next block. This is actually not needed in several places that use the method; they want the logically next block, which is nil if the last instruction of the current doesn't potentially fall through to the next block. In the one place where we need the physical next block, in the elim-next-jump method, the caller can dynamically provide this, since it walks the list. * stdlib/optimize.tl (basic-block next-block): Method removed. (basic-block link-graph): We revise the logic here a little bit. All of the cases now consistently use the mechanism of setting link-next to nil to indicate that they don't fall through to the next block. The special case handling of the close instruction is clearer. (basic-block (thread-jumps-block, peephole-block)): Several cases here referred to the physically next block via the next-block method. This can be replaced by just using the next pointer, which will be the same. (basic-blocks elim-next-jump): This method now takes the next block as an argument, since there is no next-block method it can call to get the physcally next block. The argument is guaranteed non-null, so we don't need the .? null-safe slot access syntax. (basic-blocks elim-dead-code): Iterate over the next blocks simultaneously, and pass the next block into elim-next-jump. We no longer iterate over the last block, which has no physical next block.
* compiler: cosmetic: merge set assignments.Kaz Kylheku2021-09-301-7/+7
| | | | | | * stdlib/optimize.tl (basic-blocks join-block): Merge set forms into one. (basic-blocks elim-dead-code): Likewise.
* compiler: improvement in next-block linking.Kaz Kylheku2021-09-291-3/+3
| | | | | | | * stdlib/optimize.tl (basic-blocks link-graph): Do not search the entire list for a block's successor. Iterate over the cdr of the list in parallel, so that the next block is directly available at each iteration.
* compiler: remove impossible cases in jump threading.Kaz Kylheku2021-09-291-8/+4
| | | | | | | | | | | | | | * stdlib/optimize.tl (basic-blocks thread-jumps-block): There can't be any instructions in a basic block after an if or ifq, so in these cases, jrest is always nil. Let's ignore that nil efficiently with @nil, and get rid of the cut-block branches of the code. There is a similar case in peephole-block, but the target of the jump is an (end ...) which doesn't necessarily end a basic block. I temporarily put in an (assert (null jrest)), and, surprisingly, it never went off during a rebuild of the library or running of the test case. Still, only a jend ends a basic block; it would not be correct to simplify it like these two cases in thread-jumps-block.
* compiler: peephole: merge basic blocks when jmp removed.Kaz Kylheku2021-09-291-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | When a jmp instruction is removed from (necessarily) the end of a basic block, that basic block can be merged with the next one, and marked for re-scanning. A test case where this eliminates wasteful register-register move instruction is (match #(@a) #(3) a). * stdlib/optimize.tl (basic-blocks): New slot, tryjoin. (basic-blocks join-block): Null out the instruction list of the joined block. This helps if we do this during peephole processing, because it happens in the middle of an iteration over a list of blocks which can still visit the next block that has been merged into its predecesor; we don't want to be processing instructions that are no longer relevant. (basic-blocks peephole-block): In the one case where a conditional instruction is deleted from the end of the basic block, we add the block to the rescan list, and also to the tryjoin list. If the block can be merged with the next one, that can create more opportunities for peephole optimization. (basic-blocks peephole): Use zap in a few places to condense the logic of sampling a state variable that needs to be nulled out. Add the processing of the tryjoin list: pop basic blocks from the list, and try to merge them with their successor, if possible. We handle cases here where the next block could itself be in tryjoin. Also, if we join any blocks, we set the recalc flag to recalculate the liveness info.
* 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)).
* quantile: fix test needing nonportable amount of precision.Kaz Kylheku2021-09-272-11/+14
| | | | | | | | | | | | | | * tests/common.tl (sstest): New macro. Like stest, but the right hand side is an object which the macro turns to a string, rather than expecting a string. * tests/016/arith.tl: Use the sstest macro for the main quantile test to compare the result and expected value as character strings rather than objects. Specify the expected values using no more than 14 decimal digits of precision, and over the scope of the test case, restrict floating-point printing to 14 digits. Thus, we effectively have quick and dirty epsilon comparison to 14 digits that recurses over the list, without having to write that as a function.
* quips: one in French.Kaz Kylheku2021-09-261-0/+1
| | | | * quips.tl: New quip.
* New variable: *child-env*.Kaz Kylheku2021-09-266-5/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-256-0/+98
| | | | | | | | | | | | | | | | | | | 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-252-28/+33
| | | | | | | | | | | | | | | | | 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.
* quantile: fix failing test.Kaz Kylheku2021-09-251-1/+1
| | | | | * arith.tl: Somehow I committed some wrong expected numbers in a quantile test, yet didn't catch the test failure.
* path-search: rewrite in C with saner semantics.Kaz Kylheku2021-09-256-69/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-236-1/+290
| | | | | | | | | | | | | | | | | | | | | | | | | * 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-228-1/+452
| | | | | | | | | | | | | | | | | | | * 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.
* doc: sock-opt: found proper way to escape ...Kaz Kylheku2021-09-221-2/+2
| | | | | | | * txr.1: To begin a troff line with a period that is to be treated as literal, we use \& before that dot, not simply \. This was giving warnings and not rendering properly. The \& produces good output in man, HTML and PDF.
* doc: fix problem in errno retrieval example.Kaz Kylheku2021-09-221-2/+0
| | | | * txr.1: Remove stray comment from string-get-code example.
* vm, structs: use FLEX_ARRAY macro.Kaz Kylheku2021-09-192-2/+2
| | | | | | | | * vm.c (struct vm_closure): Use the FLEX_ARRAY macro to define the trailing array at the end of the structure instead of hard-coding [1]. * struct.c (struct struct_inst): Likewise.
* vm: fix self name of vm-desc-nlevels.Paul A. Patience2021-09-171-1/+1
| | | | * vm.c (vm_desc_nlevels): vm_desc_nlevels -> vm-desc-nlevels.
* lib: fix self name of cmp-str.Paul A. Patience2021-09-171-3/+3
| | | | * lib.c (cmp_str): Fix self name and use it in uw_throwf call.
* eval: fix single-list-argument case in maprodo.Paul A. Patience2021-09-171-1/+1
| | | | | | | Calling maprodo with one list argument would fall back on mappend rather than mapdo. * eval.c (maprodo): mappendv -> mapdov.
* doc: interchange buf-str and str-buf descriptions.Paul A. Patience2021-09-171-15/+15
| | | | | * txr.1: Interchange the first arguments of buf-str and str-buf, and their descriptions also.
* doc: fix various trivial typos.Paul A. Patience2021-09-171-7/+7
| | | | | | * txr.1: Fix typos in .meIP and .mets lines. Fix a .code that should be .codn. Add missing closing parenthesis in description of greater function. Unparenthesize make-random-state in a .code.
* 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-147-24/+76
| | | | | | | | | | | | | | | | | | | | * 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.
* seq_iter: gc crash marking vector iterator.Kaz Kylheku2021-09-131-4/+4
| | | | | | | | | * lib.c (si_vec_ops): This must be initialized with seq_iter_ops_init_nomark, since it uses a cnum index, and not a val iter; the seq_iter_mark_op will pass the cnum bit pattern to gc_mark an cause a crash. (si_null_ops): While we are at it, this should also use seq_iter_ops_init_nomark, because it->ui.iter is always nil.
* hash: gc problem in copy-hash.Kaz Kylheku2021-09-131-1/+1
| | | | | | | | | * hash.c (copy_hash): The order of allocating the hash object and vector is incorrect. The hash must be allocated last, like it is in do_make_hash and make_similar_hash. If the vector is allocated after the hash, it can trigger gc, and then the garbage collector will traverse the uninitialized parts of the hash object.
* ffi, sockets: add sock-opt and sock-set-opt.Paul A. Patience2021-09-126-5/+329
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: add test for recent sock-peer place issue.Kaz Kylheku2021-09-111-1/+5
| | | | | * tests/014/socket-misc.tl: Test that we can perform a place update operation on a (sock-peer s) place.
* sockets: bug in clearing SOCK_* type flags.Kaz Kylheku2021-09-112-6/+9
| | | | | | | | | | | | | | | | | | | | Paul A. Patience reports a regression in 3d5d525eb525cfad8f643917c31e3d9fedce2874, whereby the code marked with #if SOCK_NONBLOCK || SOCK_CLOEXEC is being excluded by the preprocoessor, and so those flags are not being cleared from the socket type that we retain. This is because these preprocessor symbols are not necessarily integer constants. They may expand to C enum identifiers, in which case, in preprocessor expressions they appear to take on the value zero. * socket.c (open_socket, socketpair_wrap): Use the if statement to test for SOCK_NONBLOCK or SOCK_CLOEXEC being nonzero, rather than a preprocessor #if. This should still be optimized away as unreachable code if they are zero. * tests/014/socket-misc.tl: New file.
* sockets: remove excess apostrophe in sock-peer.Paul A. Patience2021-09-111-1/+1
| | | | | * stdlib/socket.tl (sock-peer): Remove excess apostrophe in getter.
* doc: fix various important typos.Paul A. Patience2021-09-111-10/+10
| | | | | | | | | * txr.1: use-symbol -> use-sym; socket-open -> open-socket; af-inet -> af-unix in description of open-socket; r+ -> r+b in description of sock-accept; get-obj -> fill-obj in description of fill-obj; offs -> offset in description of carray-buf; caddr-ref -> carray-ref; caddr-refset -> carray-refset; fix int-carray's argument list.
* sockets: throw exception if socket call fails.Paul A. Patience2021-09-111-0/+5
| | | | | | | | | | The open_socket function was not checking the result of the socket call for failure, which would cause datagram socket streams to be initialized with an invalid file descriptor (-1) and, when opening stream sockets, throw an error not representative of the actual problem. * socket.c (open_socket): Throw exception if socket call fails.
* mmap: fix typo in error message.Paul A. Patience2021-09-111-1/+1
| | | | * ffi.c (mmap_op): mmaped -> mmapped.