summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* doc: cptr.Kaz Kylheku2017-05-101-0/+149
| | | | * txr.1: The cptr type is now documented.
* doc: relocate and rewrite buffer literal description.Kaz Kylheku2017-05-091-12/+25
| | | | | | * txr.1: Buffer literals are now described much earlier in the document under Additional Syntax rather than in the Buffers section.
* doc: add buf and cptr to type diagram.Kaz Kylheku2017-05-091-1/+5
| | | | * txr.1: Update ASCII diagram in Object Types section.
* doc: dlopen added.Kaz Kylheku2017-05-091-0/+166
| | | | | * txr.1: Documented dlopen, dlclose and friends, plus the rtld-* variables.
* cptr: new functions.Kaz Kylheku2017-05-093-0/+35
| | | | | | | | | | * eval.c (eval_init): Register cptr-int, ctpr-obj, cptr-zap and cptr-free functions and cptr-null variable. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): New functions. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): Declared.
* ffi: remove cptr stuff.Kaz Kylheku2017-05-091-7/+0
| | | | | * ffi.c (cptr_make): Function removed. (ffi_init): Registration of cptr and cptr-null removed.
* ffi: integers and chars may convert to C float.Kaz Kylheku2017-05-092-7/+33
| | | | | | | | | * ffi.c (ffi_float_put, ffi_double_put): Support a useful type looseness by allowing integers and character Lisp values to pair with FFI floating-point types, imitating the conversion which happens in C function calls. * txr.1: Updated.
* doc: FFI module documented.Kaz Kylheku2017-05-091-0/+1618
|
* ffi: eliminate memcpy in basic gets and puts.Kaz Kylheku2017-05-081-52/+36
| | | | | | | | | | | | | | * ffi.c (ffi_i8_put, ffi_u8_put, ffi_i16_put, ffi_i16_get, ffi_u16_put, ffi_u16_get, ffi_i32_put, ffi_i32_get, ffi_u32_put, ffi_u32_get, ffi_i64_put, ffi_i64_get, ffi_u64_put, ffi_u64_get, ffi_char_put, ffi_char_get, ffi_uchar_get, ffi_short_get, ffi_ushort_put, ffi_ushort_get, ffi_int_put, ffi_int_get, ffi_uint_put, ffi_uint_get, ffi_long_put, ffi_long_get, ffi_ulong_put, ffi_ulong_get, ffi_float_put, ffi_float_get, ffi_double_put, ffi_double_get, ffi_wchar_put, ffi_wchar_get, ffi_cptr_put, ffi_cptr_get): memcpy operations replaced by by assignments through pointer casts.
* ffi: improve printed representation of closures.Kaz Kylheku2017-05-081-1/+2
| | | | | | * ffi.c (ffi_closure_print_op): Add information to the printed representation: the Lisp function, and call desc. Eliminate spurious # character before closing angle bracket.
* ffi: don't zero out anonymous struct padding.Kaz Kylheku2017-05-081-4/+0
| | | | | | | | | | * ffi.c (ffi_struct_put, ffi_struct_out): Just skip the space corresponding to the anonymous padding member; don't memset with zeros. Doing this is inconsistent because we are not zero-filling the ordinary alignment padding between members and at the end of the struct. If the uninitialized garbage is a problem in some uses, we can provide a variation of the struct type which is zero initialized.
* doc: documenting buffers.Kaz Kylheku2017-05-081-0/+739
|
* buffers: correct length check in buf-put- functions.Kaz Kylheku2017-05-081-2/+3
| | | | | | | * buf.c (buf_put_bytes): We must extend the buffer based on looking at the end position of the data transfer, not the start position, so the buffer is large enough to old the entire transfer.
* buffers: don't let a buffer shrink to zero.Kaz Kylheku2017-05-081-4/+6
| | | | | | | * buf.c (buf_shrink): If a buffer has zero length, don't shrink the allocation size all the way down to zero, because that value indicates a non-resizeable buffer.
* ffi: varray: write out all elements of Lisp seq.Kaz Kylheku2017-05-071-2/+2
| | | | | | | * ffi.c (ffi_array_put, ffi_array_out): If dealign with a variable array that is null terminated, let's add one to nelem, so that all elements of the Lisp sequence are converted, and then a null.
* ffi: rethink passing and alloc scheme for bufs.Kaz Kylheku2017-05-073-23/+34
| | | | | | | | | | | | | | | | | Backing out of the scheme of (ptr buf) passing the address of the internal pointer within buf objects. Also giving buf in handlers, to prevent the fallback on get. * buf.c (buf_addr_of): Function removed. * buf.h (buf_addr_of): Declaration removed. * ffi.c (ffi_buf_in, ffi_buf_d_in): New functions. (ffi_buf_alloc): Function removed. (ffi_type_compile, ffi_init_types): Remove specialty alloc and free functions from buffers, so the regular fixed allocator is used. Give buffers the new in functions.
* ffi: semantics: ptr-in should recurse on in.Kaz Kylheku2017-05-071-1/+14
| | | | | | | | | | * ffi.c (ffi_ptr_in_in): Don't just free the buffer for the pointer itself, but call the in handler of the target type if it has one. Pass a false copy flag to it, so that that a ptr-in pass semantically resembles a by-value pass. (ffi_ptr_in_d_in): New static function. (ffi_type_compile): Give ptr-in-d type the ffi_ptr_in_d_in function.
* ffi: bugfix: all in calls must fall back on get.Kaz Kylheku2017-05-072-4/+12
| | | | | | | | | | | | | | | | * ffi.c (ffi_ptr_out_in, ffi_ptr_out_s_in): If the target type has no in handler, fall back on its get. Here, it is without regard for the copy flag, because a zero value of that flag just indicates that the ptr-out itself is passed by-value. The target object is never by value (ffi_in): Add copy flag parameter, so the full interface is exposed, like in ffi_out. Fall back on get, if there is no in and the copy flag is true. Just return the original object if the type has no in, and copy is false. (ffi_init): Registration of ffi-in adjusted to four parameters. * ffi.h (ffi_in): Declaration updated.
* ffi: bufix: elide get if copy flag is false.Kaz Kylheku2017-05-071-2/+2
| | | | | | | | | | * ffi.c (ffi_struct_in, ffi_array_in): Only fall back on get if the copy flag is true. If the copy flag is false, we must not extract. That's not ony as an optimization (no point in extracting back from by-value objects). We also avoid extracting from pointers we don't own, like in the case of str-d, where the pointer is owned by the foreign function and may have been freed.
* ffi: bugfix: all out calls must fall back on put.Kaz Kylheku2017-05-071-4/+10
| | | | | | | * ffi.c (ffi_struct_out, ffi_array_out): For any element which has no out function, do a put if the copy flag is true. Otherwise callbacks cannot update members in aggregates passed by pointer.
* ffi: bugfix: bstr needs in operation, like str.Kaz Kylheku2017-05-071-3/+20
| | | | | | * ffi.c (ffi_bstr_in): New function. (ffi_init_types): Give bstr type ffi_bstr_in as the in function.
* ffi: bugfixes: out pointer must be checked.Kaz Kylheku2017-05-061-2/+6
| | | | | | | | | * ffi.c (ffi_closure_dispatch): Only call out on those arguments which have a non-null out pointer, otherwise we will crash. Those non-null values are the reason we even execute that loop at all. (ffi_out): Do a put for basic types (which have no out handler).
* ffi: reduce (array void t) syntax to (array t).Kaz Kylheku2017-05-061-28/+33
| | | | | | | | | | Omission of the dimension will be expressed by actual omission rather than the void placeholder. It's just a harmless bit of parsing providing a reasonably intuitive syntax that doesn't leave readers wondering what void is doing there. * ffi.c (ffi_type_compile): Rearrange array parsing code. Also diagnose if the form has more than thre elements.
* ffi: add macro language.Kaz Kylheku2017-05-062-0/+110
| | | | | | | | * lisplib.c (ffi_set_entries, ffi_instantiate): New static functions. (lisplib_init): Register auto-loading of ffi.tl. * share/txr/stdlib/ffi.tl: New file.
* ffi: handle copy flag in str type's in virtual.Kaz Kylheku2017-05-061-4/+6
| | | | | | | | | | | | | | | This solves the second issue described in parent commit. When a str type is passed in-out using (ptr str) in a struct or array, the struct or array is not picking up the new string. The pointer is freed, but the old object persists. * ffi.c (ffi_str_in): Function renamed to ffi_str_in. If the copy flag is true, retrieves a string from the pointer and that string is returned instead of the incoming one, mapping a null pointer to nil. Either way, the pointer is freed. Since ffi_ptr_out_in passes 1 for the copy flag, that ensures we extract the new string and plant it into the array.
* ffi: in function copy flag: fixes two issues.Kaz Kylheku2017-05-061-21/+21
| | | | | | | | | | | | | | | | | | | | | We have two problems. Firstly, the in handler is being called on by-value struct and array arguments, and is wastefully updating the members in the Lisp object. The second issue is opposite the str type fails to retrieve the updated string because ffi_freeing_in just frees. We don't address this issue here, but the groundwork is laid to fix it in the next commit. * ffi.c (struct txr_ffi_type *): Add a copy flag argument to the in virtual function. (ffi_freeing_in, ffi_ptr_in_in, ffi_ptr_out_in, (ffi_ptr_out_in, ffi_ptr_out_s_in): Take new copy argument. Don't pass it down to the recursive in; pass 1. (ffi_struct_in, ffi_array_in): Take copy argument and pass it down. (make_ffi_type_pointer): Type of in parameter updated. (ffi_call_wrap): Pass 0 to top level in functions. (ffi_in): Pass to in, so new object is returned.
* ffi: varray featureKaz Kylheku2017-05-061-3/+27
| | | | | | | | | | | | | | | | | If an array dimension is void, it is a varray. The C representation is pointer. The size is inferred from the length of the object. Doesn't support get method. * ffi.c (struct txr_ffi_type): New bitfield flag, is_varray. (ffi_varray_alloc): New function. (ffi_array_in, ffi_array_put, ffi_array_out): Check is_varray flag and use dynamic array size from object. (ffi_type_compile): If the array dimension is the symbol void, create a varray: a mongrel created using make_ffi_type_pointer, but using the array functions, plus alloc and free handlers, and the is_varray flag being set.
* ffi: remove unchanging param from make_ffi_pointer.Kaz Kylheku2017-05-061-9/+2
| | | | | | | | * ffi.c (make_ffi_type_pointer): The underlying ffi type is always ffi_type_pointer, so the parameter for specifying it is removed, and it is hard-coded. (ffi_type_compile): Remove &ffi_type_pointer argument from a half dozen calls.
* ffi: ffi-size function.Kaz Kylheku2017-05-062-0/+8
| | | | | | | | | This will support a sizeof macro. * ffi.c (ffi_size): New function. (ffi_init): Register ffi-size intrinsic. * ffi.h (ffi_size): Declared.
* Fix broken quasilist print notation.Kaz Kylheku2017-05-051-1/+0
| | | | | | * lib.c (obj_print_impl): Remove spurious output statement from quasi word list literal printing code. The spurious output completely ruins the printed representation.
* ffi: functions for type-system-driven buffer coding.Kaz Kylheku2017-05-042-0/+66
| | | | | | | | | | * ffi.c (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out): New functions. (ffi_init): ffi-put-into, ffi-put, ffi-in, ffi-get, ffi-out: intrinsics registered. * ffi.h (ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out): Declared.
* itypes: fix wrong error messages.Kaz Kylheku2017-05-041-5/+5
| | | | | * itypes.c (c_u8, c_u16, c_u32, c_u64, c_uint): Fix messages referring to signed version of type.
* length: support buffer objects.Kaz Kylheku2017-05-041-0/+2
| | | | * lib.c (length): Handle BUF case via length_buf.
* Disallow negative bits in two logical operations.Kaz Kylheku2017-05-041-0/+12
| | | | | * arith.c (comp_trunc, logtrunc): Check for a negative bits value and throw.
* Detect negative length in string, vec construction.Kaz Kylheku2017-05-041-3/+16
| | | | | * lib.c (mkstring, mkustring, vector, vec_set_length): Reject negative length.
* ffi: reject negative buf size.Kaz Kylheku2017-05-041-0/+5
| | | | | * ffi.c (ffi_type_compile): Check for a negative buffer size and throw.
* ffi: check array dimensions.Kaz Kylheku2017-05-041-1/+11
| | | | | | * ffi.c (ffi_type_compile): Throw error if the dimension is negative in any array operator, or also if it is zero in a zarray operator.
* Eliminate double strlen in utf8 string conversion.Kaz Kylheku2017-05-041-2/+3
| | | | | | * utf8.c (utf8_dup_from): Eliminate double call to utf8_from wrapper, which calls strlen. Call the lower level utf8_from_buf directly.
* ffi: map (array n bchar) to Lisp string.Kaz Kylheku2017-05-043-0/+36
| | | | | | | | | | * ffi.c (struct txr_ffi_type): New bitfield flag, bchar_conv. (ffi_array_in, ffi_array_get): Handle bchar_conv. (ffi_type_compile): Set bchar_conv flag for array of bchar. * lib.c (string_8bit_size): New function. * lib.h (string_8bit_size): Declared.
* ffi: bugfix: zarray put accessing last element.Kaz Kylheku2017-05-041-7/+11
| | | | | | | | | | | | | | | | | A zarray of length N is requiring the Lisp vector to be of length N. * ffi.c (ffi_array_put): Reorder logic in the loop so that when we are putting out the terminating null element of a zarray, we do not access the corresponding element of the Lisp vector. Thus if the zarray is N elements wide, the Lisp vector need only be at least N-1 elements wide, not N. (ffi_array_in): Copy the null element of a zarray to the vector only if the vector object at least N elements. If the vector is nil so that we have to construct one, construct a vector of N-1 for a zarray. (ffi_array_get): For a zarray, construct a vector of N-1 elements. Do not even fetch the null.
* ffi: new bstr type.Kaz Kylheku2017-05-044-2/+62
| | | | | | | | | | | | | | | | | | The bstr type is like str, but doesn't perform UTF-8 conversion. The C data is assumed to be null terminated byte strings representing code points U+0000 through U+00FF. * ffi.c (bstr_s, bstr_d_s): New symbol variables. (ffi_bstr_put, ffi_bstr_get, ffi_bstr_d_get): New static functions. (ffi_init_types): Register bstr and bstr-d types. (ffi_init): Initialize bstr_s and bstr_d_s. * ffi.h (bstr_s, bstr_d_s): Declared. * lib.c (chk_strdup_8bit, string_8bit): New function. * lib.h (chk_strdup_8bit, string_8bit): Declared.
* ffi: implement bchar type.Kaz Kylheku2017-05-042-2/+11
| | | | | | | | | | | | bchar is like uchar, except that in the decode direction, it produces character objects rather than integers. * ffi.c (bchar_s): New symbol variable. (ffi_bchar_get): New static function. (ffi_init_types): Register bchar type. (ffi_init): Initialize bchar_s. * ffi.h (bchar_s): Declared.
* ffi: remove redundant function.Kaz Kylheku2017-05-041-14/+1
| | | | | | * ffi.c (ffi_str_d_put): Function removed. It is identical to ffi_str_put. (ffi_init_types): Use ffi_str_put for the str-d type.
* ffi: map FFI char type to character.Kaz Kylheku2017-05-041-1/+1
| | | | | | * ffi.c (ffi_char_get): Get a char object as a Lisp character, rather than number. Users who want a byte to convert to a an integer can use one of the types int8 or uint8 instead.
* bugfix: tostringp not behaving right for floats.Kaz Kylheku2017-05-044-10/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | The obj printer is ignoring the pretty flag when rendering floating-point numbers, and just formatting them using *print-flo-format*. To address this issue, we introduce an additional *pprint-flo-format* variable. * lib.c (obj_print_impl): In the FLNUM case, use either the value of *print-flo-format* or *pprint-flo-format* based on the value of the pretty flag. * stream.c (pprint_flo_format_s): New symbol variable. (stream_init): Initialize pprint_flo_format_s with interned symbol *pprint-flo-format* and register this as a special variable. * stream.c (pprint_flo_format_s): Declared. * txr.1: Documented *pprint-flo-format*. Also put in a note in the description of the various print functions that the equivalences based on ~s and ~a only apply to floats when the special variables have their original values.
* doc: clarify when exit points are torn down.Kaz Kylheku2017-05-041-0/+11
| | | | | | * txr.1: Adding a paragraph under unwind-protect clarifying that exit points are removed during unwinding, not during the search for an exit point.
* structs: check existence of type in new and lnew.Kaz Kylheku2017-05-041-9/+23
| | | | | | | | | | | | | | | | | | | | | This achieves two objectives. The obvious one is that we get a diagnostic for new expressions that name a nonexistent type, due to a typo, before those expressions are executed. However, this also fixes an annoying issue: spurious warnings about nonexistent slots, related to structs which have not yet been autoloaded. A test case for this is an expression like (let ((b (new list-builder))) b.(add 42)). Because list-builder is auto-loaded, the add slot doesn't exist. But (new list-builder) doesn't trigger that auto-load; so the deferred warning about the nonexistent slot isn't suppressed. With this change, the existence check in (new list-builder) will trigger the auto-load for the module which defines list-builder, causing the add slot to exist before the b.(add 42) expression is visited by the expander. * share/txr/stdlib/struct.tl (sys:check-struct): New function. (new, lnew): Issue warning if the type doesn't exist.
* dlopen: add error reporting via dlerror()Kaz Kylheku2017-05-031-9/+22
| | | | | | | | | | * sysif.c (dlopen_wrap): Call dlerror() to clear the error string. Then if the call returns null, call dlerror() again and use the string in the exception if available. (dlsym_error): New static function. (dlsym_checked, dlvsym_checked): Clear error string by calling dlerror(). Afer the call, if the pointer is null call dlsym_error to report.
* dlopen: allow nil name and default both args.Kaz Kylheku2017-05-031-4/+5
| | | | | | | | | * sysif.c (dlopen_wrap): Allow the name to be null or missing, in which case a null pointer is passed to dlopen to access the program image itself. Default the flags argument to RTLD_LAZY. (sysif_init): Re-regiser dlopen intrinsic such that both arguments are optional.
* ffi: new ptr-out-s type.Kaz Kylheku2017-05-032-2/+22
| | | | | | | | | | | | | | | | | | One more ptr type is useful. This type is for objects returned via pointers embedded in arrays or structures, whereby the callee establishes both the pointer and the data. This is similar to ptr-out-d; the difference is that the data has an indefinite lifetime ("s" denotes "static") and so the pointer is not freed after the call takes place and the data is extracted into Lisp objects. * ffi.c (ptr_out_s_s): New symbol variable. (ffi_ptr_out_s_in): New function. (ffi_type_compile): Handle new ptr_out_s_s. (ffi_init): Initialize ptr_out_s. * ffi.h (ptr_out_s_s): Declared.