summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
...
* ffi: conform to GCC's bitfield layout algorithm.Kaz Kylheku2017-06-071-44/+112
| | | | | | | | | | | 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.
* ffi: support bitfields on types narrower than int.Kaz Kylheku2017-06-061-6/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* buffers: improve put-buf and fill-buf.Kaz Kylheku2017-06-051-21/+39
| | | | | | | | | | | | | | | | | | | | * stream.h (struct strm_ops): put_buf and fill_buf function pointers get third argument to indicate starting position of read and write. (put_buf, fill_buf): Declarations updated. * stream.c (unimpl_put_buf, unimpl_fill_buf): Third argument added. (generic_put_buf, generic_fill_buf, stdio_put_buf, stdio_fill_buf): Implement position argument. (delegate_put_buf, delegate_fill_buf): Take third argument, pass it down. (put_buf, fill_buf): New position argument in second position. Defaulted to zero. Passed down. (stream_init): Updated registration of put-buf and fill-buf. * txr.1: Updated documentation.
* buffers: doc: put-buf, fill-buf.Kaz Kylheku2017-06-051-0/+78
| | | | * txr.1: Documented put-buf and fill-buf.
* ffi: doc: endian typesKaz Kylheku2017-06-051-0/+69
| | | | * txr.1: Documented the endian types.
* ffi: doc: align operator.Kaz Kylheku2017-06-051-0/+45
| | | | * txr.1: Documented align type operator.
* ffi: use expressions for bit field width also.Kaz Kylheku2017-06-031-4/+5
| | | | | | | * ffi.c (ffi_type_compile): Evaluate width argument of sbit and ubit type as as expression. * txr.1: Documented.
* ffi: evaluate expressions in type notation.Kaz Kylheku2017-06-021-10/+29
| | | | | | | | | | | | | | | | | | | | | | | | | Places where an integer constant was previously allowed now allow an expression. The way enum syntax works is now different. A temporary lexical environment is created, and each enumeration is bound in that environment. The value expressions are evaluated in that environment. The decision to allow keyword symbols to be enumeration contants is retracted. * eval.h (special_s): Declared. * ffi.c (ffi_eval_expr): New static function. (make_ffi_type_enum): Enums are introduced into a temporary environment, in which the value expressions are evaluated. By this means, the expressions can refer can refer to previous enums and do arbitrary computation. Also, we drop the requirement that enums can be keyword symbols. (ffi_type_compile): Array dimension and buf size are evaluated as expresions. Array and buffer syntax is transformed by substitution of the evaluated size. * txr.1: Documented use of expressions in FFI type notation.
* ffi: functions and macros for basic type properties.Kaz Kylheku2017-06-021-10/+252
| | | | | | | | | | | | | | | | | | * ffi.c (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): New functions. (ffi_init): Registered intrinsics ffi-alignof, ffi-offsetof, ffi-arraysize, ffi-elemsize, ffi-elemtype. * ffi.h (ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype): Declared. * lisplib.c (ffi_set_entries): New autoload entries alignof, offsetof, arraysize, elemsize, elemtype. * share/txr/stdlib/ffi.tl (alignof, offsetof, arraysize, elemsize, elemtype): New macros. * txr.1: Documented new functions and macros.
* mkstring char argument is optional.Kaz Kylheku2017-06-011-1/+5
| | | | | | | | | * eval.c (eval_init): Update registration of mkstring intrinsic to make second argument optional. * lib.c (mkstring): Default second argument to space. * txr.1: Documentation of mkstring updated.
* ffi: new feature: enums.Kaz Kylheku2017-05-311-0/+60
| | | | | | | | | | | | | | | | * ffi.c (enum_s): New symbol variable. (struct txr_ffi_type): New member, sym_num, num_sym. (ffi_enum_type_mark): New static function. (ffi_type_enum_ops): New static structure. (ffi_enum_put, ffi_enum_get, ffi_enum_rput, ffi_enum_rget): New static functions. (make_ffi_type_enum): New static function. (ffi_type_compile): Extend with enum syntax. (ffi_init): Initialize enum_s with new interned symbol. * ffi.c (enum_s): Declared. * txr.1: Documented.
* Refactoring hash bang support; hash bang null hack.Kaz Kylheku2017-05-301-4/+182
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hash bang mechanism is handled in one place, and disentangled from all parsing logic. It is also endowed with special powers. * eval.c (load): Pass one less argument to read_eval_stream. * match.c (v_load): Likewise. * parser.c (read_eval_stream): hash_bang_support Boolean argument removed. Hash bang logic removed. (load_rcfile): Pass only two arguments to read_eval_stream. * parser.h (read_eval_stream): Declaration updated. * txr.c (remove_hash_bang_line): Function removed. (check_hash_bang): New static function. (txr_main): Recognize the script file name while still inside the argument processing loop. Open the file, and check for a hash bang line, doing the special processing which can generate more arguments from material after a null byte in the hash bang line. The parse_stream variable is now initialized to nil and doubles as a Boolean indicating whether a stream has been opened. After the loop, we remove the script file from the arguments, if we have an open stream and the spec_file_str matches. read_eval_stream is called only with two arguments. * txr.1: Revised existing documentation and described new features.
* command line: --eargs semantics change.Kaz Kylheku2017-05-301-10/+26
| | | | | | | | | | | | | | | | | The --eargs mechanism won't perform a blind substring replacement of {} with the following argument. Only arguments which match {} exactly are replaced. * eval.c (retf): Static function becomes extern. * eval.h (retf): Declared. * txr.c (txr_main): Replace the filtering logic on the split eargs argument list to just look for items equal to the string "{}" and replace with the following argument. * txr.1: Updated --eargs documentation.
* New variable: *args-eff*.Kaz Kylheku2017-05-301-7/+33
| | | | | | | | | | | | * txr.c (txr_main): As arguments are processed, collect them into a list called the effective arg list, which is eventually visible as the *args-eff* variable. This is the argument list which reflects the expansions that have been applied by --args or --eargs. Those two options take special care to remove themselves from that list. * txr.1: Documented *args-eff*.
* doc: grammar in ffi.Kaz Kylheku2017-05-261-6/+7
| | | | * txr.1: Smattering of grammar fixes in ffi section.
* doc: wrong word under ffi buf description.Kaz Kylheku2017-05-261-1/+1
| | | | * txr.1: buf and buf-d are "types" not "parts".
* ffi: bitfield support.Kaz Kylheku2017-05-251-0/+129
| | | | | | | | | | | | | | | | | | | | | | | * ffi.c (sbit_s, ubit_s): New symbol variables. (struct txr_ffi_type): New members, shift and mask. (ffi_sbit_put, ffi_sbit_get, ffi_ubit_put, ffi_ubit_get, bitfield_syntax_p): New static functions. (make_ffi_type_pointer): Disallow pointers to bitfields. (make_ffi_type_struct): Process bitfield members and set up shifts and masks accordingly. Recently introduced bug fixed here at the same time: the alignment calculation for each member must be done top-of-loop. (ffi_struct_compile): Exclude bitfields from the check against members with zero type. Compile the bitfield syntax. (ffi_typedef): Do not allow typedefs of bitfield type. Not only doesn't this make sense, but bitfield types are destructively modified in make_ffi_type_struct: they are imbued with a mask and offset tied to their position in a particular struct. * ffi.h (sbit_s, ubit_s): Delared. * txr.1: Documented bitfields.
* doc: clean up description of bident and lident.Kaz Kylheku2017-05-241-7/+20
| | | | | | | | * txr.1: Fix false, contradictory text claiming that an underscore may be part of a bident but not sident. (Reported by user "death" on Reddit). Add clarifying text explaining that only the slash character may be in a lident but not bident, and improve some surrounding text.
* ffi: sanity check on object in ffi_val_get.Kaz Kylheku2017-05-241-0/+6
| | | | | | | | | | | | | | | | | * ffi.c (ffi_val_get): Throw an exception if the object doesn't appear valid. * gc.c (valid_object_p): New function. Invalid objects are those that are pointers, but either not into a heap, or else to a freed object or to an object that is marked by the garbage collector (should only be seen while GC is running). All others are valid. There can be false positives here: a value with the LIT tag is in fact a pointer, but we don't check whether that is valid. * gc.c (valid_object_p): Declared. * txr.1: Remarks added to documentation of FFI val type.
* doc: point out relationship between juxt and callf.Kaz Kylheku2017-05-241-0/+22
| | | | | * txr.1: Under callf, give equivalence to juxt. Also refer to callf from juxt.
* doc: C code formatting issue.Kaz Kylheku2017-05-231-2/+6
| | | | | * txr.1: typeset couple of example printf calls properly in discussion of variadic FFI call descriptors.
* ffi: val type.Kaz Kylheku2017-05-231-0/+18
| | | | | | | | | | | * ffi.c (val_s): New symbol variable. (ffi_val_put, ffi_val_get): New functions. (ffi_init_types): Register val type. (ffi_init): Initialize val_s. * ffi.h (val_s): Declared. * txr.1: Documented.
* Version 176.txr-176Kaz Kylheku2017-05-211-2/+2
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* Adding realpath function.Kaz Kylheku2017-05-211-0/+25
| | | | | | | | | * configure: New test for realpath. * sysif.c (realpath_wrap): New static function. (sysif_init): Registered realpath intrinsic. * txr.1: Documented.
* Adding base-name and dir-name functions.Kaz Kylheku2017-05-211-0/+79
| | | | | | | | | | | | | | | * stream.c (path_sep_chars): New global variable. (detect_path_separators): New static function. (base_name, dir_name): New functions. (stream_init): Call detect_path_separators. Register base-name and dir-name intrinsic functions, and path-sep-chars variable. * stream.h (path_sep_chars, base_name, dir_name): Declared. * txr.c (dirname): Static function removed. (sysroot_init): Use dir_name instead of dirname. * txr.1: Documented dir-name, base-name and path-sep-chars.
* doc: emphasize platform-independence of abs-path-p.Kaz Kylheku2017-05-211-0/+5
| | | | | | * txr.1: Adding text to abs-path-p description which emphasizes that the definition of absolute path it uses is platform-agnostic.
* ffi: new macro, deffi-var.Kaz Kylheku2017-05-201-0/+44
| | | | | | | | * lisplib.c (ffi_set_entries): Autload entry for "deffi-var". * share/txr/stdlib/ffi.tl (deffi-var): New macro. * txr.1: Documented.
* doc: reorder typedef and deffi-cb sections.Kaz Kylheku2017-05-201-21/+21
| | | | | * txr.1: typedef moved below deffi-cb, so it it is together with sizeof.
* ffi: overhaul ffi-call API and document it.Kaz Kylheku2017-05-201-0/+47
| | | | | | | | | | | | | | | * ffi.c (ffi_call_wrap): Take struct args * parameters rather than a list. Check that number of arguments matches required number from call desc. No need to build argument array any more; we just refer to the one in args. Also, the first two parameters are reversed for consistency with other functions. (ffi_init): Update registration of ffi-call to reflect type change. * ffi.h (ffi_call_wrap): Declaration updated. * txr.1: Documented ffi-call.
* ffi: turn carray-ref into accessor.Kaz Kylheku2017-05-201-1/+8
| | | | | | | | | | * lisplib.c (ffi_set_entries): Add carray-ref to list of autoload names. * share/txr/stdlib/ffi.tl (carray-ref, carray-refset): Registered function pair as a simple accessor. * txr.1: Updated carray-ref doc.
* ffi: variable length zarray needs in operation.Kaz Kylheku2017-05-201-1/+13
| | | | | | | | * ffi.c (ffi_varray_null_term_in): New static function. (ffi_type_compile): Wire in new function as in operation of variable length zarray. * txr.1: Documented.
* ffi: new carray-buf-sync function.Kaz Kylheku2017-05-201-0/+27
| | | | | | | | | * ffi.c (carray_buf_sync): New function. (ffi_init): carray-buf-sync intrinsic registered. * ffi.h (carray_buf_sync): Declared. * txr.1: Documented.
* ffi: new function, carray-cptr.Kaz Kylheku2017-05-191-0/+41
| | | | | | | | | * ffi.c (carray_cptr): New function. (ffi_init): Registered intrinsic. * ffi.h (carray_cptr): Declared. * txr.1: Documented.
* doc: update variable array desription.Kaz Kylheku2017-05-191-7/+26
| | | | | | | * txr.1: Fix misleading text which says that variable arrays correspond to pointers. They do not; they must be wrapped in expicit (ptr ...). Also documenting new get operation of variable zarray.
* awk: new feature: again operator.Kaz Kylheku2017-05-191-0/+25
| | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): Wrap a loop around around the two forms that split the record into fields and dispatch the main rule function. The loop repeats if the named block returns :awk-again. (sys:awk-mac-let): New local macro (again) which bails out of the :awk-rec block just like (next) does, but specifies :awk-again as the return value. * txr.1: Documented.
* doc: ffi carray type and carray objects documented.Kaz Kylheku2017-05-181-35/+556
| | | | * txr.1: Documented the total current state of carray.
* ffi: bugfix: broken buf in semantics, bad doc.Kaz Kylheku2017-05-181-20/+74
| | | | | | | | | | | | | * ffi.c (ffi_buf_in): The bug in this one is that if *loc has been mutated to a null pointer, we want to produce a nil, rather than to try to duplicate the buffer. (ffi_buf_d_in): The bug here is that *loc is always different from origptr, because origptr is from the original buffer object, whereas we placed a copy of it into *loc. The semantics is changed. We take ownership of whatever pointer is there. If it is null, then yield nil. * txr.1: buf and buf-d documentation revised.
* ffi: macro named ffi for type compiling shorthand.Kaz Kylheku2017-05-171-0/+15
| | | | | | | | | * lisplib.c (ffi_set_entries): Add "ffi" to autoload name list. * share/txr/stdlib/ffi.tl (ffi): New macro. * txr.1: Documented.
* ffi: typedef macro instead of deffi-type.Kaz Kylheku2017-05-171-8/+6
| | | | | | | | | | * share/txr/stdlib/ffi.tl (typedef): New macro. * lisplib.c (ffi_set_entries): Add typedef to autoload name list. * txr.1: Doc update. Remove mentions of deffi-type, though it continues to work.
* Version 175.txr-175Kaz Kylheku2017-05-151-2/+2
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* ffi: use dynamic allocation for wstr and wstr-d.Kaz Kylheku2017-05-131-26/+3
| | | | | | | | | | | | | | | | | | | The direct pointer use of the wstr type causes problems for callbacks. Plus allowing the foreign world to retain the pointers into string objects is inherenty unsafe. We can introduce an "unsafe wstr" type in a later release for efficiency. * ffi.c (ffi_wstr_in): New function. (ffi_wstr_put): Removed by ffi_wstr_d_put rename. (ffi_wstr_d_put): Renamed to ffi_wstr_put: both wstr and wstr-d strings have a dynamically-allocating put. (ffi_init_types): Give wstr type ffi_wstr_in handler. wstr-d type's registration switched to ffi_wstr_put, which is just ffi_wstr_d_put renamed. * txr.1: Memory management notes for wstr updated.
* ffi: support programmable abort return value.Kaz Kylheku2017-05-111-5/+27
| | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (stuct txr_ffi_closure): New member, abort_retval. (ffi_closure_mark_op): Mark the new member. (ffi_closure_dispatch_safe): Implement the abort_retval. If it is not nil, use put to place the value into the return buffer. There is a risk that this could also throw an exception, which is no longer protected: programer's problem. (ffi_make_closure): New abort_ret_in argument, which is defaulted and stored. (ffi_init): Update registration of ffi-make-closure to reflect new argument. * ffi.h (ffi_make_closure): Declaration updated. * share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): Add abort-retval parameter; insert into ffi-make-closure call. (deffi-cb): Take optional abort-retval expression; pass it down to the expander function. (deffi-cb-unsafe): Pass nil as abort-retval down to expander. * txr.1: Documented.
* ffi: a measure of safety for callbacks.Kaz Kylheku2017-05-111-5/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don't want, by default, for callbacks to capture delimited continuations across foreign code, or perpetrate non-local transfers across foreign code. Here, we take an approach similar for what was done in ftw_wrap. * ffi.c (s_exit_point): New global variable with internal linkage. (ffi_call_wrap): If s_exit_point isn't nil, then it means that the callback intercepted a nonlocal transfer and stored its exit point. We resume the transfer to that exit point instead of returning normally. (ffi_closure_dispatch_safe): New static function. (ffi_make_closure): Support a new argument which indicates whether to make a closure which uses ffi_closure_dispatch_safe, or ffi_closure_dispatch. (ffi_init): Update registration of ffi-make-closure intrinsic. * ffi.h (ffi_make_closure): Declaration updated. * share/txr/stdlib/ffi.tl (sys:deffi-cb-expander): New function. (deffi-cb): Macro internals replaced by call to new function. (deffi-cb-safe): New macro. * txr.1: Documentation of ffi-make-closure updated. New deffi-cb-unsafe macro documented.
* ffi: adjust semantics of zarray of characters.Kaz Kylheku2017-05-101-4/+26
| | | | | | | | | | | | | We want to be able to extract null-terminated UTF-8 strings from arrays, without trailing junk, yet retain the ability to extract the entire array including embedded nulls. The natural way is to use the array/zarray distinction. * ffi.c (ffi_array_in, ffi_array_get): Don't try to guess whether the array is null terminated; just rely on the null_term flag, and treat accordingly. * txr.1: Doc updated.
* 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.
* ffi: integers and chars may convert to C float.Kaz Kylheku2017-05-091-3/+3
| | | | | | | | | * 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
|