summaryrefslogtreecommitdiffstats
path: root/unwind.c
Commit message (Collapse)AuthorAgeFilesLines
* Adding panic macro, which throws a panic exception.Kaz Kylheku2016-05-071-0/+1
| | | | | | | | | | | * lib.c (panic_s): New symbol variable. (obj_init): Initialize panic_s. * lib.h (panic_s): Declared. * unwind.c (uw_init): Register panic exception. * unwind.h (panic): New macro.
* Valgrind support in continuations.Kaz Kylheku2016-04-161-1/+18
| | | | | | | * unwind.c (revive_cont): When scanning the stack of the revived continuation to fix up pointers, we can save the Valgrind validity bits of each word, mark it defined, and then restore the validity bits.
* Block absconds across foreign frames.Kaz Kylheku2016-04-161-0/+4
| | | | | * unwind.c (uw_block_abscond): If a UW_GUARD frame occurs in the search for the abscond point, throw an error.
* Remove frame popping action from uw_continue.Kaz Kylheku2016-04-111-2/+1
| | | | | | | | | | | | * unwind.c (uw_continue): Don't take the current frame as an argument and consequently don't pop the current frame. This function currently has only one use, the uw_catch_end macro. * unwind.h (uw_continue): Declaration updated. (uw_catch_end): Slight code rearrangement: pop the frame unconditionally before the test for whether uw_continue must be called.
* Typo in comment.Kaz Kylheku2016-04-111-1/+1
| | | | | * unwind.c (uw_unwind_to_exit_point): Misspelled "execute".
* New frame type to block bad unwinding and cont capture.Kaz Kylheku2016-04-081-3/+30
| | | | | | | | | | | | | | | | | | If some external function is invoked which can call back into TXR Lisp, we should guard against the called-back code from capturing a continuation across the external stack frames, and also from unwinding across those frames. This patch prepares a mechanism for this. * unwind.c (uw_unwind_to_exit_point): Abort with message on standard error if attempt is made to unwind across UW_GUARD frame. (uw_push_guard): New function. (uw_capture_cont): If the frame search encounters a UW_GUARD block, an exception is thrown. * unwind.h (enum uw_frtype): New enum constant, UW_GUARD. (uw_push_guard): Declared.
* Implement socket timeouts.Kaz Kylheku2016-03-151-0/+1
| | | | | | | | | | | | | | | | | * lib.c (timeout_error_s): New symbol variable. (obj_init): Intern timeout-error, init new variable. * lib.h (timeout_error_s): Declared. * socket.c (sock_timeout, sock_send_timeout, sock_recv_timeout): New static functions. (sock_load_init): Register sock-send-timeout and sock-recv-timeout intrinsics. * stream.c (stdio_maybe_read_error, stdio_maybe_error): Convert EAGAIN into timeout_error_s. * txr.1: Documented.
* Semantics fix: unhandled exceptions must still unwind.Kaz Kylheku2016-01-221-23/+27
| | | | | | | | | | | | | | | | | * unwind.c (unhandled_ex): New static structure. (unwind_to_exit_point): The code to print the unhandled exception info and bail the process is moved here out of uw_throw. We do this in the situation when we have an unhandled exception, which is represented by the fact that the exception pointer points to the unhandled_ex structure. (uw_throw): If unhandled hook isn't a function, we don't abort; we go through the unwinding and unhandled processing. Also, ditto if the unhandled function returns, ditto. Unhandled processing is entered by substituting unhandled_ex for the not-found exception, and allowing unwind_to_exit point to be called. * txr.1: Document new behavior for unhandled exceptions and *unhandled-hook*.
* Header file cleanup.Kaz Kylheku2016-01-221-1/+0
| | | | | | | * arith.c, cadr.c, debug.c, eval.c, filter.c, gencadr.txr, glob.c, hash.c, linenoise/linenoise.c, lisplib.c, match.c, parser.c, rand.c, regex.c, signal.c, stream.c, struct.c, sysif.c, syslog.c, txr.c, unwind.c, utf8.c: Remove unncessary header files.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* Useful feature: object post-initialization.Kaz Kylheku2015-12-161-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Structs can now have code which executes after an object is initialized, which is useful for doing work like registering objects in global lists and whatever, when those actions need access to the initialized slots of the object. * share/txr/stdlib/struct.tl (defstruct): Handle :posinit syntax, by generating lambda as eighth argument of sys:make-struct call. * struct.c (struct struct_type): New member, postinitfun. (struct_init): Adjust registrations of make_struct_type to account for new parameter. The user visible make-struct-type is registered as having one optional argument, for backward compat. (make_struct_type): New argument, postinitfun. Store this in the structure. For backward compatibility, the argument is defaulted. (struct_type_mark): Mark the new postinitfun member. (call_postinitfun_chain): New static function. (make_struct, lazy_struct_init): Call call_postinitfun_chain after slots are initialized, and after the boa function is called. * struct.h (make_struct_type): Declaration updated. * lib.c (time_init): Pass eighth argument to make_struct type. * sysif.c (sysif_init): Likewise. * unwind.c (uw_late_init): Likewise. * tests/012/struct.tl: Update defstruct expansion test case. * txr.1: Document new argument of make-struct-type, and clarify ordering of initfun with regard to other actions. Likewise, document :postinit, and clarify ordering of :init actions with regard to other actions.
* Error reports trace through layers of macroexpansion.Kaz Kylheku2015-11-281-26/+4
| | | | | | | | | | | | | | | | | | | | * eval.c (error_trace): New function. Consolidates error reporting between unhandled exception handling in uw_throw, and the catcher in the repl. (op_defmacro, expand_macrolet): Propagate location info from body to wrapping block, and to the macro binding. In the latter function, also to the body that is wrapped by local macros. (do_expand, macroexpand_1): Propagate location info from macro expander to expansion, only taking it from the form if the macro doesn't supply it. * eval.h (error_trace): Declared. * parser.c (repl): Replace error reporting code with call to error_trace. * unwind.c (uw_throw): uw_throw: likewise.
* Report chain of macro-expansions in errors.Kaz Kylheku2015-11-251-1/+9
| | | | | | | | | | | | | | | * eval.c (origin_hash): New global variable. (lookup_origin): New function. (expand_macro): Enter original form into origin hash, keyed by new form. (eval_init): gc-protect and initialize origin_hash. * eval.h (lookup_origin): Declared. * parser.c (repl): Report chain of expansions from last_form_evaled. * unwind.c (uw_throw): Likewise.
* Clear stack area below revived continuation.Kaz Kylheku2015-11-051-0/+1
| | | | | | | | | | | * unwind.c (revive_cont): Don't just reserve frame_slack bytes below the continuation for any stack frame, but clear the bytes to zero. On Cygwin, this fixes a failing continuation test case. The issue is that the cont_obj variable in capture_cont lands into this area (implying it is not captured). When the continuation is revived, the variable has a garbage value, rather than nil, as expected.
* Copy envs for middle-of-binding continuations.Kaz Kylheku2015-11-051-1/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When continuations are captured/restored in the middle of variable binding constructs, a hidden problem occurs. Binding constructs work by allocating an empty environment and then destructively extending it. Since the environment is not on the stack, but a referenced object, it doesn't get deep copied into a continuation. As the continuation is revived repeatedly, parts of the variable binding code are repeatedly re-executed, and keep pushing fresh bindings into the same environment object. Though the new bindings correctly shadow the old, the old bindings are there and potentially hang on to garbage. The solution taken here is to introduce a new kind of frame for handling the situation: a continuation copy handling frame. This frame allows functions to register objects to be copied more deeply if a continuation is captured/revived across them. * eval.c (copy_env): New static function. (copy_env_handler): New static function. (bind_args, bind_macro_params): Install continuation copy handling frame for cloning new_env. (struct bindings_helper_vars): New struct type. (copy_bh_env_handler): New static function. (bindings_helper): Install continuation copy handling frame for de and ne variables which hold environments. The variables are moved to a struct to facilitate access from the handler. * eval.h (copy_env): Declared. * unwind.c (uw_push_cont_copy): New function. (call_copy_handler): New static function. (revive_cont): When a continuation is being revived invoke the copying actions in its continuation copy handling frames, but not if it is only being temporarily revived for immediate unwinding. (capture_cont): After copying the continuation, invoke any continuation copying frames in the "parent": the original frames that were captured. * unwind.h (enum uw_frtype): New type, UW_CONT_COPY. (struct uw_cont_copy): New struct type. (union uw_frame): New member cp. (uw_push_cont_copy): Declared.
* Moving sys:capture-cont to call/cc style API.Kaz Kylheku2015-11-021-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * unwind.c (revive_cont): Don't wrap cons cell around passed arg; just pass it directly. We don't need that convention any more. * capture_cont: Take functional argument. Pass the captured continuation to the function. If the function returns, return whatever it returned. When resuming, return the continuation argument. (uw_capture_cont): Take functional second argument and pass to capture_cont. Context form becomes third argument. (uw_late_init): Update registration of sys:capture-cont to three arguments, two required. * unwind.h (uw_capture_cont): Declaration updated. * share/txr/stdlib/yield.tl (sys:yield-impl): Not needed any more; all this was doing was implementing a call/cc style interface around sys:capture-cont which can now be used directly. (yield-from): Use sys:capture-cont directly. (suspend): Simplified to the point of triviality with new sys:capture-cont. * txr.1: Documented.
* Provide a way to free the continuation stacks.Kaz Kylheku2015-10-291-39/+50
| | | | | | | | | | | | | | | | | | * share/txr/stdlib/yield.tl (sys:obtain-impl): Pass sys:cont-free symbol to each abandoned continuation to release its stack buffer. (obtain): Handle the sys:cont-free symbol in the lambda, so the initial lambda can be treated uniformly with continuation functions. * txr.1: Documented sys:obtain-impl. * unwind.c (sys_cont_free_s): New symbol variable. (cont_mark): Check for null stack pointer and avoid marking. (revive_cont): If arg is sys:cont-free, then free the continuation and return nil. If the continuation has a null stack buffer, throw an error. (uw_late_init): Initialize sys_cont_free_s.
* Unwinding continuations via "poison" value.Kaz Kylheku2015-10-291-2/+3
| | | | | | | | | | | | * unwind.c (sys_cont_poison_s): New symbol variable. (revive_cont): If the argument is the poison symbol, then unwind through the continuation all the way back to revive_cont's own block, instead of to the continuation's very top block. Thus the continuation is not restarted but completely unwound. (uw_late_init): Initialize sys_cont_poison_s. * txr.1: Documented sys:cont-poison.
* Implementing sys:abscond-from operator.Kaz Kylheku2015-10-281-0/+47
| | | | | | | | | | | | | | | | | | | | | * eval.c (sys_abscond_from_s): New symbol variable. (op_abscond_from): New static function. (do_expand): Handle abscond-from like return-from. (eval_init): Initialize sys_abscond_from_s and register sys:abscond-from operator. * share/txr/stdlib/yield.tl (yield-from): Use sys:abscond-from instead of return-from, to avoid tearing down the continuation's resources that it may need when restarted. * txr.1: Documented sys:abscond-from and added a mention to the Delimited Continuations introduction. * unwind.c (uw_abscond_to_exit_point): New static function. (uw_block_abscond): New function. * unwind.h (uw_block_abscond): Declared.
* Context form error reporting in sys:capture-cont.Kaz Kylheku2015-10-281-6/+9
| | | | | | | | | | | | | | * unwind.c (sys_capture_cont_s): New variable. (uw_capture_cont): Second argument is now a context form rather than a symbol; eval_error is used for error reporting. The form's operator symbol si used in the error message, or else sys:capture-cont if the context argument is null or missing. (uw_late_init): Initialize sys_capture_cont_s. * unwind.h (uw_capture_cont): Declaration updated. * txr.1: Documented.
* Fix size growth of nested continuation capture.Kaz Kylheku2015-10-271-1/+2
| | | | | | | | | | | | | The issue is that captures from within a restarted continuation of the same continuation, are using the restart prompt as the delimiter rather than re-using captured block of the same name. Thus each successive capture adds a new frame, causing the size to grow drastically. * unwind.c (uw_capture_cont): Allow the existing captured block to be the delimiter; don't delimit up to the revive_cont's prompt block of the same name.
* Capture portion of stack beyond prompting block.Kaz Kylheku2015-10-261-1/+3
| | | | | | | | | | Without this we don't properly capture some of the context in some built-in special operator functions like op_for when we capture up to their implicit blocks. * unwind.c (capture_cont): Capture an extra region of the stack above the delimiting block. 32 words seems like a reasonable fudge value.
* TXR gets delimited continuations.Kaz Kylheku2015-10-251-1/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * unwind.c (sys_cont_s): New symbol variable. (uw_pop_block): New function, supporting uw_block_end macro. Special logic is needed for popping blocks now, because a block can be a captured stub at the top of a continuation, which must not be popped in the regular manner. (struct cont): New struct type. (cont_destroy, cont_mark): New static functions. (cont_ops): New static structure. (revive_cont, capture_cont): New static functions. (uw_capture_cont): New functions. (uw_init): Initialize sys_cont_s. Register sys:capture-cont intrinsic. * unwind.h (enum uw_frtype): New enum member UW_CAPTURED_BLOCK. When a block is captured as a stub copy of the prompt block of a delimited continuation, its type is changed from UW_BLOCK to this new type. This does two things: it makes the block invisible to block-related code that does nothing with continuations (code that looks for UW_BLOCK and ignores anything else). Secondly, there is some special handling related to UW_CAPTURED_BLOCK frames. (uw_pop_block, uw_capture_cont): Declared. (uw_block_begin): New local pointer uw_rslt introduced which helps communicate the result variable over to the uw_block_end macro (so we don't have to add a variable argument to the latter). (uw_block_end): Use uw_pop_block instead of uw_pop_frame. * txr.1: Documented delimited continuations.
* Stop using C library setjmp/longjmp.Kaz Kylheku2015-10-251-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TXR is moving to custom assembly-language routines. This is mainly motivated by a very dubious thing done in the GNU C Library setjmp and longjmp in the name of security. Evidently, glibc's setjmp "mangles" certain pointer values which are stored into the jmp_buf buffer. It's been that way since 2005, evidently. This means that, firstly, all along, the use of setjmp in gc.c to get registers into a buffer so they can be scanned has not actually worked properly. More importantly, this pointer mangling in setjmp and longjmp is very hostile to a stack copying implementation of delimited continuations. The reason is that continuations contain jmp_buf buffers, which get relocated in the process of capturing and reviving a continuation. Any pointers in a jmp_buf which point into the captured stack segment have to be fixed up to point into the relocated location. Mangled pointers make this difficult, requiring hacks which are specific to glibc and the machine architecture. We might as well implement a clean, well-behaved setjmp and longjmp. * Makefile (jmp.o): New object file. (dbg/%.o, opt/%.o): New rules for .S prerequisites. * args.c, arith.c, cadr.c, combi.c, cadr.c, combi.c, debug.c, eval.c, filter.c, glob.c, hash.c, lib.c, match.c, parser.c, rand.c, regex.c, signal.c, stream.c, struct.c, sysif.c, syslog.c, txr.c, unwind.c, utf8.c: Removed <setjmp.h> include. * gc.c: Switch to struct jmp and jmp_save, instead of jmp_buf and setjmp. * jmp.S: New source file. * signal.h (struct jmp): New struct type. (jmp_save, jmp_restore): New function declarations denoting assembly language routines in jmp.S. (extended_jmp_buf): Uses struct jmp instead of setjmp. (extended_setjmp): Use jmp_save instead of setjmp. (extended_longjmp): Use jmp_restore instead of longjmp.
* Reduce stack usage for args in a few places.Kaz Kylheku2015-10-241-2/+1
| | | | | | * eval.c (apply, do_eval): Use ARGS_MIN instead of ARGS_MAX. * unwind.c (uw_throw): Ditto, when invoking handler.
* Adding find-frame function.Kaz Kylheku2015-10-151-0/+47
| | | | | | | | | | | | * unwind.c (uw_find_frame): New function. (uw_late_init): Registered find-frame intrinsic. * unwind.h (uw_find_frame): Declared. * lib.h (default_arg_strict): New inline function. Will not replace nil value with default. * txr.1: Documented find-frame.
* Introspection over catch and handle frames.Kaz Kylheku2015-10-151-1/+81
| | | | | | | | | | | | | | * unwind.c (types_s, jump_s): New symbol variables. (frame_type, catch_frame_type, handle_frame_type): New globals denoting struct types. (uw_get_frames, uw_invoke_catch): New functions. (uw_late_init): Initialize new global variables. Register get-frames and invoke-catch intrinsics. * unwind.h (uw_get_frames, uw_invoke_catch): Declared. * txr.1: Documented frame, catch-frame, handle-frame, get-frames and invoke-catch.
* New way of handling exceptions without unwinding.Kaz Kylheku2015-10-141-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (handler_bind_s): New symbol variable. (op_handler_bind): New static function. (do_expand): Traverse handler-bind forms. (eval_init): Initialize handler_bind_s variable and register handler-bind operator. * lisplib.c (except_set_entries, except_instantiate): New functions. (lisplib_init): Register new functions in dl_table. * parser.c (intr_s): New symbol variable. (repl_intr): Throw exception of type intr, rather than error. This way we can interrupt accidental exception handling loops involving exceptions derived from error. (parse_init): Initialize intr_s. * share/txr/stdlib/except.tl: New file, defines handle macro. * unwind.c (uw_push_handler): New function. (invoke_handler): New static function. (uw_throw): Search loop looks for and processes handlers in addition to catches. * unwind.h (uw_frtype_t): New enum member, UW_HANDLE. (struct uw_catch): Move member visible so it is in the same position as in struct uw_handler. (struct uw_handler): New struct type. (union uw_frame): New member ha of type struct uw_handler. (uw_push_handler): Function declared. * txr.1: Added introductory paragraphs to Exception Handling section. Documented handler-bind and handle. Some minor errors corrected.
* Report objects with ~s in exception registration code.Kaz Kylheku2015-10-081-4/+4
| | | | | * unwind.c (uw_register_subtype): Error messages should print symbols with ~s, not the information-losing ~a.
* Use of new args for function calls in interpreter.Kaz Kylheku2015-08-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * args.c (args_copy_to_list): New function. * args.h (ARGS_MIN): New preprocessor symbol. (args_add_list): New inline function. (args_copy_to_list): Declared. * debug.c (debug): Args in debug frame are now struct args *. Pull them out nondestructively for printing using args_copy_to_list. * eval.c (do_eval_args): Fill struct args argument list rather than returning evaluated list. Dot position evaluation is handled by installing the dot position value as args->list. (do_eval): Allocate args of at least ARGS_MAX for the call to do_eval_args. Then use generic_funcall to invoke the function rather than apply. (eval_args_lisp1): Modified similarly to do_eval_args. (eval_lisp1): New static function. (expand_macro): Construct struct args argument list for the sake of debug_frame. (op_dwim): Allocate args which are filled by eval_args_lisp1, and applied to the function/object with generic_funcall. The object expression is separately evaluated with eval_lisp1. * match.c (h_fun, v_fun): Construct struct args arglist for the sake of debug_frame call. * unwind.c (uw_push_debug): args argument becomes struct args *. * unwind.h (struct uw_debug): args member becomes struct args *. (uw_push_debug): Declaration updated. * txr.1: Update documentation about dot position argument in function calls. (list . a) now works, which previously didn't.
* Large scale conversion to new way of handling arguments.Kaz Kylheku2015-08-231-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Function arguments are now allocated on the stack using alloca, in conjunction with the struct alloc header structure. The generic_funcall and apply functions are refactored for this, as are most functions that take variadic arguments. * args.c (args_add_list, args_cons_list): Functions removed. (args_normalize, args_normalize_fill): New functions. (args_get_checked): Draw arguments from list when array runs out. (args_copy, args_copy_zap): New functions. * args.h (ARGS_MAX): Reduced to 32. (ARGS_MIN): New preprocessor symbol. (args_init): Call args_init_list. (args_add2, args_add3, args_add4): New inline functions. (args_more): Take into account list, which may hold additional arguments. (args_two_more): New inline function. (args_normalize, args_normalize_fill): Declared. (args_get_list): Normalize all arguments into one list and return it. (args_get_rest, args_at, args_atz): New inline functions. (args_get): Draw arguments from list when array runs out. (args_clear): New inline function. * arith.c (maskv): Convert to new args. * eval.c (APPLY_ARGS): Preprocessor symbol removed. (bind_args): Converted to accept struct args. (apply): Function reduced down to trivial adapter which converts a list of arguments to args, and calls the new generic_funcall. (applyv): New static function: struct args wrapper around apply_intrinsic. (iapply): Converted to struct args. (call): Static function removed. The call intrinsic function binding now goes directly to generic_funcall. (list_star_intrinsic, interp_fun): Converted to struct args. (op_catch): Adjustments for bind_args, which requires a struct args arglist. (me_op): Must use the new minl and maxl, since minv and maxv don't take lists any more. (mapcarv, mappendv, lazy_mapcarv, lazy_mappendv, mapdov, weavev, or_fun, and_fun, tf, nilf, do_retf, do_apf, do_ipf, callf, do_mapf, mapf): Converted. (mapcarl): New function, like the old mapcarv. (eval_init): call_f initialized from generic_funcall rather than call. apply registered to applyv rather than apply_intrinsic. Registrations for zip, hash_from_pairs, vec, alist-remove, alist-nremove, and throw similarly updated to new or renamed functions. * eval.h (interp_fun, mapcarv): Declarations updated. (mapcarl): Declard. * hash.c (hashv): Converted to struct args. (hashl): New function. (hash_construct): Use hashl, not hashv. (hash_from_pairs, hash_list, group_by): Converted. * hash.h (hashv, hash_construct, hash_from_pairs, hash_list, group_by): Declarations updated. (hashl): Declared. * lib.c (appendv, nconcv, lazy_appendv): Converted to struct args. (lazy_appendl): New function. (multi): Converted. (listv): New function. (nary_op, plusv, mulv, logandv, logiorv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv): Converted. (maxl, minl): New functions, like old maxv and minv. (exptv, gcdv, lcmv, lessv, greaterv, lequalv, gequalv): Converted. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n1ov, func_n2ov, func_n3ov): Converted. (generic_funcall): Converted to take struct args. (funcall, funcall1, funcall2, funcall4): Pass stack-allocated struct args as trailing arguments to variadic functions, and to generic_funcall. (do_curry_12_1_v): New struct-args-based static function, needed to implement curry_12_1_v now. (curry_12_1_v): Converted. (transposev): New function based on previous tranpose. (transpose): Now a wrapper for transposev. (do_chain, chainv, do_chand, chandv, do_juxt, juxtv, do_and, andv, do_or, orv, do_not, do_iff): Converted. (vectorv): New function. Implementation basis for vec intrinsic function. (alist_removev, alist_nremovev): New functions. (multi_sort): Switch from mapcarv to mapcarl. (unique): Converted. (uniq): Allocate struct args for calling unique. (obj_init): list_f function now based on new listv, rather than identity. * list.h (varg): New typedef. (struct func): All variadic function pointers converted to use struct args. (appendv, nconcv, lazy_appendv, multi, nary_op, plusv, minusv, mulv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv, exptv, gcdv, lcmv, logadnv, logiorv, maskv, lessv, greaterv, lequalv, gequalv, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n1ov, func_n2ov, func_n3ov, generic_funcall, chainv, chandv, juxtv, adnv, orv, unique): Declarations updated. (lazy_appendl, listv, maxl, minl, transposev, vectorv, alist_removev, alist_nremovev): Declared. * stream.c (make_catenated_stream_v): New function. (aformat): Renamed to formatv. The recognition of the nil and t streams (standard output and string) is done here now. (vformat): Follow rename of aformat to formatv. (formatv): Function removed. Nobody calls this anymore. (stream_init): make-catenated-stream re-registered to new make_catenated_stream_v function. * stream.h (formatv): Declaration updated. (make_catenated_v): Declared. * syslog.c (syslog_init): syslog registred to syslog_wrapv. (syslog_wrapv): New function based on syslog_wrap converted to struct args. (syslog_wrap): Now wrapper for syslog_wrapv. * syslog.h (syslog_wrapv): Declared. * unwind.h (uw_throwv): New function. (uw_throwfv, uw_errorfv): Converted to struct args. * unwind.h (uw_throwv): Declared. (uw_throwfv, uw_errorfv): Declarations updated.
* New exception type: system-error.Kaz Kylheku2015-08-051-0/+1
| | | | | | | | | * lib.c (system_error_s): New symbol variable. (obj_init): Initialize new variable. * lib.h (system_error_s): Declared. * unwind.c (uw_init): Register system-error exception type.
* * eval.c (bind_args): Use new ~! for proper indentationKaz Kylheku2015-08-041-4/+4
| | | | | | | of multi-line context form. (apply): Use ~! for proper indentation of function code. * unwind.c (uw_throw): Use ~! for proper indentation of code.
* * eval.c (force): Default the new second argument of source_loc_str.Kaz Kylheku2015-08-041-4/+2
| | | | | | | | | | | | | | | | | | | (eval_error): Derive location of error from the last_form_evaled, if form doesn't have it. (eval_init): Re-register source-loc-str as binary with an optional arg. * match.c (debuglf, sem_error, file_err, typed_error): Default new argument of source_loc_str. * parser.h (source_loc_str): Declaration updated. * parser.l (source_loc_str): Take second argument which specifies alternative value if the source loc info is not found. * unwind.c (uw_throw): Simplify code thanks to source_loc_str default argument. * txr.1: Document new argument of source-loc-str.
* Improved error reporting, particularly for macro expansion.Kaz Kylheku2015-02-211-2/+8
| | | | | | | | | | | | | | | | | | | * eval.c (last_form_expanded): New variable. (do_expand): New static function; contains previous expand function. (expand): Becomes a wrapper for do_expand, with re-entry counting. (eval_init): GC-protect last_form_expanded. * eval.h (last_form_expanded): Declared. * parser.l (regex_parse, lisp_parse): Just use a simple word for the name of the regex or string parse location, not the entire expression itself. * unwind.c (uw_throw): Check whether expansion was going on when the unhandled exception was thrown and print additional information.
* * unwind.c (uw_throw): Detect invalid re-entry and bail.Kaz Kylheku2015-02-061-0/+7
| | | | | Cautiously, we use fprintf rather than our streams system, in case some problem with the streams is involved in this mess.
* * unwind.c (uw_throw): Put a txr: prefix on the unhandledKaz Kylheku2015-02-061-1/+1
| | | | exception in early initialization message.
* Slight internal representation change of string-only exceptions.Kaz Kylheku2015-02-061-8/+15
| | | | | | | | | | | | | | | | | | | | | | | | | One upshot of all this is that (throw 'foo "msg") now does exactly the same thing as (throwf 'foo "msg"). A message-only exception really is a one-string exception argument list ("message ..."), like the documentation says. * unwind.h (struct uw_catch): exception member renamed to args. (uw_catch): Macro follows structure member rename. * eval.c (op_catch): Removed now unnecessary kludge of turning non-list exception argument list into a one-element argument list. * match.c (v_try): Similar hack to the one in op_catch removed here. * unwind.c (uw_unwind_to_exit_point, uw_push_catch): Follows rename of exception member. (uw_throw): The exception parameter is renamed to args. The kludge removed from op_catch re-appears here, because numerous calls to uw_throw just pass a string as args. It's less of a kludge here because this is the master entry point to exception processing, and it straightens out the representation right away. The exception arguments or message are printed in a clearer way.
* * unwind.c (unhandled_hook_s): New static variable.Kaz Kylheku2015-02-061-2/+29
| | | | | | | | | | | | | | | | | | | (uw_throw): In the unhandled case, check if *unhandled-hook* variable has a function, and use it instead of the default logic. If it's not a function, abort with an error message. Clear it so that if the hook function re-enters this code, it will not be used. Always exit now on unhandled exceptions; do not abort. (uw_late_init): New function. * unwind.h (uw_late_init): Declared. * lib.c (init): Call uw_late_init. * txr.1: Documented *unhandled-hook*. * genvim.txr: Scan the unwind.c file, since it has a reg_var now. * tl.vim, txr.vim: Updated.
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* * Makefile: Removing trailing spaces.Kaz Kylheku2014-10-241-1/+0
| | | | | | | | | | (GREP_CHECK): New macro. (enforce): Rewritten using GREP_CHECK, with new checks. * arith.c, combi.c, debug.c, eval.c, filter.c, gc.c, hash.c, lib.c, * lib.h, match.c, parser.l, parser.y, rand.c, regex.c, signal.c, * signal.h, stream.c, syslog.c, txr.c, unwind.c, utf8.c: Remove trailing spaces.
* Converting cast expressions to macros that are retargettedKaz Kylheku2014-10-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
* * eval.c (eval_init): Update registration of lisp-parse and readKaz Kylheku2014-09-021-0/+1
| | | | | | | | | | | | | | | | | | | | to account for new parameter. * lib.c (syntax_error_s): New symbol_variable. (obj_init): New symbol variable initialized. * lib.h (syntax_error_s): Declared. * parser.h (lisp_parse): Declaration updated. * parser.l (lisp_parse): Takes third parameter. * txr.1: Third parameter of read described. * txr.c (txr_main): Pass colon_k to third parameter of lisp_parse to obtain exception throwing behavior. * unwind.c (uw_init): Register syntax-error as subtype of error.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* * configure: Add a check, in the case that we cannot make anKaz Kylheku2014-07-221-0/+5
| | | | | | | | | | | | | | | | | executable, whether this is due to being required to use C99. For instance, the Solaris environment requires compilation using the C99 dialect if _XOPEN_SOURCE is set to 600 or higher. * debug.c: When compiling as C99, we have to obey the special C99 conventions for instantiating inline functions. * hash.c: Likewise. * lib.c: Likewise. * parser.y: Likewise. * unwind.c: Likewise.
* The dumping of bindings and printing of false must nowKaz Kylheku2014-06-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | be explicitly requested by the -B option. * match.c (opt_nobindings): Variable removed. (opt_print_bindings): New variable. (extract): Print bindings or "false" if opt_print_bindings is true. * stream.c (output_produced): Variable removed. (stdio_put_string, stdio_put_char, stdio_put_byte): Remove update of output_produced. * stream.h (output_produced): Declaration removed. * txr.1: Documentation updated. * txr.c (txr_main): Option 'b' does nothing. 'B', 'l', 'a', and '--lisp-bindings' set opt_print_bindings to 1. * txr.h (opt_nobindings): Declaration removed. (opt_print_bindings): Declared. * unwind.c (uw_throw): When exiting due to a query error or file error, print false when opt_print_bindings is true.
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash, Change to how locations are passed around, for the sake of generational GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash,
* * lib.c (assert_s): New global variable.Kaz Kylheku2014-03-061-0/+1
| | | | | | | | | | | | | | | (obj_init): Intern assert symbol, store in assert_s. * lib.h (assert_s): Declared. * match.c (typed_error, v_assert, h_assert): New static functions. (dir_tables_init): Register v_assert and h_assert. Register assert_s as non-data-matching directive. * unwind.c (uw_init): Register assert as a subtype of error. * txr.1: Describe assert.
* In the spirit of the previous hack, here is another hack toKaz Kylheku2014-02-161-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | alleviate a long-standing pain: when an exception happens in TXR's library somewhere, the program dies without leaving a clue about what code was being evaluated when that happened. What we can do is have the evaluator publish the most recent compound form it has processed by stashing it in a variable. Then when an unhandled exception occurs, we can peek at that and try to pull out source location info. * eval.c (last_form_evaled): New variable. (do_eval): When evaluating a compound form, stash it in last_form_evaled. (eval_init): Protect last_form_evaled from gc. * eval.h (last_form_evaled): Declared. (eval_error_s): Existing variable declared. * unwind.c: Has to include "eval.h" for the above variable and "parser.h" for the source_loc function. (uw_throw): When an exception is unhandled, if last_form_evaled has source info, add it to the diagnostic. But not if the exception is eval-error; because errors from the evaluators already have the info.
* First cut at signal handling support.Kaz Kylheku2013-12-121-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.