summaryrefslogtreecommitdiffstats
path: root/ffi.c
Commit message (Collapse)AuthorAgeFilesLines
* ffi: use existing local instead of struct access.Kaz Kylheku2018-06-251-4/+4
| | | | | | * ffi.c (ffi_closure_dispatch, ffi_closure_dispatch_safe): The nargs variable holds a copy of tfcl->nparam, so use it instead of accessing tfcl->nparam again.
* bugfix: include most negative two's in cnum range.Kaz Kylheku2018-04-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The INT_PTR_MIN value isn't the smallest value actually representable in cnum, because it is just the additive inverse of INT_PTR_MAX. In two's complement, the INT_PTR_MIN-1 value is still representable. But we are excluding it. If a Lisp integer has the value INT_PTR_MIN-1, the c_num function will fail to convert it to a cnum. This situation occurs in FFI, where code may expect that the Lisp value #x-80000000 can convert to an external 32 bit integer type. This will be done by way of a conversion to cnum first via c_num (see ffi_i32_put for instance, which calls c_i32 which relies on c_num). * arith.c (INT_PTR_MAX_SUCC_MP): New static variable. This holds a bignum equivalent to INT_PTR_MAX + 1. (in_int_ptr_range): We now check whether the value against the range [-(INT_PTR_MAX + 1), (INT_PTR_MAX + 1)] and then check all possible return values. The MP_LT case is clearly in range, and MP_GT is out of the range. The interesting situation is MP_EQ: in that case we just test the sign to see whether we are looking at -(INT_PTR_MAX + 1). (int_flo): INT_PTR_MIN is referenced in this function, so we use INT_PTR_MIN - 1 instead. This allows that value to be handled via the simple bignum(n) case. (arith_init): Initialize INT_PTR_MAX_SUCC_MP. We cannot initialize it to INT_PTR_MAX + 1 directly because that expression overflows: insted we use INT_PTR_MIN - 1 and then flip the resulting bignum's sign. (arith_free_all): Call mp_clear on the new variable to release its digit buffer. * ffi.c (make_ffi_type_enum): Use INT_PTR_MIN - 1 as the initial value of the highest variable, to accurately calculate the range of the enum values if they contain INT_PTR_MIN - 1.
* args: overhaul for clarity and reduced consing.Kaz Kylheku2018-03-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * args.c (args_normalize): Renamed to args_normalize_exact, because this tries to split the arguments between an exact array fill quantity and trailing list. Not all places using this function actually need an exact fill, which causes unnecessary consing when args->fill is reduced in order to move items to args->list. (args_normalize_least): New function. Variant of args_normalize that can be used by functions which only require a minimum fill. (args_normalize_fill): Use args_normalize_least rather than args_normalize_exact. This reduces consing in generic_funcall, in handling variadic calls where arrayed arguments have been supplied for trailing parameters. * args.h (args_normalize): Renamed to args_normalize_exact. (args_normalize_least): Declared. (args_get_list, args_get_rest): Use args_normalize_exact. (args_clear): Inline function removed. Was used only in one place in generic_funcall and is no longer. * eval.c (gather_free_refs): Use args_normalize_least. (prod_common): Use args_normalize_exact. * ffi.c (ffi_call_wrap): Use args_normalize_least. * lib.c (generic_funcall): Use args_normalize_least in switch statement that handles various callable non-function objects. When copying args, ensure that there are ARGS_MIN. A different strategy is used for producing the trailing args for variadic calls, further reducing consing. Rather than normalize the args to the fixed number, and then set args->fill to zero so that args contains just the list, we use args_cat_zap_from to create a copy of the args in which the fixed ones are trimmed out. The resulting args is not renormalized to be purely a list so no consing or list traversal takes place. If the rebalancing is needed, the called function will have to do it. (dwim_set): Streamline the code that handles hashes assigned via two or three args. * struct.c (method_args_fun, umethod_args_fun): Use args_normalize_exact.
* Copyright year bump 2018.Kaz Kylheku2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, win/cleansvg.txr: Extended Copyright line to 2018.
* carray: check type object in several API functions.Kaz Kylheku2017-10-261-4/+4
| | | | | | | * ffi.c (carray_blank, carray_buf, carray_cptr, carray_pun): these functions should be using ffi_type_struct_checked, since they are public interfaces to which anything can be passed. Otherwise TXR can easily be crashed by misusing them.
* carray: bugfix: allow negative indexing in ref operation.Kaz Kylheku2017-10-261-0/+3
| | | | | | * ffi.c (carray_ref): If the index is negative, displace it by the length of the array. (Then if it is still negative, the function will throw.)
* ffi: new FFI type I/O functions.Kaz Kylheku2017-08-161-0/+45
| | | | | | | | | * ffi.c (put_obj, get_obj, fill_obj): New functions. (ffi_init): put-obj, get-obj, fill-obj intrinsics registered. * ffi.h (put_obj, get_obj, fill_obj): Declared. * txr.1: Documented.
* ffi: new buf-carray function.Kaz Kylheku2017-08-081-0/+9
| | | | | | | | | * ffi.c (buf_carray): New function. (ffi_init): Registered buf-carray intrinsic. * ffi.c (buf_carray): Declared. * txr.1: Documented.
* ffi: add offset argument to ffi buffer functions.Kaz Kylheku2017-07-161-26/+50
| | | | | | | | | | | | | * ffi.c (ffi_put_into, ffi_in, ffi_get, ffi_out): New offset parameter. (ffi_init): Re-register ffi-put-into, ffi-in, ffi-get and ffi-out with new optional parameter. * ffi.c (ffi_put_into, ffi_in, ffi_get, ffi_out): Declarations updated. * txr.1: Documented new argument on ffi-put-into, ffi-in and ffi-get. The documentation for ffi-out doesn't exist!
* carray: add offset to carray-buf.Kaz Kylheku2017-07-151-15/+31
| | | | | | | | | | | | | | * ffi.c (struct carray): New member, offs. (make_carray): Initiialize offs member from new argument. (copy_carray, carray_blank, carry_ptr, carray_sub, carray_pun, carray_unum, carray_num): Pass zero offset to (carray_buf): New optional parameter off_in. (carray_buf_sync): Handle offset. (ffi_init): Update registration of carray-buf. * ffi.h (make_carray, carray_buf): Declaration updated. * txr.1: Documented.
* Fix use of raw null constant in carray implementation.Kaz Kylheku2017-07-151-1/+1
| | | | | | * ffi.c (carray_cptr): Ref argument in make_carray call should be specified as nil not 0. The meaning is the same, but it's wrong style for TXR internals.
* ffi: new function, zero-fill.Kaz Kylheku2017-07-091-0/+33
| | | | | | | | | * ffi.c (zero_fill): New function. (ffi_init): zero-fill intrinsic registered. * ffi.h (zero_fill): Declared. * txr.1: Documented.
* ffi: new make-zstruct function and znew macro.Kaz Kylheku2017-07-021-0/+45
| | | | | | | | | | | | | * ffi.c (make_zstruct): New function. (ffi_init): Register make-zstruct instrinsic. * ffi.h (make_zstruct): Declared. * lisplib.c (ffi_set_entries): Add znew to autload list. * share/txr/stdlib/ffi.tl (znew): New macro. * txr.1: Documented make-zstruct and znew.
* ffi: new ffi-type-operator-p and ffi-type-p.Kaz Kylheku2017-06-301-0/+18
| | | | | | | | | | * ffi.c (ffi_type_operator_p, ffi_type_p): New functions. (ffi_init): Register ffi-type-operator-p and ffi-type-p intrinsics. * ffi.h (ffi_type_operator_p, ffi_type_p): Declared. * txr.1: Documented.
* ffi: fix more bugginess in struct bitfield allocation.Kaz Kylheku2017-06-291-2/+2
| | | | | | | | | * ffi.c (make_ffi_type_struct): Fix incorrect shift calculations, which are still being done from the unit_offs byte rather than the correct offs byte where the bitfield is actually placed. It is bit_offs which has the correct bit offset of the bitfield relative to offs.
* ffi: make-union can initialize.Kaz Kylheku2017-06-291-3/+12
| | | | | | | | | | | * ffi.c (make_union): Two arguments added. These are optional. (ffi_init): Update registration of make-union as three-parameter function, with one required arg. * ffi.h (make_union): Declaration updated. * txr.1: Documented.
* ffi: fix union printing as struct.Kaz Kylheku2017-06-291-1/+1
| | | | | * ffi.c (ffi_type_compile): Syntax for union type wrongly using struct symbol rather than union.
* ffi: fix bool printing as integer type.Kaz Kylheku2017-06-291-1/+1
| | | | | | * ffi.c (ffi_type_compile): Assign full bool syntax to cloned type, rather than just the argument syntax denoting the base type.
* ffi: reject bitfields as arguments or return values.Kaz Kylheku2017-06-291-0/+6
| | | | | * ffi.c (ffi_make_call_desc): Throw error if argument or return value is a bitfield.
* ffi: tighten syntax validation in type compiler.Kaz Kylheku2017-06-291-2/+46
| | | | | * ffi.c (ffi_type_compile): Check for too few or too many arguments in a compound form.
* ffi: new enumed type operator: enums with base type.Kaz Kylheku2017-06-271-1/+13
| | | | | | | | | | * ffi.c (enumed_s): New symbol variable. (ffi_type_compile): New case for enumed type op. (ffi_init): Initialize enumed_s. * ffi.h (enumed_s): Declared. * txr.1: enumed documented.
* ffi: prepare for variably sized enum implementation.Kaz Kylheku2017-06-271-17/+26
| | | | | | | | | | | | | | | | | | | This lays the groundwork for enumerations based off types other than int. All we need to do is implement the syntax for this. * ffi.c (ffi_enum_put, ffi_enum_get, ffi_enum_rput, ffi_enum_rget): Retrieve the element type descriptor and recurse into its put, get, rput and rget operation, respectively, instead of hard-coded calls to the int operations. (make_ffi_type_enum): New argument, base_type. Numerous properties of the enum type are taken from base_type: the FFI type, the alignment, size, and alloc, free and clone operations. The base type is installed as eltype. (ffi_type_lookup): Static function relocated. (ffi_type_compile): In the enum case, resolve the int type and pass to make_ffi_type_enum.
* ffi: bugfix: diagnostic problems in enum put.Kaz Kylheku2017-06-271-6/+8
| | | | | | * ffi.c (ffi_enum_put, ffi_enum_rput): Fix function name appearing in quotes in error diagnostic. Fix nonexistent member being wrongly reported as nil.
* ffi: add missing rput/rget ops for big endian.Kaz Kylheku2017-06-271-0/+35
| | | | | | | | | | | | We either mishandle return values, or crash due to a null rput/rget function pointers on aggregate types and bools. * ffi.c (ffi_bool_rput, ffi_bool_rget): New static functions. (make_ffi_type_pointer, make_ffi_type_struct, make_ffi_type_union, make_ffi_type_array): Fill in rput and rget. (ffi_type_compile): Fill in rget and rput for bool with new functions.
* ffi: fix incorrect null-terminated array in op.Kaz Kylheku2017-06-271-3/+4
| | | | | | | | | * ffi.c (ffi_varray_null_term_in): Rewrite nonsensical code that refers to the newly created empty output array as input. We must perform the in semantics on all the original elements. Then get semantics on any new elements if the array was extended, and the copy flag is true (by-ref nuance).
* ffi: bugfix: varray alloc not accounting for null term.Kaz Kylheku2017-06-261-1/+1
| | | | * ffi.c (ffi_varray_alloc): Add tft->null_term to length.
* ffi: bugfix: null-terminated zarray in semantics.Kaz Kylheku2017-06-261-1/+1
| | | | | | * ffi.c (ffi_varray_null_term_in): Pass zero to replace rather than 0, which corresponds to nil and is interpreted as a list by replace.
* ffi: fix leak in new union code.Kaz Kylheku2017-06-251-1/+1
| | | | | | * ffi.c (make_ffi_type_union): Create cobj with correct cobj_ops structure: ffi_type_struct_ops, not ffi_type_enum_ops.
* ffi: fix incorrect cptr type tag implementation.Kaz Kylheku2017-06-241-6/+14
| | | | | | | | | | | | | | | | | | | We can't use the eltype field of the type structure to store the cptr tag symbol, because that is expected to be a type object and not a symbol. * ffi.c (struct txr_ffi_type): New member, tag. (ffi_cptr_put, ffi_cptr_get, ffi_cptr_alloc): Refer to tag rather than eltype. (ffi_type_compile): Handle the compound cptr type using the same code as the simple one in ffi_init_types: use make_ffi_type_builtin rather than make_ffi_type_pointer. Install the tag into the tag field. Also set up the forgotten alloc and free routines. (ffi_init_types): For cptr, explicitly initialize the tag to nil. This is not necessary since the structure is calloced, and we rely on that for nil all over the place, but here it serves as a reminder that cptr has a tag.
* ffi: fix memory leak regression.Kaz Kylheku2017-06-241-0/+3
| | | | | | | | | | | | The recent commit "ffi: elide useless by-value in calls." neglects to mark a few types with the by_value_in flag. The string types need it because their in action performs memory freeing, which must be done regardless of the by-value or by-pointer semantics. * ffi.c (ffi_init_types): set by_value_in to 1 for str, bstr and wstr. In general, if the type needs a release function, it needs by_value_in to be set.
* ffi: provide longlong and ulonglong types.Kaz Kylheku2017-06-241-0/+4
|
* ffi: elide useless by-value in calls.Kaz Kylheku2017-06-241-11/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We can avoid calling in methods in the by-value nuance (copy == 0) on types known not to have by-value in semantics. Basic types have no by-value in. Pointers inherently have by-value in. An aggregate has by-value in semantics if any of one of its members does, otherwise not. * ffi.c (struct txr_ffi_type): New bitfield member, by_value_in. (ffi_ptr_in_in, ffi_ptr_in_d_in): Elite in call if target type's by_value_in flag is clear. (ffi_struct_in): Short-circuit to a return if doing by-value, and the FFI struct type has no by-value semantics. (ffi_array_in_common): Likewise. In this code change, we just have to replace the test whether the element type has an in method with a test of its by_value_in flag. (make_ffi_type_pointer): Set by_value_in flag to 1, since pointers have by value in semantics. This is true also of ptr-in, because a structure passed as an in parameter to a function via ptr-in could itself contain ptr or ptr-out elements. (make_ffi_type_struct): Set the type's by_value_in if any element type's by_value_in is true. (make_ffi_type_array): Propagate the by_value_in flag from the element type to the array type. (ffi_call_wrap): Calculate the in_pass_needed local flag from the by_value_in flags of the arguments, not from whether or not they have an in function. Only call the in function for arguments which have the flag set.
* ffi: short-circuit useless by-value in semantics.Kaz Kylheku2017-06-231-15/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The theme here is that if a struct or array is being subject to a by-value in operation, there is nothing to do for that aggregate itself. So if there is no corresponding Lisp object, we should not create one. The caller isn't expecting it and will throw it away. If it is known that no element of an aggregate supports by-value semantics, then the operation should short-circuit, and not perform a useless loop. * ffi.c (ffi_struct_in): If the strct parameter is nil, don't unconditionally make a new structure; do so only when the copy flag is asserted (by reference semantics). If there is no Lisp struct object and by value semantics is in effect, there is no point in doing anything; just short-circuit to a nil return. (ffi_array_in_common): If doing by value semantics, and there is no vector object or the structure element type has no by value in semantics (such as a basic type), then short circuit to an early return. (ffi_array_in): Only do the special string decoding when reference semantics is in effect; there is no point in extracting strings back from a by-value struct. If by-value semantics is in effect, we fall through to the ffi_array_in_common call even for character types; but since those types have no by-value in semantics, that function will just short-circuit, which is what we want. (ffi_varray_in): If there is no vec, bail out with nil, regardless of whether this is by value or not. Just return vec if by-value semantics is in effect; don't try to update it.
* ffi: provide support for unions.Kaz Kylheku2017-06-231-2/+269
| | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (union_s): New symbol variable. (ffi_find_memb, ffi_memb_not_found): New static functions. (ffi_union_in, ffi_union_put, ffi_union_get): New static functions. (make_ffi_type_union): New static function. (ffi_struct_compile): Handle union syntax using ffi_struct_compile to compile the member definitions to types, and make_ffi_type_union to produce the type node. (struct uni): New struct type. (uni_struct, uni_struct_checked): New static functions. (union_destroy_op, union_mark_op): New static functions. (union_ops): New static struct. (make_union_common, make_union_tft): New static functions. (union_get_ptr, make_union, union_members, union_get, union_put, union_in, union_out): New functions. (ffi_init): Initialize union_s. Register intrinsics make-union, union-members, union-get, union-put, union-in, union-out. * ffi.h (union_s, union_get_ptr, make_union, union_members, union_get, union_put, union_in, union_out): Declared. * txr.1: Documented unions.
* ffi: add back-pointer into type structure.Kaz Kylheku2017-06-231-0/+6
| | | | | | | | | | | Upcoming work is going to benefit from a pointer for navigating from the txr_ffi_type structure to the Lisp object whose implementation is that structure. * ffi.c (struct txr_ffi_type): New member, self. (make_ffi_type_builtin, make_ffi_type_pointer, make_ffi_type_struct, make_ffi_type_array, make_ffi_type_enum): Initialize self pointer.
* ffi: override libffi size/alignment calculations.Kaz Kylheku2017-06-211-51/+16
| | | | | | | | | | | | | | | | | | Don't bother creating and filling the ffi_type elements[] array for a structs or array. Let's punch in the size and alignment fields with the values we calculate ourselves already, and set up a dummy elements[] array that contains only a null terminator. * ffi.c (struct txr_ffi_type): New member, elements: one element dummy array that holds a null pointer. (ffi_type_struct_destroy_op): Do not free ft->elements, since it isn't dynamically allocated any more. (ffi_struct_clone, ffi_array_clone): Don't copy the elements array; just set up a dummy elements array in the copied type. (make_ffi_type_struct, make_ffi_type_array): Eliminate the dynamic allocation of the elements array. Point ft->elements to the dummy array. Set up the ft->size and ft->alignment.
* ffi: fix broken float put.Kaz Kylheku2017-06-201-2/+6
| | | | | | | | * ffi.c (ffi_float_put): Fix silly range check: FLT_MIN and FLT_MAX are, of course, both positive. Also, fix num being used as an argument in the error diagnostic. It's the address of a C function, not an object.
* ffi: bool type.Kaz Kylheku2017-06-201-0/+33
| | | | | | | | | | | | * ffi.c (bool_s): New symbol variable. (ffi_bool_put, ffi_bool_get): New static functions. (ffi_type_compile): Handle (bool <type>) parametrized type. (ffi_init_types): Register bool typedef for (bool uchar). (ffi_init): Initialize bool_s. * ffi.h (bool_s): Declared. * txr.1: Documented.
* Handle returns of MPI functions that return MP_TOOBIG.Kaz Kylheku2017-06-181-6/+6
| | | | | | | | | | | * arith.c (do_mp_error): New function. (num_from_buffer, plus, minus, mul, floordiv, expt, exptmod, logtrunc, sign_extend, ash, bit): Handle errors from select MPI functions: those that have the mp_ign attribute. * ffi.c (unum_carray, num_carray): Likewise. * rand.c (random): Likewise.
* ffi: copy-carray, hooked into copy.Kaz Kylheku2017-06-151-0/+9
| | | | | | | | | | | | * 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-151-0/+26
| | | | | | | | | | * 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-141-0/+110
| | | | | | | | | | | | * 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.
* 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.
* Follow up on C++ diagnostics.Kaz Kylheku2017-06-121-6/+6
| | | | | | | | | * 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.
* 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.
* 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-121-0/+6
| | | | | | | | | * 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-111-0/+93
| | | | | | | | | | | | | | 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-111-0/+21
| | | | | | | | | * 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-111-0/+43
| | | | | | | | | | | | | | | | 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.