summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* A few volatile fixes related to setjmp.Kaz Kylheku2016-10-202-6/+6
| | | | | | | | | | | | * socket.c (dgram_get_byte_callback): nbytes must be volatile because we assign to it after setting up the catch, and then access it in the unwind code. (sock_accept): Likewise. * stream.c (generic_get_line): buf variable must be volatile. (struct save_fds): The members of this structure must be volatile; it's used as a local variable in a number of functions in a way that requires volatile.
* obj_print: use of volatile.Kaz Kylheku2016-10-201-3/+5
| | | | | | | | * lib.c (obj_print): The ret variable doesn't have to be volatile qualified, because it is never modified after setting an exception handler, and then accessed in the cleanup. On the other hand, the ctx variable is manipulated this way and must be volatile.
* doc: reduce-left fixes.Kaz Kylheku2016-10-201-2/+8
| | | | | * txr.1: Fixed grammar error and added clarification that the init-val isn't filtered through key-function.
* doc: fix incomplete range literal desc.Kaz Kylheku2016-10-201-0/+10
| | | | | * txr.1: describe from and to expressions of range literals.
* doc: fix incomplete hash literal desc.Kaz Kylheku2016-10-201-1/+8
| | | | * txr.1: describe key-value pairs of hash literals.
* Check call graph circularity in circ_backpatch.Kaz Kylheku2016-10-201-7/+13
| | | | | | | | | | | | | | | | | The circ_backpatch function could suffer runaway recursion, so we must add a cycle check. This could happen due to hitting cyclical objects when traversing structs. Structs have static slots that could contain cyclic objects, as well as construction logic which can generate slots that contain cycles and are not overridden by anything in the literal. * parser.c (circ_backpatch): Take struct circ_stack * argument; extend the circ_stack in recursive calls. Do circular check on entry. (parser_resolve_circ): Pass null pointer as the new stack argument to circ_backpatch.
* Fix struct lit problem exposed by circular syntax.Kaz Kylheku2016-10-206-12/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The semantics of how struct literals come to life is poorly designed: namely, the slot-value pairs in the struct literal are used as the plist argument in a call to make-struct. This is wrong because the implied initializations are then clobbered by the structure type's :init and :postinit handlers, resulting in an object with slot values that don't match what is in the literal. When you add circular syntax to the mix, things get worse. Slots may be initialized with (sys:circ-ref ...) expressions corresponding to #<n># syntax. These expressions then get clobbered by the constructor actions before the circ_backpatch processes the syntax. * parser.y (struct): Use make_struct_lit rather than make_struct to instantiate struct object. * struct.tl (sys:struct-lit): Expand to a form which calls sys:make-struct-lit, rather than make-struct. * struct.c (struct_init): Register new make_struct_lit function as sys:make-struct-lit intrinsic. (make_struct_lit): New function. * struct.h (make_struct_lit): Declared. * tests/012/struct.tl: struct literal expansion test case updated. * txr.1: Updated documentation of struct literals. Added compat notes.
* Implement *print-circle* for sharing and cycles.Kaz Kylheku2016-10-201-5/+122
| | | | | | | | | | | | | | | | | | | | | | | * lib.c (obj_print_impl): On entry, ctx being non-null indicates that cycle and substructure detecting is enabled via *print-circle* for this print job. In this case, check whether this is the first request to print a multiply-referenced object, in which case we print the #<n>= label definition, or whether it is a second or additional reference, in which case we render the object as #<n>#. Special handling must also be introduced into the loop which prints list elements. At any point in a list, the rest of the list could be shared substructure or a cyclic link that must be rendered with the appropriate notation. (populate_obj_hash): New static function. Enters all objects in the substructure that are eligible for the circle notation into the hash that is stored in the print context. Any object that appears two or more times is associated with a t value. (obj_print, obj_pprint): Unless circle printing is already in effect, check *print-circle* and turn it on if necessary and prepare the context, associating it with the stream. Either way, if circle printing is enabled, call populate_obj_hash to walk the object and add its components to the hash.
* Add stream printing context.Kaz Kylheku2016-10-208-55/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is some infrastructure which will support *print-circle*. * lib.h (struct strm_ctx): Forward declared. (struct cobj_ops): Add context parameter to print function pointer. (cobj_print_op, obj_print_impl): Add context parameter to declarations. * hash.c (hash_print_op): Take context argument and pass it down in obj_print_impl calls. * lib.c (cobj_print_op, out_quasi_str): Likewise (obj_print_impl): Likewise, and also pass to COBJ print method. (obj_print, obj_pprint): Pass null pointer as context argument to obj_print_impl. * regex.c (regex_print): Take context parameter and ignore it. * socket.c (dgram_print): Likewise. * stream.h (struct strm_ctx): New struct type. (struct strm_base): New ctx member, pointer to struct strm_ctx. (stream_print_op): Add context parameter to declaration. (get_set_ctx, get_ctx): Declared. * stream.c (strm_base_init): Add null pointer to initializer. (strm_base_cleanup): Add assertion against context pointer being non-null: that indicates that some stream operation installed a context pointer and neglected to restore it to null before returning, which is bad because context will be stack allocated. (stream_print_op, stdio_stream_print, cat_stream_print): Take context parameter and ignore it. (get_set_ctx, get_ctx): New functions. * struct.c (struct_type_print): Take context parameter and ignore it. (struct_inst_print): Take context parameter and pass down to obj_print_impl.
* Add *print-circle* special variable.Kaz Kylheku2016-10-192-2/+3
| | | | | | | | * stream.c (print_circle_s): New symbol variable. (stream_init): Initialize print_circle_s as symbol named *print-circle*; register as special var. * stream.h (print_circle_s): Declared.
* Cycle detection in sys:cp-origin.Kaz Kylheku2016-10-191-9/+13
| | | | | | | | | | | | | | | Tree-walking code in the place expander runs into trouble if the expression contains cycles. Test case: (defparm a '(#1=(a . #1#))). * share/txr/stdlib/place.tl (sys:cp-origin): Take list of symbols as a single argument instead of trailing arguments. Support an optional argument that gives serves as a cycle-detecting stack. Bail if a cycle is detected. (call-udpate-expander, call-clobber-expander, call-delete-expander): Update sys:cp-origin calls to follow interface change.
* reduce-left bugfix: bad init val with key-func.Kaz Kylheku2016-10-181-1/+1
| | | | | * lib.c (reduce_left): init value pulled from list itself must be passed through the key function.
* Adding notation for cycles and shared structure.Kaz Kylheku2016-10-184-5/+213
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit implements the parse-side support for handling a notation that exists in ANSI Common Lisp for specifying objects with cycles and shared substructure. * parser.h (struct parser): New members, circ_ref_hash and circ_count. (circref_s, parser_resolve_circ, parser_circ_def, parser_circ_ref): Declared. * parser.c (circref_s): New symbol variable. (parser_mark): Visit the new circ_ref_hash member of the parser structure. (parser_common_init): Initialize new members circ_ref_hash and circ_count of parser structure. (patch_ref, circ_backpatch): New static functions. (parser_resolve_circ, parser_circ_def, parser_circ_ref): New functions. (circref): New static function. (parse_init): Initialize circref_s as sys:circref symbol. Register sys:circref function. * parser.l (grammar): Scan #<num>= and #<num># notation as tokens, extracting their numeric value. * parser.y (HASH_N_EQUALS, HASH_N_HASH): New token types. (i_expr, n_expr): Adding phrases for hash-equalsign and hash-hash syntax. (yybadtoken): Handle new token types in switch. (parse_once): Call parser_resolve_circ after parsing to rewrite any remaining #<num># references in the structure to the objects they denote. (parse): Reset new struct parse members to initial state. Call parser_resolve_circ after parsing to rewrite any remaining #<num># references.
* Detect cycles in rlcp_tree.Kaz Kylheku2016-10-183-3/+34
| | | | | | | | | | | | | This will be required when the parser becomes capable of creating object graphs with cycles. * parser.c (parser_callgraph_circ_check): New function. * parser.h (struct circ_stack): New struct. (parser_callgraph_circ_check): Declared. * parser.y (rlcp_tree_rec): New static function. (rlcp_tree): Reduced to wrapper for rlcp_tree_rec.
* New function to access slot list of struct type.Kaz Kylheku2016-10-182-0/+7
| | | | | | * struct.c (slots): New function. * struct.h (slots): Declared.
* Provide functions to alter range objects.Kaz Kylheku2016-10-172-0/+16
| | | | | | | | | | Ranges continue to be immutable; but a backdoor is needed for upcoming support for circular notation. * lib.c (set_from, set_to): New functions. * lib.h (set_from, set_to): Declared.
* Bugfix: unable to assign to x.y.z place.Kaz Kylheku2016-10-151-4/+1
| | | | | | | | | | | | | | | | | | | This regression was caused by commit 957f80f "Bugfix: issue with expansion of place macros" on Sep 7, 2016. The commit itself is sound, but exposes a hidden problem in nearby code. * share/txr/stdlib/place.tl (sys:pl-expand): The conditions for terminating the loop and returning the expansion are too weak, due to the inclusion of an incorrect test. We must not bail when the expansion of a compound form is a compound form with the same symbol. This is because some macros behave that way, such as, oh: qref! The expansion of (qref a b c) is (qref (slot a 'b) 'c): another qref form. To fully expand, we must keep iterating until the returned form is eq to the input form. The original macroexpand (which was replaced by macroexpand-1 in 957f80f) hid this problem because macroexpand doesn't use this broken termination test.
* Support nil env in env-fbind and env-vbind.Kaz Kylheku2016-10-152-10/+30
| | | | | | | | * eval.c (env_fbind, env_vbind): Allow env to be nil, indicating that the binding is to take place in the global environment. * txr.1: Documented.
* Version 154.txr-154Kaz Kylheku2016-10-156-662/+710
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Fix wrong memset in new args handling function.Kaz Kylheku2016-10-151-1/+1
| | | | | | | * args.c (args_cat_zap_from): Clear the area that was copied, starting at the index offset, rather than from argument zero. This bug could result in spurious retention due to failing to zap some arguments.
* doc: defsymacro: runaway recursion.Kaz Kylheku2016-10-141-1/+1
| | | | | * txr.1: If a symbol macro expands to itself indirectly, the result isn't a loop but runaway recursion.
* doc: defsymacro rewording.Kaz Kylheku2016-10-141-8/+12
| | | | | * txr.1: Updating awkward wording, beginning with clumsy two-clause sentence joined by a colon.
* doc: small fix under format ~s directive.Kaz Kylheku2016-10-141-1/+3
| | | | | * txr.1: typeset print function name with .code so it turns to typewriter font and hyperlink.
* Adding family slot to socket addresses.Kaz Kylheku2016-10-133-9/+37
| | | | | | | | | | | | | | | A static slot indicating the address family simplifies code which wants to map a socket address to its family. * lisplib.c (sock_instantiate): Call sock_load_init before loading socket.tl rather than after, because socket.tl now references variables defined inside sock_load_init. * share/txr/stdlib/socket.tl (sockaddr, sockaddr-in, sockaddr-in6, sockaddr-un): New static slot, family. * txr.1: Documented family slots.
* Bugfix: sub and length on abstract sequences.Kaz Kylheku2016-10-133-1/+45
| | | | | | | | | | * lib.c (length_proper_list): New static function. (length): Use length_proper_list for objects. (sub): Call nullify on COBJ object before passing to sub_list. * tests/012/aseq.tl, tests/012/aseq.expected: New files.
* Overhaul where funtion.Kaz Kylheku2016-10-131-14/+43
| | | | | * lib.c (where): Implement faster ref-based access for vectors and strings. Support abstract sequence structs.
* doc: clarification under nullify method.Kaz Kylheku2016-10-131-1/+2
| | | | | | * txr.1: the nullify method need not return the object itself in the non-empty case; it may also return a sequence.
* Let some sequence functions work on structs.Kaz Kylheku2016-10-131-28/+32
| | | | | | * lib.c (in, sub, ref, search, rsearch, sel): These functions now accept struct objects that have the nullify, car and cdr methods.
* find-max and find-min support hashes.Kaz Kylheku2016-10-122-15/+76
| | | | | | | * lib.c (find_max): Restructured to implement separately for vectors and lists. Support hash tables. * txr.1: Document find-min and find-max for hashes.
* New accessor: hash-userdata.Kaz Kylheku2016-10-123-9/+51
| | | | | | | | | | | | | | The get-hash-userdata function is now deprecated in favor of hash-userdata, which is an accessor. * hash.c (hash_init): Register hash-userdata as a synonym for the same function as get-hash-userdata. * share/txr/stdlib/place.tl (hash-userdata): New defplace. * txr.1: Document new accessor, marking get-hash-userdata as a deprecated synonym. Replace references to get-hash-userdata with references to hash-userdata.
* listener: put each result into linenoise.Kaz Kylheku2016-10-121-0/+1
| | | | | | | | * parser.c (repl): After each successful command that produces a value, not only print the value but also call lino_set_result to install its string representation into the linenoise object, so it is available for insertion via Ctrl-X Ctrl-P.
* linenoise: Ctrl-X Ctrl-P edits result of command.Kaz Kylheku2016-10-122-0/+21
| | | | | | | | | | | | * linenoise/linenoise.c (struct lino_state): New member, result. (edit): Ctrl-P or p in extended mode cause result string to be inserted into the buffer. (lino_copy): Ensure result string in copy is null. (lino_cleanup): Free result string and set to null. (lino_set_result): New function. * linenoise/linenoise.h (lino_set_result): Declared.
* Include user data in hash read syntax.Kaz Kylheku2016-10-122-8/+40
| | | | | | | | | | | | | * hash.c (userdata_k): New keyword symbol variable. (hash_print_op): Print the userdata together with the hash flags as :userdata obj. (hashv): Parse out :userdata obj syntax from the argument list. This takes care of supporting it in the read notation and in the hash function. (hash_init): Initialize userdata_k. * txr.1: Documenting :userdata in hash read notation and hash function.
* Support gmtoff and zone in time struct.Kaz Kylheku2016-10-122-4/+52
| | | | | | | | | | | | | | * lib.c (gmtoff_s, zone_s): New symbol variables. (tm_to_time_struct): Copy tm_gmtoff and tm_zone into Lisp struct from struct tm, if the platform has these. (time_fields_to_tm): Zero/null-out the tm_gmtoff and tm_zone fields of the target structure, if the platform has them. (time_init): Intern the gmtoff and zone symbols, initializing the gmtoff_s and zone_s variables. Add the gmtoff and zone slots to the time struct. * txr.1: Documented new slots.
* doc: typo under html-encode*Kaz Kylheku2016-10-121-1/+1
| | | | * txr.1: necessary -> necessarily
* linenoise: bug in resubmit historic line when dupe.Kaz Kylheku2016-10-121-2/+4
| | | | | | | | | | | When Ctrl-X Enter is used to resubmit a line from the history, and it is a duplicate, it is not entered into the history. The position then doesn't advance to the next historic line. * linenoise/linenoise.c (lino_hist_add): Do add the line even if it is duplicate if the last submitted line was from the middle of the history.
* New function regex-from-trie.Kaz Kylheku2016-10-122-0/+78
| | | | | | | * filter.c (regex_from_trie): New static function. (filter_init): Register regex-from-trie intrinsic. * txr.1: Documented regex-from-trie.
* Support n-ary and and or operators in regex.Kaz Kylheku2016-10-101-1/+63
| | | | | | | | | | | Since much regex code assumes these are binary, the easiest and briefest approach is to implement a code transformation pass which rewrites n-ary forms into binary. * regex.c (reg_nary_unfold, reg_nary_to_bin): New functions. (regex_compile): Put raw sexp through reg_nary_to_bin to expand the nary syntax.
* Simplify some regex tree walking code.Kaz Kylheku2016-10-101-18/+10
| | | | | | | | | | * regex.c (reg_expand_nongreedy, reg_compile_csets): Generalize the compound_s case slightly by referring to sym rather than hard-coded compound_s. Then handle most of the regex operators under this same case. Their semantics are not relevant to the expansions being performed in these functions: all their arguments are regexes to be recursed over.
* Support curried args in method and meth.Kaz Kylheku2016-10-096-18/+115
| | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (meth): Take trailing arguments and pass them down to method, which now accepts them. * struct.c (struct_init): Register method intrinsic to the function method_args instead of the method function. (method_args_fun): New static function. (method_args): New function. Behaves like method function if args is empty, otherwise creates a function by means of method_args_fun. * struct.h (method_args_fun): Declared. * tests/012/oop.tl: New test case. * tests/012/oop.expected: Updated. * txr.1: Documented new features in method and meth, revising the documentation in the process.
* Support curried arguments in umethod and umeth.Kaz Kylheku2016-10-096-14/+71
| | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (umeth): accept variadic arguments. Evaluate them using the dwim brackets and pass to umethod. The (fun umethod) trick is used to refer to the umethod in the function namespace even if it is shadowed by a variable. * struct.c (struct_init): Update registration of umethod to reflect its new variadic argument signature. (umethod_args_fun): New static function. (umethod): Return a function based on umethod_fun, as before, if there are no variadic args. Otherwise, use umethod_args_fun which deals with them. * struct.h (umethod): Declaration updated. * tests/012/oop.tl: Modest testcase for umeth with curried argument. * tests/012/oop.expected: Updated. * txr.1: Updated documentation of umeth and umethod.
* New function: args_cat_zap_from.Kaz Kylheku2016-10-092-0/+11
| | | | | | * args.c (args_cat_zap): New function. * args.c (args_cat_zap): Declared.
* Bugfix: wrong memset size in args_cat_zap.Kaz Kylheku2016-10-091-4/+5
| | | | | | | | | | | | | | | * args.c (args_copy): Use from->arg and from->fill in calculating the memcpy size. It doesn't matter in this function because the to and from are the same; however, this may be the origin of the copy and paste error that led to args_cat_zap problem. (args_copy_zap): Similar change to args_copy: be consistent in using the from side expressions. (args_cat_zap): Bugfix: the total size of the to arguments was used to zap the from side. This writes zeros past the end of the from arguments. Fixing by calculating the size in one place and using the calculated size.
* Version 153.txr-153Kaz Kylheku2016-10-074-4/+19
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* gc issues in clear_struct and replace_struct.Kaz Kylheku2016-10-071-0/+3
| | | | | | | * struct.c (clear_struct, reset_struct): Inform the garbage collector that the structure has been mutate, using the mut macro. This is required for correctness because the structure may be a mature object receiving young generation values.
* Check for self-assignment in replace_struct.Kaz Kylheku2016-10-072-12/+27
| | | | | | | | | * struct.c (replace_struct): If target and source are the same object, just do nothing and return target. * txr.1: Document self-assignment and return value of replace-struct.
* doc: mistakes in introduction of do operator.Kaz Kylheku2016-10-071-3/+3
| | | | | | * txr.1: Where do is being introduced, fix a statement that about op, which should be about do. Plus fix verb agreement.
* nuke trailing newlines from exception messages.Kaz Kylheku2016-10-073-8/+8
| | | | | | | | | * signal.c (set_signal_handler, get_sign_handler): Eliminate newline in exception messages. * stream.c (unimpl, formatv): Likewise. * unwind.c (uw_block_abscond): Likewise.
* small bug in format: handle missing format char.Kaz Kylheku2016-10-071-0/+2
| | | | | | | | * stream.c (formatv): When the format string ends at the point where the format character is expected to occur, do not emit an error about #\nul being an unknown format directive character; emit an error that the character is missing.
* bug: heap backpointer assignment in static-slot-ensure.Kaz Kylheku2016-10-071-1/+1
| | | | | | | | * struct.c (static_slot_ens_rec): Neglected use of set macro to store newval in freshly allocated slot, which means we corrupt garbage collection if this causes an old generation objet to point to a new generation object.