summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
...
* simplify toseq, reverse and nerverse.Kaz Kylheku2017-06-161-39/+28
| | | | | | * lib.c (toseq, reverse, nreverse): Classify the sequence with seq_info, and simplify the code by just dealing with the sequence kinds.
* New sequence classification system.Kaz Kylheku2017-06-161-0/+60
| | | | | | | | | | | | 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-161-4/+17
| | | | | | | | | | | | | | | | 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-161-0/+11
| | | | | | | | | | | * 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-151-0/+2
| | | | | | | | | | | | * 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.
* Follow up on C++ diagnostics.Kaz Kylheku2017-06-121-1/+1
| | | | | | | | | * 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.
* int-str: allow radix to be #\c for C conventions.Kaz Kylheku2017-06-121-18/+42
| | | | | | | | | * 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.
* 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-121-0/+12
| | | | | | | | | 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: new carray-replace function.Kaz Kylheku2017-06-111-0/+4
| | | | | | | | | | | | | | 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: handle sub operation in carray.Kaz Kylheku2017-06-111-0/+2
| | | | | | | | | | | | | | | | 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-111-0/+5
| | | | | | | | | | | | | | | | | | | | 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-111-0/+2
| | | | | | * lib.c (length): Handle COBJ of carray type. * txr.1: Documented.
* ffi: retain some functionality if libffi missing.Kaz Kylheku2017-06-101-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: 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.
* ffi: fix broken bchar array get.Kaz Kylheku2017-06-051-1/+2
| | | | | | | * lib.c (string_8bit_size): This function must allocate an extra wchar_t and null-terminate. That is the semantics expected by ffi_bchar_array_get which uses it, and of course string_own requires a null-terminated string.
* mkstring char argument is optional.Kaz Kylheku2017-06-011-1/+2
| | | | | | | | | * 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.
* Splitting cptr object into separate CPTR tag.Kaz Kylheku2017-05-151-7/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CPTR shares representation and a lot of implementation with COBJ. The COBJ class symbol is the CPTR type tag. There is no hierarchy among CPTR tags. The nil tag is used for a modicum of type looseness, so that we don't straitjacket ourselves too much into this tag-based typing scheme. All existing cptr objects are becoming CPTR, and all get a nil tag, except for dlopen library handles, and dlsym symbols, which are tagged as dlhandle and dlsym. The FFI framework will support tag-declared cptr's. This will help with safety. For instance, suppose an API has half a dozen different kinds of opaque handles. If they are all just cptr on the TXR Lisp side, it's easy to mix them up, passing the wrong one to the wrong C function. * lib.h (enum type): New enum member, CPTR. (cptr_print_op, cptr_typed, cptrp, cptr_type, cptr_handle): Declared. (cptr_addr_of): Parameters added. * lib.c (code2type): Map CPTR type code to cptr_s. (equal): Handle CPTR objects. They are only equal to other CPTR objects which have the same operations, and are equal under the equal function of those operations. (cptr_print_op): New function. (cptr_ops): Use cptr_print_op rather than cobj_print_op. (cptr_typed): New function. (cptr): Use cptr_typed to make a cptr with tag nil, rather than using cobj. (cptrp, cptr_handle, cptr_type): New functions. (cptr_get): Go through cptr_handle rather than cobj_handle. (cptr_addr_of, cptr_zap, cptr_free): Use call to cptr_handle rather than cobj_handle for the type checking side effect. New parameters for type and parent function name. (obj_print_impl): Handle CPTR with same case as COBJ. * gc.c (finalize, mark_obj): Handle CPTR cases using common code with COBJ. * hash.c (equal_hash): Handle CPTR just like COBJ. * eval.c (eval_init): Register cptrp and cptr-type intrinsic functions. * ffi.c (ffi_cptr_put, ffi_cptr_get, ffi_cptr_alloc): Use the potentially type-safe cptr_handle, instead of cptr_get. However, for an untagged cptr, there is no type safety because tft->mtypes is nil. The argument can be any kind of cptr. * sysif.c (dlhandle_s, dlsym_s): New symbol variables. (cptr_dl_ops): Use cptr_print_op. (dlopen_wrap, dlclose_wrap): Use typed cptr with dlhandle as the type. (dlsym_wrap, dlsym_checked, dlvsym_wrap, dlvsym_checked): Recognize only a cptr of type dlhandle for the library. Construct a typed cptr of type dlsym. (sysif_init): Initialize dlhandle_s and dlsym_s. Register dlsym function using dlsym_s.
* less table robust against type renumbering.Kaz Kylheku2017-05-151-19/+14
| | | | | | | | | | * lib.c (less_tab_init): The type_prec table initialization will become incorrect if new type enums are added other than at the end. Let's switch to assignments. Anything not mentioned is zero. * lib.h: Add more advice to comment about extending type_t: consider all places where MAX_TYPE is used.
* bugfix: use proper hashing for cptr.Kaz Kylheku2017-05-151-1/+7
| | | | | | | | | | | | | | | Since cptr objects are equal if their handles are equal, they must have a hashing function over the handle rather than over their own address. * lib.c (cobj_handle_hash_op): New function. (cptr_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op. * lib.h (cobj_handle_hash_op): Declared. * sysif.c (cptr_dl_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op.
* cobj: rename poorly named default operation.Kaz Kylheku2017-05-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Renaming cobj_hash_op to cobj_eq_hash_op. This function is only appropriate to use with COBJ objects which use eq as their equal funtion. I've spotted one instance of an inappropriate use which have to be addressed by a different commit: the equal function is other than eq, but cobj_hash_op is used for the equal hash. * lib.h (cobj_hash_op): Declaration renamed to cobj_eq_hash_op. * hash.c (cobj_hash_op): Renamed to cobj_eq_hash_op. (hash_iter_ops): Refer to renamed cobj_hash_eq_op. * ffi.c (ffi_type_builtin_ops, ffi_type_struct_ops, ffi_type_ptr_ops, ffi-closure_ops, ffi_call_desc_ops): Likewise. * lib.c (cptr_ops): Likewise. * parser.c (parser_ops): Likewise. * rand.c (random_state_ops): Likewise. * regex.c (char_set_ops, regex_obj_ops): Likewise. * socket.c (dgram_strm_ops): Likewise. * stream.c (null_ops, stdio_ops, tail_ops, pipe_ops, dir_ops, string_in_ops, byte_in_ops, strlist_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops, record_adapter_ops): Likewise. * struct.c (struct_type_ops): Likewise. * sysif.c (cptr_dl_ops): Likewise. * syslog.c (syslog_strm_ops): Likewise. * unwind.c (cont_ops): Likewise.
* cptr: new functions.Kaz Kylheku2017-05-091-0/+25
| | | | | | | | | | * 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.
* 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.
* length: support buffer objects.Kaz Kylheku2017-05-041-0/+2
| | | | * lib.c (length): Handle BUF case via length_buf.
* 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: map (array n bchar) to Lisp string.Kaz Kylheku2017-05-041-0/+9
| | | | | | | | | | * 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: new bstr type.Kaz Kylheku2017-05-041-0/+24
| | | | | | | | | | | | | | | | | | 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.
* bugfix: tostringp not behaving right for floats.Kaz Kylheku2017-05-041-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* ffi: allow ptr-in-out passing of cptr.Kaz Kylheku2017-04-281-0/+6
| | | | | | | | | | | | | | | * ffi.c (ffi_ptr_alloc): New static function. (ffi_type_compile): Give the cptr type alloc and free functions: alloc just retrives the address of the pointer inside the cptr object (pointer to pointer); free is a noop. (cptr_make): New static function. (ffi_init): Register cptr_make as cptr intrinsic. Register cptr-null intrinsic variable denoting a ready-made null pointer. * lib.c (cptr_addr_of): New function. * lib.h (cptr_addr_of): Declared.
* Provide access to dlopen.Kaz Kylheku2017-04-251-2/+2
| | | | | | | | | | | | | | | | | | | | * configure: New test for dlopen. * lib.c (cptr_equal_op): Function renamed to cobj_equal_handle_op, to reflect what it's really doing; it is not specifically to cptr objects. Also changed from static to extern. (cptr_ops): Follow rename. * lib.h (cobj_equal_handle_op): Declared. * sysif.c (cptr_dl_destroy_op): New static function. (dlopen_wrap, dlclose_wrap, dlsym_wrap, dlvsym_wrap): New static functions. (sysif_init): Register new intrinsic functions dlopen, dlclose, dlsym, dlvsym. New variables rtld-lazy, rtld-now, rtld-global, rtld-local, rtld-nodelete, rtld-noload, rtld-deepbind.
* Start of FFI implementation based on libffi.Kaz Kylheku2017-04-241-0/+6
| | | | | | | | | | | | * Makefile (OBJS): Add ffi.o. * configure (have_libffi): New variable. (gen_config_make): Generate have_libffi make variable. New check for availability of libffi. * ffi.c, ffi.h: New files. * lib.c (init): Call ffi_init.
* Continuing implementation of buffers.Kaz Kylheku2017-04-211-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS): New objects itypes.o and buf.o. * buf.c, buf.h: New files. * itypes.c, itypes.h: New files. * lib.c (obj_print_impl): Handle BUF via buf_print and buf_pprint. (init): Call itypes_init and buf_init. * parser.h (end_of_buflit): Declared. * parser.l (BUFLIT): New exclusive state. (grammar): New rules for recognizing start of buffer literal and its interior. (end_of_buflit): New function. * parser.y (HASH_B_QUOTE): New token. (buflit, buflit_items, buflit_item): New nonterminals and corresponding grammar rules. (i_expr, n_expr): These symbols now generate a buflit; a buffer literal is a kind of expression. (yybadtoken): Handle HASH_B_QUOTE case.
* New buffer data type.Kaz Kylheku2017-04-161-1/+11
| | | | | | | | | | | | | | | | | | | | | | | Work in progress. * gc.c (finalize): Add cast to switch expression so gcc flags when we are missing one of the enumerations. Handle new BUF enum to free dynamic buffers. (mark_obj): Mark len and size fields of buf, in case they aren't just nil or integers. * hash.c (hash_buf): New static function. (equal_hash): Route BUF type to hash_buf. * lib.c (buf_s): New symbol variable. (code2type): Handle BUF. (equal): Handle BUF using memcmp on the data. (obj_init): Intern buf symbol and initialize buf_s. * lib.h (type_t): New enum member BUF. (struct buf): New type. (union obj): New member b, of struct buf type. (buf_s): Declared.
* Protect internal symbols from uninterning.Kaz Kylheku2017-04-151-2/+31
| | | | | | | | | | | | | | | | | | | | Issue: TXR holds numerous symbol references in global variables, like list_s. These variables are not registered as root pointers with the garbage collector. This is normally okay because symbols are reachable via packages. However, if such a symbol is uninterned, that causes an integrity problem. Solution: protect those symbols from being removed from their packages. * Makefile (OBJS): Add protsym.o. * genprotsym.txr, protsym.c: New files. * lib.c (prot_sym_check): New static function. (use_sym, uintern, rehome_sym): Use prot_sym_check to implement a defense against internal symbols being booted out of their package.
* Honor *print-circle* disabling in print methods.Kaz Kylheku2017-04-121-6/+10
| | | | | | * lib.c (obj_print): Don't assume that if we have a circle printing context in the stream, circle printing is enabled. Check the variable.
* quasiliterals: issue in printing embedded syms.Kaz Kylheku2017-04-051-28/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The op macro replaces syntax like @3 with gensyms. The problem is these genyms are not wrapped with (sys:var ...). For instance: `foo@{1}bar` ;; (sys:quasi "foo" (sys:var 1 () ()) "bar") might, inside an op expression turn into: (sys:quasi "foo" #:arg001 "bar") If this object is printed, it renders as `foo#:arg001bar` which is garbage syntax. After this fix, that will come out as: `foo@{#:arg001}bar` It is not read/print consistent, but it has the same meaning under evaluation. * lib.c (out_quasi_str_sym): New static function. Formed out of a block of code taken from out_quasi_str. (out_quasi_str): Print (sys:var ...) symbols via a call to out_quasi_str_sym, eliminating a block of code. If an element itself is a symbol, then print that using out_quasi_str_sym also.
* New time-parse-local and time-parse-utc functions.Kaz Kylheku2017-04-041-3/+29
| | | | | | | | | | | | | | | * eval.c (eval_init): Register intrinsic functions time-parse-local and time-parse-utc. * lib.c (strptime_wrap): New static function. (time_parse): Now implemented as by call to strptime_wrap. (time_parse_local, time_parse_utc): New functions. These get the time_t time from struct tm without constructing the intermediate Lisp structure. * lib.h (time_parse_local, time_parse_utc): Declared. * txr.1: Documented new functions.
* listener: completion sensitive for slots and methods.Kaz Kylheku2017-03-211-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When completing .prefix[TAB], .(prefix[TAB] or .[prefix[TAB], restrict identifiers to the appropriate namespace. The former will report only symbols from the relevant package which are struct slots; the latter further restricts it to those which are static slots defined as functions. * lib.c (symbol_visible): Static function becomes extern. * lib.h (symbol_visible): Declared. * parser.c (find_matching_syms): par parameter is renamed kind and can hold additional values 'S' (slots) and 'M' (methods). New get_slot_syms function is used to fetch the slots, as necessary, instead of the visible syms, if the kind is 'S' or 'M'. The same loop as before (with the minor change of recognizing 'S' and 'M' also) performs the prefix matching. (provide_completions): Recognize . .( and .[ prefix, calculating the kind argument of find_matching_syms in a new way. * struct.c (get_slot_syms): New function. * struct.h (get_slot_syms): Declared. * txr.1: Add some notes about this under the description of completion. The full rules are not given though; let the user discover.
* Sandboxing support via *package-alist*.Kaz Kylheku2017-03-171-5/+17
| | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register *package-alist* variable, taking on the contents of the packages variable. * lib.c (package_alist_s): New symbol variable. (make_package, packagep, find_package, package_alist); Work with dynamic package alist variable via cur_package_alist_loc macro. (get_current_package_alist_loc): New function. * lib.h (cur_package_alist_loc): New macro. (packages, package_alist_s, get_current_package_alist_loc): Declared. * txr.1: Documented *package-alist* along with notes about sandboxing. Documented that the package-alist function is now obsolescent.
* Rename badly named default_bool_argKaz Kylheku2017-03-171-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.h (default_bool_arg): Inline function renamed to default_null_arg. * eval.c (if_fun, pad, ginterate, giterate, range_star, range, constantp, macroexpand_1, macro_form_p, expand_with_free_refs, do_expand, eval_intrinsic, func_get_name, make_env_intrinsic): Follow rename. * arith.c (lognot): Likewise. * gc.c (gc_finalize): Likewise. * glob.c (glob_wrap): Likewise. * hash.c (group_reduce, gethash_n): Likewise. * lib.c (print, multi_sort, lazy_str, vector, iff, tok_str, split_str_keep, search_str, remove_if, val): Likewise. * match.c (match_fun): Likewise. * parser.c (lisp_parse_impl, regex_parse): Likewise. * rand.c (make_random_state): Likewise. * regex.c (read_until_match, search_regex, regex_compile): Likewise. * socket.c (sock_accept, sock_connect): Likewise. * stream.c (open_files_star, open_files, run, open_process, open_tail, get_string, record_adapter): Likewise. * struct.c (static_slot_ensure, static_slot_ens_rec, clear_struct, make_struct_type): Likewise. * sysif.c (exec_wrap, errno_wrap, cobj_ops_init): Likewise. * unwind.c (uw_capture_cont, uw_find_frames_impl): Likewise.
* split, split*, partition, partition*: allow neg indices.Kaz Kylheku2017-03-141-14/+46
| | | | | | | | | | * lib.c (partition_split_common): Filter the list of indices, displacing any negative values by the length of the sequence, removing any that are still negative. This is subject to compatibility. (partition_star): Likewise. * txr.1: Document, and add compat notes.
* Fix missing nao terminator in formatted printing.Kaz Kylheku2017-03-131-1/+1
| | | | | | | | | | | | | | * arith.c (trunc1, trunc, floorf, ceili): Add missing nao terminator to uw_throwf calls. * debug.c (debug): Missing nao terminator in format call. * eval.c (expand_opt_params_rec, me_equot): Missing nao terminator in eval_error call. * lib.c (use_sym): Missing nao in uw_throw call. * regex.c (reg_derivative): Missing nao in uw_throwf.
* New functions starts-with and ends-with.Kaz Kylheku2017-03-121-0/+12
| | | | | | | | | | | * eval.c (eval_init): Register starts-with and ends-with intrinsics. * lib.c (starts_with, ends_with): New functions. * lib.c (starts_with, ends_with): Declared. * txr.1: Documented.
* New rmismatch function.Kaz Kylheku2017-03-121-0/+100
| | | | | | | | | | * eval.c (eval_init): Register rmismatch intrinsic. * lib.c (rmismatch): New function. * lib.h (rmismatch): Declared. * txr.1: Documented
* uref: the a.b.c syntax extended to .a.b.cKaz Kylheku2017-03-061-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now it is possible to use a leading dot on the referencing dot syntax. This is the is the "unbound reference dot". It expands to the uref macro, which denotes an unbound-reference: it produces a function which takes an object as the argument, and curries the reference implied by the remaining arguments. * eval.c (uref_s): New global symbol variable. (eval_init): Intern uref symbol and init uref_s. * eval.h (uref_s): Declared. * lib.c (simple_qref_args_p): A qref expression is now also not simple if it contains an embedded uref, meaning that it cannot be rendered into the dot notation without ambiguity. (obj_print_impl): Support printing (uref a b c) as .a.b.c. * lisplib.c (struct_set_entries): Add uref to the list of autoload triggers for struct.tl. * parser.l (DOTDOT): Consume any leading whitespace as part of recognizing the DOTDOT token. Otherwise the new rule for UREFDOT, which matches (mandatory) leading space will take precedence, causing " .." to be scanned wrong. (UREFDOT): Rule for new kind of dot token, which is preceded by mandatory whitespace, and isn't consing dot (which has mandatory trailing whitespace too, matched by an earlier rule). * parser.y (UREFDOT): New token type. (i_dot_expr, n_dot_expr): New grammar rules. (list): Handle a leading dot on the first element of a list as a special case. Things are done this way because trying to work a UREFDOT into the grammar otherwise causes intractable conflicts. (i_expr): The ^, ' and , punctuators are now followed by an i_dot_expr, so that the expression can be an unbound dot. (n_expr): Same change as in i_expr, but using n_dot_expr. Plus new UREFDOT n_expr production. * share/txr/stdlib/struct.tl (uref): New macro. * txr.1: Documented.
* remq/remove-if family: bugfixes in error message.Kaz Kylheku2017-02-221-9/+9
| | | | | | | | | | | | * lib.c (rem_impl): Take a name argument, so as to report correct function name. Also, serious fix here: we passed the address of the in function to the error message format job, rather than seq_in. (remove_if): Report as remove-if rather than remq in the error message. Also, same bug as in remq_impl: in used in place of seq_in. (remq, remql, remqual, keepq, keepql, keepqual): Pass function name as string into remq_impl.
* New internal function: vec.Kaz Kylheku2017-02-151-0/+22
| | | | | | * lib.c (vec): New function. * lib.h (vec): Declared.