summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* New sequence classification system.Kaz Kylheku2017-06-162-0/+73
| | | | | | | | | | | | This will help simplify writing generic sequence code, while allowing lists and vectors to be handled specially. * lib.h (enum seq_kind, seq_kind_t): New enum and typedef. (struct seq_info, seq_info_t): New struct and typedef. (seq_kind_tab, seq_info): Declared. * lib.c (seq_kind_tab): New global array. (seq_info): New function.
* New length method on structures.Kaz Kylheku2017-06-162-6/+65
| | | | | | | | | | | | | | | | With this change, nreverse is possible on a struct, if it has lambda, lambda-set and length methods. * lib.c (length_s): New symbol variable. (length): Check for length method and call it, in preference to checking for car method and falling back on cdr-based length. (empty): If object has a length method, call it and compare result to zero. (obj_init): Initialize length_s. * txr.1: Documented. We now have the concepts of structs being vector-like sequences or list-like sequences.
* Support ref, refset on structs via lambda, lambda-set.Kaz Kylheku2017-06-163-1/+30
| | | | | | | | | | | * lib.c (ref, refset): Check for lambda and lambda-set, respectively, and use it. * txr.1: Documented. * tests/012/aseq.tl (add lambda): Fix previously unused broken method which now causes test to go into infinite recursion.
* reverse, nreverse: do generalized sequences and carray.Kaz Kylheku2017-06-151-2/+10
| | | | | | | | * lib.c (reverse): Support COBJ via list operations, but handle carray via vector case. (nreverse): Support COBJ via vector case. This will work for carray. Fixes are needed in ref and refset to work with structs.
* ffi: copy-carray, hooked into copy.Kaz Kylheku2017-06-154-0/+37
| | | | | | | | | | | | * ffi.c (copy_carray): New function (ffi_init): Register copy-carray intrinsic. * ffi.h (copy_carray): Declared. * lib.c (copy): Call copy_array for carray objects. * txr.1: Documented copy-carray and updated copy description.
* ffi: new put-carray and fill-carray functions.Kaz Kylheku2017-06-153-0/+67
| | | | | | | | | | * ffi.c (put_carray, fill_carray): New functions. (ffi_init): put-carray and fill-carray intrinsics registered. * ffi.h (put_carray, fill_carray): Declared. * txr.1: Documented.
* ffi: new integer-carray conversion functions.Kaz Kylheku2017-06-143-0/+211
| | | | | | | | | | | | * ffi.c (carray_unum, carray_num, unum_carray, num_carray): New functions. (ffi_init): New intrinsics registered: carray-unum, carray-num, unum-carray, num-carray. * ffi.h (carray_unum, carray_num, unum_carray, num_carray): Declared. * txr.1: Documented.
* bugfix: sign-extend broken for bignums.Kaz Kylheku2017-06-141-0/+1
| | | | | | | | | | | | | * arith.c (sign_extend): After taking the two's complement which works at the granularity of digits, not the exact number of bits, we must truncate the number to the exact number of bits before negating. Otherwise we end up with an excessively large value. For instance if a bignum like #x80... is sign extended tightly to the upper 1 bit, the resulting value is something like #-xFFFF80..., rather than #x-80... as it should be. There are extra 1 bits padding up to the bignum digit. These must be chopped away.
* Big MPI whitepace and comment cleanup.Kaz Kylheku2017-06-147-2413/+1445
| | | | | | | | * mpi/logtab.h, mpi/mpi-config.h mpi/mpi-types.h mpi/mpi.c, mpi/mpi.h mpi/mplogic.c mpi/mplogic.h: Reformatted comments. Removed useless comments. Removed superfluous blank lines and whitespace. Added space between C keywords if, for, while, sizeof and opening parens. Removed #if 0 blocks. Tabs to spaces.
* Update banner to inform about cheatsheet command.Kaz Kylheku2017-06-141-1/+1
| | | | * txr.c (banner): Text updated.
* linenoise: Ctrl-X ? displays editing cheatsheet.Kaz Kylheku2017-06-141-0/+101
| | | | | * linenoise/linenoise.c (show_help): New static function. (edit): Call show_help on Ctrl-X ?.
* ffi: turn carray-sub into accessor.Kaz Kylheku2017-06-133-2/+12
| | | | | | | | | | | | | | | | * lisplib.c (ffi_set_entries): Register carray-sub for autoload. * share/txr/stdlib/ffi.tl (carray-sub): New place macro, aliases to sub. This is not 100% correct since that means it will admit non-carray objects, but the alternative is to clone the entire sub expander with a few changes, or else factor out sub expansion into a shared routine. Bleh ... * txr.1: Documented. We don't cover up the ruse we perpetrated, and reveal that it's just a place macro targetting sub.
* bugfix: autoload syntactic places.Kaz Kylheku2017-06-132-2/+7
| | | | | | | | | | | | | | | | | | | | | | | TXR Lisp doesn't autoload the definition of places. For instance if a (set (foo x) y) appears out of the blue and foo is keyed for autoload, it doesn't happen. The right place to fix this is to do the autload check in the place macro expander, since every place form is tried as a macro. We need to expose the lisplib_try_load function as a Lisp intrinsic. * lisplib.c (lisplib_init): Register sys:try-load intrinsic, mapped to lisplib_try_load. * share/txr/stdlib/place.tl (sys:get-place-macro): New function. (sys:pl-expand): Use sys:get-place-macro instead of direct lookup in *place-macro* hash. The new function tries to autoload the symbol if it finds no place macro for it.
* ffi: fix buggy bitfield allocation.Kaz Kylheku2017-06-131-2/+2
| | | | | | | | | | | | | | * ffi.c (make_ffi_type_struct): When there is no room in the current bitfield, two mistakes are made. When bit_offs is reset to zero in this case, the dependent variable bits_alloc that was calculated from it (bits allocated to current unit) must also be reset. The subsequent shift depends on it. Secondly, when we establish the memb[i].offs field, that must come from offs, not from unit_offs, because unit_offs is always the base offset of the existing cell (which doesn't have room for the new bitfield in this case); the main offset variable offs is what gets gets adjusted to the cell which has room for the new bitfield.
* Version 178.txr-178Kaz Kylheku2017-06-127-929/+969
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* Follow up on C++ diagnostics.Kaz Kylheku2017-06-122-7/+7
| | | | | | | | | * ffi.c (ffi_generic_sbit_put, fi_generic_sbit_get, ffi_generic_ubit_put, fi_generic_ubit_get): Add needed coerce from zalloca to mem_t *. (make_ffi_type_struct): Fix signed/unsigned comparison. * lib.c (vector): Fix signed/unsigned comparison.
* Sort groups by symbol in protsym.c.Kaz Kylheku2017-06-121-0/+1
| | | | | * genprotsym.txr: Sort groups so that the protsym.c deltas, going forward, are more stable.
* Eliminate some blank lines in protsym.c.Kaz Kylheku2017-06-121-2/+4
| | | | | | * genprotsym.txr: use @(first) directive trick to eliminate leading blank lines in front of items that are not controlled by a preprocessor symbol.
* buf: new bufp function.Kaz Kylheku2017-06-123-0/+23
| | | | | | | | | * buf.c (bufp): New function. (buf_init): Registered bufp intrisic. * buf.h (bufp): Declared. * txr.1: Documented.
* awk macro: new fconv conversions c and cz.Kaz Kylheku2017-06-122-3/+22
| | | | | | | | | | * share/txr/stdlib/conv.tl (sys:conv-let): New local functions c and cz, using the new #\c radix conversion. * txr.1: Documented new extension under the fconv awk macro. Also fixed a typo here; the b conversion was exemplified as (c str).
* int-str: allow radix to be #\c for C conventions.Kaz Kylheku2017-06-122-22/+70
| | | | | | | | | * lib.c (int_str): Support #\c base, recognizing 0x as hex and leading 0 as octal. We don't rely on the wcstol function's ability to do this conversion, but scan it ourselves. * txr.1: Documented.
* doc: document bracket notation for carray and buf.Kaz Kylheku2017-06-121-1/+25
| | | | | * txr.1: Put carray and buf cases into the description of the indexing notation under the dwim operator.
* ffi: overflow checks in type system.Kaz Kylheku2017-06-121-10/+14
| | | | | | | | | | | | | | * ffi.c (make_ffi_type_struct): Use chk_xalloc instead of chk_malloc. (make_ffi_type_array): Use chk_xalloc. Since there are multiple callers, take a self argument to pass down to chk_xalloc. (ffi_type_compile): Pass self down to make_ffi_type_array. (ffi_make_call_desc): Use chk_xalloc. (carray_ensure_artype): Take a self argument and pass down to make_ffi_type_array. (carray_get_common, carray_put_common): Pass self down to carray_ensure_artype.
* streams: add overflow checks.Kaz Kylheku2017-06-121-4/+17
| | | | | | | | | * stream.c (open_process): Check that manipulations of nargs do not overflow int type. Use chk_xalloc. Allocation is done before pipe so we have no file descriptors to clean up if chk_xalloc throws. (run): In both versions of run, check that manipulations of nargs don't overflow int and use chk_xalloc.
* sysif: add overflow checks.Kaz Kylheku2017-06-121-14/+19
| | | | | | | | | | | | | | * sysif.c (excec_wrap): Check that our nargs manipulation doesn't exceed INT_MAX. Use chk_xalloc to allocate the argument vector, providing an overflow check. Use self variable in place function name embedded in literal. (getgroups_wrap): Use chk_xalloc instead of chk_malloc, so multiplication overflow is checked. Use self variable in place function name embedded in literal. (setgroups_wrap): Revamp existing overflow check. Use ucnum for the size, check that it can convert to size_t and back without loss of value, and use chk_xalloc instead of chk_malloc.
* lib: revamp overflow checks in vec operations.Kaz Kylheku2017-06-121-16/+11
| | | | | | | | | | | | | * lib.c (vector): Bugfix: we are checking whether length + 2 is negative, not length. Check the original value, and simplify everything using check_mulloc. (list_vec, sub_vec): Use chk_xalloc just in case. There shouldn't be any overflow if the vector was constructed and manipulated properly. (replace_vec): Replace division-based oveflow check with a simple test that total + 2 doesn't overflow; then rely on chk_xalloc to do the multiplication overflow check.
* lib: reimplement chk_wmalloc using chk_xalloc.Kaz Kylheku2017-06-121-4/+2
| | | | | * lib.c (chk_wmalloc): Drop the incorrect multiplication overflow test, and just call chk_xalloc.
* lib: new chk_xalloc, with mult overflow check.Kaz Kylheku2017-06-122-0/+13
| | | | | | | | | This will simplify code that allocates an array-like object whose size is the product of two numbers. * lib.c (chk_xalloc): New function. * lib.h (chk_xalloc): Declared.
* ffi: fix carray multiplication overflow checks.Kaz Kylheku2017-06-121-3/+3
| | | | | | | | * ffi.c (carray_dup): Do size multiplication using unsigned type, then coerce back to signed. Check for overflow correctly by first testing result for negative, then doing division check. (carray_replace): Add check for negative size, which confirms overflow.
* ffi: add carrayp function.Kaz Kylheku2017-06-123-0/+23
| | | | | | | | | * ffi.c (carrayp): New function. (ffi_init): Register carrayp intrinsic. * ffi.h (carrayp): Declared. * txr.1: Documented.
* ffi: new carray-replace function.Kaz Kylheku2017-06-114-0/+175
| | | | | | | | | | | | | | Thanks to this (set [ca from..to] list) works. * ffi.c (carray_replace): New function. (ffi_init): Register carray-replace intrinsic. * ffi.h (carray_replace): Declared. * ffi.c (replace): Hook in carray_replace. * txr.1: Mention carray under replace, and document carray-replace.
* ffi: new function, carray-pun.Kaz Kylheku2017-06-113-0/+60
| | | | | | | | | * ffi.c (carray_pun): New function. (ffi_init): Registered carray-pun intrinsic. * ffi.h (carray_pun): Declared. * txr.1: Documented.
* ffi: handle sub operation in carray.Kaz Kylheku2017-06-114-1/+136
| | | | | | | | | | | | | | | | Thus, [ca 3..5] syntax works for slice extraction. However, this works referentially, not by making a copy. The extracted subarray points to the original memory, until carray-dup is invoked on it. * ffi.c (carray_sub): New function. (ffi_init): carray-sub intrinsic registered. * ffi.h (carray_sub): Declared. * lib.c (sub): Handle carray via carray_sub. * txr.1: Documented changes in sub.
* ffi: support sel operation on carray.Kaz Kylheku2017-06-114-7/+42
| | | | | | | | | | | | | | | | | | | | Thus (select ca '(0 3 4 ...)) works and so does the sytnax [ca '(0 3 4 ...)]. This is inefficiently implemented. The selected elements are extracted to a list which is then converted to a carray of the same kind agan. * ffi.c (carray_list): New function. (ffi_init): Register carray-list intrinsic. * ffi.h (carray_list): Declared. * lib.c (make_like): Add carray case, so we can turn a list into a carray based on an example carray. This uses carray_list, with the type pulled from the original carray. The target isn't null terminated. (sel): Handle carray via vector case. * txr.1: Document changes in select and make-like.
* buf: support ref, refset and indexing.Kaz Kylheku2017-06-111-0/+5
| | | | * lib.c (generic_funcall, ref, refset): Handle BUF.
* length function supports carray.Kaz Kylheku2017-06-112-0/+8
| | | | | | * lib.c (length): Handle COBJ of carray type. * txr.1: Documented.
* doc: document length for buf.Kaz Kylheku2017-06-111-10/+13
| | | | | * txr.1: Restructure the length documentation to use definition-style paragraphs, and add buf.
* ffi: new carray-get and carray-put functions.Kaz Kylheku2017-06-103-0/+145
| | | | | | | | | | | | | | | | | * ffi.c (struct carray): New member, artype. (carray_mark_op): Mark artype member. (make_carray): Initialize artype to nil. (carray_ensure_artype, carray_get_common, carray_put_common): New static functions. (carray_get, carray_getz, carray_put, carray_putz): New functions. (ffi_init): Register intrinsics carray-get, carray-getz, carray-put, carray-putz. * ffi.h (carray_get, carray_getz, carray_put, carray_putz): Declared. * txr.1: Documented new functions.
* Rename carray_get.Kaz Kylheku2017-06-102-3/+3
| | | | | | | | * ffi.c (carray_get): Renamed to carray_ptr. (ffi_carray_put): Follow rename. * ffi.h (carray_get): Declaration removed. (carray_put): Declared.
* ffi: retain some functionality if libffi missing.Kaz Kylheku2017-06-104-19/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The FFI module is more than just foreign calls and callbacks; it provides a type system and operations for working with binary data. None of it depends on libffi being present and so shouldn't be disabled if libffi is not available. * Makefile (ffi.o): Unconditionally link this object file, not subject to the have_libffi variable. * configure (have_libffi): Variable removed. (gen_config_make): Do not generate a have_libffi variable into config.make, since nothing needs it. * ffi.c (ffi_type): Fake ffi_type defined if libffi is missing. (FFI_TYPE_STRUCT): Fake macro. (ffi_type ffi_type_void, ffi_type_pointer, ffi_type_sint, ffi_type ffi_type_schar, ffi_type_uchar, ffi_type ffi_type_sshort, ffi_type_ushort, ffi_type ffi_type_sint, ffi_type_uint, ffi_type ffi_type_slong, ffi_type_ulong, ffi_type ffi_type_sint8, ffi_type_uint8, ffi_type ffi_type_sint16, ffi_type_uint16, ffi_type ffi_type_sint32, ffi_type_uint32, ffi_type ffi_type_sint64, ffi_type_uint64, ffi_type ffi_type_float, ffi_type_double): Fake libffi type objects, so that code which references these things will build without modification. (ffi_get_type): Function only defined if we have libffi. (ffi_type_struct_destroy_op, ffi_struct_clone, make_ffi_type_struct, ffi_array_clone, make_ffi_type_array): Don't work with ffi_type's element array if we don't have libffi; our fake ffi_type doesn't have such an array. (struct txr_ffi_closure): Type only defined if we have libffi. (ffi_closure_struct, ffi_closure_struct_checked, ffi_closure_print_op, ffi_closure_destroy_op, ffi_closure_mark_op, ffi_closure_put): Functions only defined if we have libffi. (ffi_closure_ops): Static structure only defined if we have libffi. (ffi_init_types): Don't register a closure type if we don't have libffi. (struct txr_ffi_call_desc): Don't define type if we don't have libffi. (ffi_call_desc, ffi_call_desc_checked, ffi_call_desc_print_op, ffi_call_desc_destroy_op, ffi_call_desc_mark_op, ffi_make_call_desc, ffi_call_wrap, ffi_closure_dispatch, ffi_closure_dispatch_safe, ffi_make_closure, ffi_closure_get_fptr): Functions only defined if we have libffi. (ffi_call_desc_ops): Static structure only defined if we have libffi. (ffi_init): Only register ffi-make-call-desc, ffi-call, and ffi-make-closure if we have libffi. * lib.c: Include "ffi.h" header unconditionally. (generic_funcall, ref, refset, int): Remove #if HAVE_LIBFFI.
* ffi: bugfix: string semantics for incomplete zarray.Kaz Kylheku2017-06-101-17/+28
| | | | | | | | | | | | The problem is that the get semantics (zarray char) produces a vector of characters, not a string. Ditto for bchar and wchar. * ffi.c (ffi_varray_null_term_in): Check for the char_conv, wchar_conv or bchar_conv flag and delegate to ffi_array_get_common. (ffi_type_compile): Set char_conv, wchar_conv or bchar_conv flag for incomplete zarray.
* ffi: bugfix: string semantics on typedef-d chars.Kaz Kylheku2017-06-101-3/+3
| | | | | | | | | | | | | | The problem is that if we have a typedef like (typedef x char) then (array 256 x) will not do string conversion in the manner of (array 256 char). This is because the raw syntax is checked for the symbol char, rather than inspecting the type object. * ffi.c (ffi_type_compile): When checking whether the array element is a char, bchar or wchar, look at the syntax in the compiled type object, not the raw syntax. The compiled type object is the original type pulled from behind the typedef alias and has the symbol char, bchar or wchar as its syntax.
* doc: carray corrections.Kaz Kylheku2017-06-091-7/+12
| | | | | * txr.1: forgotten documentation added: the carray-own function can't be used on a carray which references a buf.
* ffi: support ref, refset and indexing on carray.Kaz Kylheku2017-06-091-0/+13
| | | | | | | | | * lib.c (generic_funcall): Handle carray object via the same cas that handles vectors, lists and strings. That in turn works via ref and other lower-level functions (not all of which support carray yet). (ref): Handle carray object via carray_ref. (refset): Handle carray_object via carray_refset.
* awk macro: fix broken rng.Kaz Kylheku2017-06-072-9/+22
| | | | | | | | | | | | | | | Bug: rng fails to activate when the to and from condition are true for the same record. * share/txr/stdlib/awk.tl (sys:awk-mac-let): Rename the flag-new gensym holder to flag-act, since it indicates whether the range is active, either from before or due to being activated by the current record. A new gensym is added to indicate whether the range is being deactivated in this record. The inclusive rng range refers to this variable rather than flag-old. But a bug emulation is provided to refer to the wrong variable. * txr.1: Added compatibility note.
* Version 177.txr-177Kaz Kylheku2017-06-077-864/+939
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: conform to GCC's bitfield layout algorithm.Kaz Kylheku2017-06-072-66/+137
| | | | | | | | | | | The way bitfields are laid out must be changed. The requirements were reverse-engineered by experimentation. * ffi.c (make_ffi_type_struct): Member allocation loop substantially rewritten. * txr.1: Documentation rewritten. Description of the bitfield allocation algorithm moved to a separate paragraph.
* better error message for unum conversion.Kaz Kylheku2017-06-061-1/+1
| | | | | | * arith.c (c_unum): When the input value is negative, complain about that, not about uint_ptr_t, which means nothing in TXR Lisp.
* ffi: support bitfields on types narrower than int.Kaz Kylheku2017-06-063-29/+183
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (bit_s): New symbol variable. (ffi_generic_sbit_put, ffi_generic_sbit_get, ffi_generic_ubit_put, ffi_generic_ubit_get): New static functions. (bitfield_syntax_p): Include bit symbol in the check. (make_ffi_type_pointer): Zero size is no longer an early rejection test for bitfields; don't rely on it. (make_ffi_type_struct): Revise the member calculating loop to handle bitfields of various sizes. If a bitfield follows one of a different size, it starts a new cell even if the previous one has room, et cetera. The masking and shifting is set up to work on cells of int size; however, the new ffi_generic_s?bit_{put,get} functions use a temporary buffer and transfer just the right number of bytes to and from the actual buffer. (ffi_struct_compile): The check against incomplete type members only needs to test size zero; bitfields have nonzero size now, which is the true size of the underlying storage unit. They also have true alignment, which is used in make_ffi_type_struct rather than hard-coding to alignof (int). New syntax (bit width type) is now handled, where type can be any of the signed and unsigned integral types up to int32 and int. The endian types are not supported for now. (ffi_typedef, ffi_size, ffi_alignof): Zero size is no longer an early rejection test for bitfields; don't rely on it. (ffi_init): Initialize bit_s. * ffi.h (bit_s): Declared. * txr.1: Documented.
* ffi: bugfix: assign evaluated syntax to bitfield.Kaz Kylheku2017-06-061-1/+2
| | | | | | * ffi.c (ffi_type_compile): Give the bitfield type the evaluated syntax where the width expression is reduced to an integer value.