summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* gc: remove #if 0 and #if 1.Kaz Kylheku2019-08-121-8/+0
| | | | | * gc.c (mark_obj): Remove material excluded by #if 1. (gc): Eliminate #if 0 block.
* @(collect): don't default vars if all required missing.Kaz Kylheku2019-08-122-60/+99
| | | | | | | | | | | | | | | | | | | | | | | | | The @(collect) directive disallows the situation when there are required vars, but some are missing (not bound by the collect body). However, the special case is allowed when none of the required variables are bound; that doesn't trigger the exception. There is a poor specification in this area: the issue is that when there are optional variables, and all variables are missing (optional and required), the optional ones are still bound to their default values. Thus, the situations is half-baked: some of the :vars are bound and some are not. This violates the all-or-nothing principle of :vars. This patch addresses the poor specification: if all variables are missing, then the optional variables are not bound to their defaults. * match.c (h_collect, h_coll): Detect the situation when at least one variable is required, and all optional variables are defaulted. In this case, don't propagate any bindings to the collected lists. * txr.1: Doc updated.
* reverse: bugfix: garbage object in error message.Kaz Kylheku2019-08-091-1/+1
| | | | | * lib.c (reverse): pointer to the C function in is being used as a value; the correct expression is seq_in.
* base-name: optionally remove suffix.Kaz Kylheku2019-08-093-5/+20
| | | | | | | | | | | | | | | | The base-name function now takes a second argument which is optional, specifying a suffix to be removed. The behavior is similar to that of the second argument of the POSIX basename command. * stream.c (base_name): Second argument added. If present, the returned value is adjusted by trimming the suffix, unless that would cause an empty string to be returned. (stream_init): Update registration of base-name intrinsic. * stream.h (base_name): Declaration updated. * txr.1: New base-name parameter documented.
* compiler: inline-lambda: optimize constant apply list.Kaz Kylheku2019-08-091-65/+75
| | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (comp-inline-lambda): Pass nil to new argument of lambda-apply-transform, indicating top-level call. (lambda-apply-transform): Takes new argument indicating whether it's a recursive call. If the apply list expression is constant, then it is evaluated and treated as a list of arguments which are then turned into quoted constants individually and passed as fixed args in a recursive call. This eliminates the generation of code dealing with run-time evaluation and destructuring of the apply arguments.
* compiler: inline-lambda: optimize generated let.Kaz Kylheku2019-08-081-3/+8
| | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): We conditionally generate the outer let as an alet, if there are no shadowing issues. The shadowing test is very conservative: the intersection between the argument expressions and the lambda symbols must be empty. Also, we move the gensym for the apply list expression into the let*, because we need a real storage location that we can pop.
* pop: improve expansion.Kaz Kylheku2019-08-081-1/+1
| | | | | | * share/txr/stdlib/place.tl (pop): Use alet for binding the temporary rather than let, so that if (,getter) expands to a symbol, it will disappear.
* compiler: bugfix: eval order in inline lambda.Kaz Kylheku2019-08-071-52/+54
| | | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): The expander fails to observe left-to-right evaluation because if the trailing argument form is present, it is evaluated first, even though it is the last argument. Also, the argument evaluations are wrongly interleaved among the default expressions for optional arguments; they must be evaluated firt. We fix all this by allocating gensyms for all of the fixed argument forms, and binding these via an extra let wrapped around the output let* form. When generating the let* we refer to the gensyms instead of the original fixed arguments. This extra let needs optimizing, but it can't just be converted to an alet because of scoping issues.
* compiler: bugfix: scoping issue in inline lambda.Kaz Kylheku2019-08-071-1/+1
| | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): The gensym for binding the trailing argument expression must be bound before any of the parameters, otherwise the expression is exposed to the scope of the parameters that have been emitted so far. We use add* to put it at the front.
* expander: bugfix: spurious lambda form warning.Kaz Kylheku2019-08-071-5/+5
| | | | | | | | | | * eval.c (do_expand): In the expansion logic for function calls, after we have done the dot-to-apply transform, we must thereafter consistently refer to the new front element of the form insym, and not the original element sym. The first element may be a lambda form moved into the second position by dot-to-apply. We then falsely warn about that being in the operator position. Test case: ((lambda ()) . 3).
* compiler: inline lambda: incomplete opt param support.Kaz Kylheku2019-08-071-9/+20
| | | | | | | | | | | | | | The compilation of lambdas that are immediately called or applied is missing the support for the Boolean parameters that indicate whether optional arguments are present. * share/txr/stdlib/compiler.tl (lambda-apply-transform): Check whether the opt parameter items from the fun-param-parser object have a third element, the indicator variable, and emit the binding for it. This has to be done in all three cases: optional parameter statically present, statically missing, and dynamically determined from run-time apply list of unknown length.
* @(collect)/@(coll): streamline list accumulation code.Kaz Kylheku2019-08-071-10/+17
| | | | | | | | | * match.c (h_coll, v_collect): Revising the code for accumulating items into lists. Duplicate assoc lookups via assoc and acons_new are eliminated in favor of doing rplacd or acons. We don't call assoc to look up a binding if have_vars is false. car(binding) is called once and captured in the local vaiable sym.
* lib: don't GC-protect two non-heap objects.Kaz Kylheku2019-08-061-1/+1
| | | | | | | | | | * lib.c (obj_init): The null string literal and "nil" do not require gc protection; they cannot be reclaimed by the garbage collector, which ignores them. Don't waste two slots in the prot_stack on them. This is a remnant from ancient TXR; these variables were protected already in Version 11 from September 2009. At that time, there were no built-in string literal objects; these two objects were heap-allocated.
* compiler: remove one-argument or.Kaz Kylheku2019-08-061-1/+1
| | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): Remove useless one-argument use of or operator.
* Version 222.txr-222Kaz Kylheku2019-07-305-181/+213
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* ffi: bugfix: kind enum in wrong argument positions.Kaz Kylheku2019-07-301-10/+14
| | | | | | | | | | | | * ffi.c (ffi_type_compile, ffi_init_types): Fixed a number of instances of make_ffi_type_builtin being passed the type kind as the fourth rather than the third argument. The strange fluke here is that FFI_KIND_NUM is 1, so this actually made no difference in all the case in ffi_init_types! However in ffi_type_compile, it would have set the type of cptr-s to struct, and its size to 3. Anyway, we were saved from a regression by the good pre-release habit of compiling as C++!
* doc: update FFI struct/union description.Kaz Kylheku2019-07-301-6/+152
| | | | | | | * txr.1: Document existing gensym behavior of nil struct/union tags. Document new rules regarding structs/unions that have no members, redefinitions of complete and incomplete types, and semantics of self-reference.
* doc: fix wrapping save-exe exampleKaz Kylheku2019-07-291-1/+2
| | | | | | * txr.1: Use backslash escape in the save-exe example to break up long string literal, so it won't be wrapped by man at 80 columns.
* FFI: bugfix: GC-correctness of assignments.Kaz Kylheku2019-07-281-0/+11
| | | | | | | | | | | Recent work has introduced wrong-way assignments. When we compile the slots after we have created the type object, the slot types may be in a newer generation than the type object. If we are reusing an old type object, it can be older than the syntax, or the Lisp object being stored in it. * ffi.c (make_ffi_type_struct, make_ffi_type_union): add some setcheck calls to handle anti-generational assignments.
* FFI: bugfix: properly re-use existing struct type.Kaz Kylheku2019-07-281-2/+6
| | | | | | | | | This is a bug in the prior commit's change. * ffi.c (make_ffi_type_struct, make_ffi_type_union): When using an existing type, do not call cobj to make a new Lisp object for the type structure; pull the existing one out from tft->self.
* FFI: self-referential structs.Kaz Kylheku2019-07-281-90/+200
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this commit, FFI a struct definitions can contain references to the struct type being defined. It becomes possible to pass a (non-circular) linked list of structures to and from C foreign function. * ffi.c (ffi_kind_t): New enum. We need some tag in the txr_ffi_type struct to indicate type. (ffi_struct_tag_hash): New static variable. (struct txr_ffi_type): New members: kind and flexible. (ffi_struct_in, ffi_struct_get): Use the new flexible bit as an indicator that the struct has a flexible member, rather than the incomplete bit. (make_ffi_type_builtin): Take new argument indicating type kind, and store it in the kind member. (make_ffi_type_pointer): Initialize kind field. (ffi_memb_compile): New static function. (make_ffi_type_struct): No longer receives the list of slot names and their compiled types as arguments. The compiling is done in this function on-the-fly as the slots are initialized, using the ffi_memb_compile function helper. If a same-named struct/union type already exists, this is passed in; the function will replace that type by freeing and reallocating the member vector, clearing the existing struct type to all zero and re-initializing it from scratch. The new kind field is initialized. The incomplete flag is set initially and then updated at the end, so during the processing of the member types, the struct type is considered incomplete. If a struct has no members, it is considered incomplete now. It is flexible only if it ends in a flexible array. The struct type is added to ffi_struct_tag_hash, keyed on its tag. (make_ffi_type_union): Similar changes as in make_ffi_type_struct. (ffi_membs_compile): Function removed. (ffi_type_compile): Change to struct compilation logic. An empty struct definition now avoids creating a Lisp struct type. If a FFI struct type already exists, that one is returned, otherwise an empty one (considered incomplete) is created. A struct definition with members replaces an existing one. The new make_ffi_type_struct interface is used which simplifies things here, since we just pass down the syntax and the existing type, without having to compile the member types. Not a big change for unions: just use the new make_ffi_type_union interface, which requires the existing type, and just the syntax now, rather than compiled slots. For varrays, set the type kind to FFI_KIND_ARRAY, overriding the FFI_KIND_PTR type that is already there due to varrays being implemented as pointers. Perhaps varray should have its own kind, but for now this approach serves fine. For buffer types, set the kind to FFI_KIND_PTR, and for the bitfields, set it to FFI_KIND_NUM. (ffi_init_types): Pass an appropriately-valued kind argument in ach call to the make_ffi_type_builtin constructor. (ffi_init): GC-protect the ffi_struct_tag_hash variable, and initialize it.
* FFI: bugfix: pointer "in" ops must map null to nil.Kaz Kylheku2019-07-271-0/+8
| | | | | | | | | * ffi.c (ffi_ptr_in_in, ffi_ptr_in_d_in, ffi_ptr_out_in, ffi_ptr_out_s_in): If the memory location which holds the pointer to the C object is null, then just return nil. If we don't do this, we then crash trying to extract the object from a null pointer via the recursive tgtft->in or tgtft->get call.
* parser: give start of a bad forms even if line 1.Kaz Kylheku2019-07-261-1/+4
| | | | | | | * parser.y (parse): Emit the "while parsing form starting at line N" even if N is 1. I think the idea here was supposed to be to suppress this additional message for parses that don't advance from the starting line, so I'm fixing it that way.
* FFI: elemtype as type operator, not just macro.Kaz Kylheku2019-07-262-5/+48
| | | | | | | | * ffi.c (elemtype_s): New symbol variable. (ffi_type_compile): Handle elemtype. (ffi_init): Initialize elemtype_s. * txr.1: Document elemtype.
* FFI: document: elemsize and elemtype work on enums.Kaz Kylheku2019-07-262-10/+16
| | | | | | | | * ffi.c (ffi_elemsize, ffi_elemtype): Fix error messages to include enum among possible argument types. * txr.1: Extend documentation for ffi-elemsize and ffi-elemtype to include base integer type of enumerations.
* FFI: allow member type reference using referencing dot.Kaz Kylheku2019-07-262-0/+69
| | | | | | * ffi.c (ffi_type_compile): New case handling qref_s symbol. * txr.1: Documented.
* Version 221.txr-221Kaz Kylheku2019-07-236-647/+678
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: Latin overhaul.Kaz Kylheku2019-07-221-16/+27
| | | | | | * txr.1: Ensure all instances of vice versa are spellled consistently without a dash and italicized. Italicize every et cetera and one a priori.
* doc: remove "of course".Kaz Kylheku2019-07-221-47/+42
| | | | * txr.1: All instances of the hedge phrase "of course" are removed.
* doc: improvements tied to "very".Kaz Kylheku2019-07-221-31/+34
| | | | | | | * txr.1: A smattering of wording improvements motivated by a search for the fluff adjective "very". Most instances of "very" are deleted, and in some cases the surrounding wording is improved.
* doc: @(merge) improvement.Kaz Kylheku2019-07-221-6/+6
| | | | | * txr.1: Description of @(merge) is improved by eliminating fluff wording.
* doc: eliminate example uses of obsolete txr-path.Kaz Kylheku2019-07-221-3/+4
| | | | | | | | | * txr.1: In the --args example, don't use txr-path, but txr-exe-path. Also, path-cat instead of plain string catenation. The example for save-exe was additionally doing something wrong: taking the dir-name of txr-path, which would calculate the parent of the executable directory. This example is harmonized with the --args one.
* doc: wording under dir-name.Kaz Kylheku2019-07-221-1/+1
| | | | | * txr.1: the term "raw directory path" has not been introduced; it is a typo for "raw directory prefix".
* txr: regression: lack of file name in error messages.Kaz Kylheku2019-07-226-12/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was broken on April 21, 2019 in commit 2e36e0feae8d1dd75c8410b365d7dc33b30ce66b (April 21, 2019) which changed parse_once in such a way that the name being passed down was no longer stored in the parser. The ensure_parser function being relied upon doesn't take on the responsibility of propagating the name from the stream to the parser, so the parser ends up with a nil name. Let's just smooth this over by having ensure_parser take a name parameter. If ensure_parser creates a new parser, it puts in the name. If the name is nil, then it is taken from the stream. * eval.c (load): Pass name to ensure_parser. * match.c (v_load): Likewise. * parser.c (parser): Take name parameter, and plant into newly constructed parser. (ensure_parser): Take name parameter. When creating a parser, give it that name, or if name is specified as nil, then give it the name taken from the stream. (parser_set_lineno): Pass nil name to ensure_parser. (lisp_parse_impl, read_file_common): Pass name to ensure_parser. * parser.h (parser, ensure_parser): Declarations updated. * parser.y (parse_once): Pass name to ensure_parser. * txr.c (txr_main): Pass spec_file_str to ensure_parser.
* ffi: bugfix: flexible struct get not working right.Kaz Kylheku2019-07-221-7/+13
| | | | | | | | | | The get operation must use the flexible array's in virtual function, because incomplete arrays have a no-op get function. * ffi.c (ffi_flex_struct_in): return the value of the slot. (ffi_struct_get): When processing the terminating slot of a flexible struct, we invoke its in-semantics, using the updated slot value as the object.
* ffi: support flexible structures.Kaz Kylheku2019-07-203-66/+218
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for working with foreign structures which use the C99 "flexible array member", or possibly the old "C struct hack". Some improvements are made in the FFI code the area of incomplete types and bitfields. * ffi.c (struct txr_ffi_type): New flag members incomplete and bitfield. (ffi_varray_dynsize): Check incomplete type flag rather than for zero size. (ffi_flex_dynsize, ffi_flex_alloc, ffi_flex_struct_in): New static functions. (ffi_struct_in): Call ffi_flex_struct_in when doing by-value semantics on a flexible structure, just before converting last member. This checks for the length method, calls it, and adjusts the last member object as documented. (ffi_struct_get): Likewise. (bitfield_syntax_p): Static function removed; there is a flag for this now in the type, so no need to parse its syntax. (make_ffi_type_pointer): Test bitfield flag rather than using bitfield_syntax_p. (make_ffi_type_struct): Take new argument indicating that the struct is flexible. Wire in appropriate virtual functions based on this flag, and set the type's incomplete flag accordingly. Check bitfield flag rather than using bitfield_syntax_p for detecting bitfield members. Calculate the size of flexible struct differently: it is the offset of the last member. (make_ffi_type_union): Test bitfield flag rather than using bitfield_syntax_p. (ffi_struct_compile): Renamed to ffi_membs_compile. (ffi_membs_compile): New pointer parameter for returning an indication whether the member list specifies a flexible struct. Test the incomplete flag of a member type rather than size being zero. (ffi_type_compile): Follow rename of ffi_struct_compile to ffi_membs_compile. Pass down the flag obtained from ffi_membs_compile into make_ffi_type_struct so that a flexible struct type is created when necessary. Disallow arrays of bitfields. Set bitfield flag on bitfield types. (ffi_init_types): Set incomplete flag on void type. (ffi_make_call_desc): Test for incomplete and bitfield types using new flags. (ffi_typedef, ffi_size, ffi_alignof): Test for bitfield type using new bitfield flag. (carray_elem_check): New static function. (carray_buf, carray_pun, carray_unum, carray_num): Use new carray_elem_check to check for bad array element type. This uses the incomplete flag rather than checking for zero size, and also disallows bitfields. * lib.h (length_s): Declared. * txr.1: Flexible structs documented in new section. Also section on incomplete types. Description of sizeof operator gives more detaild about incomplete types including flexible structs.
* doc: document ffi-out.Kaz Kylheku2019-07-181-0/+53
| | | | * txr.1: Add missing documentation for ffi-out.
* doc: ffi-in: wrong direction word.Kaz Kylheku2019-07-181-1/+1
| | | | * txr.1: ffi-in is a decoding not an encoding action.
* doc: ffi-in offset argument description missing.Kaz Kylheku2019-07-181-1/+9
| | | | * txr.1: Document the offset argument of the ffi-in operation.
* relate: optimize with hashes.Kaz Kylheku2019-07-172-3/+32
| | | | | | | | | | | * lib.c (do_relate_hash, do_relate_hash_dfl): New static functions. (relate): If the number of keys and values is the same, and there are more than ten, then use hashing. If the default value is specified, and it is nil, then a hash table can be returned directly, instead of a function. * txr.1: Note added that relate may return a hash.
* New function: hash-zip.Kaz Kylheku2019-07-173-0/+48
| | | | | | | | | * hash.c (hash_zip): New function. (hash_init): hash-zip intrinsic registered. * hash.h (hash_zip): Declared. * txr.1: Documented.
* ffi: two-argument form of sizeof.Kaz Kylheku2019-07-113-7/+42
| | | | | | | | | | | | | | | If sizeof is given an extra argument (an expression which evaluates to an object), it can calculate the dynamic size of the FFI type in relation to representing that object. * ffi.c (dyn_size): New static function. (ffi_init): Register sys:dyn-size intrinsic. * share/txr/stdlib/ffi.tl (sizeof): Support additional argument, avoiding run-time compilation of the type expression with the help of load-time. * txr.1: Update documentation for sizeof macro.
* ffi: handle variable length types in buffer ops.Kaz Kylheku2019-07-112-7/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The motivating bug here is that (ffi-put #(1 2 3 5) (ffi (array int))) perpetrates a buffer overrun. The size of (array int) is zero, and so a zero-length buffer is allocated. But then an array of five ints is stored. This is made to work correctly: allocating a buffer large enough. A new virtual function is introduced into the txr_ffi_type structure to calculate a type's dynamic size, from a prototype Lisp object. * ffi.c (struct txr_ffi_type): New function pointer member, dynsize. (ffi_fixed_dynsize, ffi_varray_dynsize): New static functions. (make_ffi_type_builtin, make_ffi_type_pointer, make_ffi_type_struct, make_ffi_type_union, make_ffi_type_array): Initialize new dynsize member of type structure with pointer to ffi_fixed_dynsize. (ffi_type_compile): Initialize the dynsize pointer of variable array types to ffi_varray_dynsize. (ffi_put_into, ffi_put, ffi_in, ffi_out): Use dynsize to calculate the real size required to store or extract the given object. * txr.1: Update doc for ffi-put, ffi-put-into and ffi-in. Looks like we are missing ffi-out; it is not documented!
* chk_calloc: use unsigned arithmetic.Kaz Kylheku2019-07-111-1/+1
| | | | | | | * lib.c (chk_calloc): Use unsigned arithmetic to figure out the total, which is only used for incrementing the malloc_bytes counter. The unsigned arithmetic is performed in the same type as that counter.
* Version 220.txr-220Kaz Kylheku2019-07-086-987/+1023
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* crc32: comment header formatting problem.Kaz Kylheku2019-07-082-2/+6
| | | | * crc32.c, crc32.h: Repair accidentally joined lines.
* compile-file: elide top-level atoms.Kaz Kylheku2019-07-071-1/+1
| | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): If a top-level form is compiled that is an atom, don't emit the translation, since it has no effect (beyond interning the symbol).
* compile-file: don't ignore atomic forms.Kaz Kylheku2019-07-071-22/+22
| | | | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): do not silently ignore forms that (after macroexpansion) are atoms; treat them like any other forms. This is mostly useless, but if unbound variables are used as top-level forms, it is diagnosed, and keeps the file compilation behavior closer to interpreted semantics.
* doc: op: incorrect example.Kaz Kylheku2019-07-061-5/+14
| | | | | | * txr.1: Switch op example to ap and move under description of ap, which needs an example anyway. Add new examples for op. Reported by user vapnik spaknik.
* replace: deal with overlapping.Kaz Kylheku2019-07-053-4/+16
| | | | | | | | | | | | | * buf.c (replace_buf): In the same-type case, use memmove rather than memcpy in case the objects overlap, so we don't invoke C undefined behavior. * lib.c (replace_str, replace_vec): Likewise. * txr.1: Specify that if the replacement sequence overlaps with the target range of the destination sequence, or with any portion that has to be relocated if range changes size, then the behavior is unspecified.