summaryrefslogtreecommitdiffstats
path: root/unwind.h
Commit message (Collapse)AuthorAgeFilesLines
* debugger: expand frames.Kaz Kylheku2019-04-291-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds special unwind frames for backtracing expansions. With this, we can get rid of the global variable last_form_expanded, since to get the last form expanded, we just search for the most enclosing expand frame. * eval.c (last_form_expanded): Global variable removed. (error_trace): Use uw_last_form_expanded() instead of last_form_expanded. (expand_eval): No need to save and restore last_form_expanded any more. (expand_lisp_setq, expand_setqf, expand_lisp1, do_expand): Use uw_last_form_expanded(). (expand, do_macroexpand_1): Push and pop expand frame. This fixes a bug: do_macroexpand_1 was not recording last_form_expanded. Evaluation of top-level forms uses explicit macroexpansion, therefore top-level evaluation was neglecting to set last_form_expanded. This explains weird behavior I saw in the listener from time to time, when errors would report against the expansion of the wrong form. (eval_init): Remove reference to last_form_expanded variable. * eval.h (last_form_expanded): Declaration removed. * share/txr/stdlib/debug.tl (expand-frame print-trace, expand-frame loc): New methods. (print-backtrace): Include uw-expand frames in the backtrace. * unwind.c (expand_frame_type): New static variable. (uw_find_frames_by_mask): Handle UW_EXPAND. (uw_last_form_expanded, uw_push_expand): New functions. (uw_late_init): Register expand-frame struct type. * unwind.h (enum uw_frtype): New enum member, UW_EXPAND. (uw_last_form_expanded, uw_push_expand): Declared.
* debugger: eval frames.Kaz Kylheku2019-04-211-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We introduce evaluation tracking frames. The backtrace function can use these to deduce the line from which a function is called (if called from interpreted code). Eventually we will have analogous virtual machine frames to do this for compiled code. * eval.c (do_eval): If backtraces are enabled, then push and pop an eval frame, which holds the two key pieces: the form and environment. * share/txr/stdlib/debug.tl ((fcall-frame loc), (fcall-frame print-trace), (eval-frame loc), (eval-frame print-trace)): New methods. (print-backtrace): Loop reduced to just dispatching frame-specific print-trace methods. It gives the previous and next frame to each method. The (fcall-frame print-trace) method prints function frames, using the previous form to deduce the location from which the function is called. The (eval-frame print-trace) method mostly suppresses the printing of eval frames. We print an eval frame if it is the parent of an internal function frame, and if it is the topmost frame (to identify the toplevel form at the root of the backtrace). * unwind.c (form_s): New symbol variable. (eval_frame_type): New static variable. (uw_find_frames_by_mask): Handle UW_EVAL case, producing eval-frame struct. (uw_push_eval): New function. (uw_late_init): Allocate eval-frame struct type, storing it in eval_frame_type, and gc-protect that new variable. Register uw-eval variable evaluating to a one bit mask with the UW_EVAL-th bit set. * unwind.h (enum uw_frtype): New enum constant UW_EVAL. (struct uw_eval): New struct type. (union uw_frame): New member, el. (uw_push_eval): Declared.
* debugger: initial backtrace support.Kaz Kylheku2019-04-161-1/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * debug.c (debug_state): Switch to unsigned, since this is now a bitmask. (sys_print_backtrace_s): New symbol variable. (dbg_clear, dbg_set, dbg_restore): New static functions. (debug_init): Initialize sys_print_backtrace_s. Register dbg-clear, dbg-set, dbg-restore intrinsics. Register dbg-enable, dbg-step, dbg-backtrace and dbg-all bitmask variables, Lisp equivalents of DBG_ENABLE, DBG_SETP, DBG_BACKTRACE and DBG_ALL. (debug_dump_backtrace): New function. * debug.h (opt_debugger): Declaration removed. (debug_state): Declaration updated. (DBG_ENABLE, DBG_STEP, DBG_BACKTRACE, DBG_ALL): New preprocessor symbols. (debug_set_state): Inline function removed. (debug_clear, debug_set, debug_restore): New inline functions. (dbg_backtrace, dbg_fcall_begin, dbg_fcall_end): New macros. (debug_dump_backtrace): Declared. * eval.c (error_trace): Invoke debug_dump_backtrace if support is compiled in and backtraces are enabled. * lib.c (do_generic_funcall): New function, copy of generic_funcall. (generic_funcall): Now a wrapper for do_generic_funcall which registers fcall frames if backtrace support is enabled. (funcall, funcall1, funcall2, funcall3, funcall4): Route to slow generic_funcall path if backtraces are enabled. * lisplib.c (debugger_instantiate, debugger_set_entries): New static functions. (lisplib_init): Autload support for debug module via above new functions. (lisplib_try_load): Save and restore debugger state in new way using debug_set and debug_restore, with specific mask values. * parser.y (parse_once): Disable debugging in new way. * share/txr/stdlib/debug.tl New file. * sighal.h (EJ_DBG_MEMB, EJ_DBG_SAVE, EJ_DBG_REST): New macros for saving/restoring debug state. (EJ_OPT_MEMB, EJ_OPT_SAVE, EJ_OPT_REST): Reference the above macros to include debug state in extended jump context. * txr.c (help): Document --backtrace and that that -d implies --backtrace. (txr_main): Enable debugger using debug_set. Provide new --backtrace option to enable backtraces only. * unwind.c (args_s): New symbol variable. (fcall_frame_type): New static variable. (unwind_to_exit_point): Save pointer to original frame stack and restore it when calling error_trace. This is so that error_trace can walk the stack to collect a backtrace. (uw_find_frames_by_mask, uw_push_fcall): New functions. (uw_late_init): Initialize args_s and fcall_frame_type. gc-protect fcall_frame_type. Register uw-* variables corresponding to the UW_* frame types. * unwind.h (uw_frtype_t): New enum constant UW_FCALL. (struct uw_fcall): New frame structure. (union uw_frame): New member fc. (uw_push_fcall, uw_find_frames_by_mask): Declared.
* cmdline: use handler instead of catch for errors.Kaz Kylheku2019-04-161-5/+12
| | | | | | | | | | | | | | | | | | | Errors encountered when parsing or evaluating a source file should be handled using a handler rather than a catch, so that the unwind stack is available to the error reporting function. This anticipates being able to dump a backtrace. * txr.c (parse_once_noerr, read_eval_stream_noerr): Adjust to reduced argument count in ignerr_func_body macro. * unwind.c (uw_trace_error): New function. * unwind.h (uw_trace_error): Declared. (ignerr_func_body): Revised to establish a handler in addition to the catch. The catch now doesn't do anything other than provide an intercepting exit point; the error_trace call is moved into the handler, and so it executes in a context where unwinding hasn't happened yet.
* exceptions: allow description field in catch frames.Kaz Kylheku2019-04-101-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (op_catch): Extra argument in sys:catch syntax specifies an expression that evaluates to a description field. (expand_catch): Expand the desc expression in sys:catch syntax. * parser.c (read_file_common): Increase acceptance of compiled files from versions 1-4 to 1-5, since we are now marking compiled files with version 5.0 rather than 4.0. * share/txr/stdlib/asm.tl (op-catch catch): Support new argument in the opcode syntax. Turns out we have a spare field in the instruction format which was previously set to zero We can use that for the description. Thus, the instruction set and VM remain backward compatible: old code works. * share/txr/stdlib/compiler.tl (compiler comp-catch): Handle the desc argument introduced into the sys:catch form. We must compile it as an expression, then inject the code into the instruction template, and reference the output register of that code block in the catch instruction. (%tlo-ver%): Bump up the compiled file version to 5.0. * share/txr/stdlib/except.tl (usr:catch, catch*): Add desc argument to generated sys:catch form, specifying it as nil. * unwind.c (desc_s): New symbol variable. (uw_find_frames_impl): Set the desc member of the extracted catch structure from the corresponding field in the catch frame. (uw_late_init): Initialize desc_s with interned symbol. Add desc slot to catch-frame type. * unwind.h (struct uw_catch): New member, desc. (uw_catch_begin_w_desc): New macro. * vm.c (vm_catch): Extract the desc field from the catch instruction, and use uw_catch_begin_w_desc to propagate that to the catch frame.
* debug support: crude debugger removed.Kaz Kylheku2019-04-091-17/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * debug.c (debug_depth, debug_quit_s): Variables removed. (step_mode, next_depth, breakpoints, last_command, cols): Static variables removed. (debug_check): C99 inline instantiation removed. (help, show_bindings): Static functions removed. (debug): Function removed. (debug_set_state): Now takes one int argument, returns int. It's anticipated that the new debug system will have a simple on-off switch; there won't be a debug_depth hack. (debug_restore_state): Function removed. (debug_init): Emptied. * debug.h (debug_depth, debug_state_t): Declarations removed. (debug_enter, debug_leave, debug_return): Macros removed. (debug_check): Inline function removed. (debug_set_state): Declaration updated. (debug_restore_state): Declaration removed. (debug_frame, debug_end): Macros removed. * eval.c (do_eval, me_interp_macro): Debugging support scrubbed. * lisplib.c (lisplib_try_load): Adapt to debug_set_state interface change. * match.c (h_fun, do_match_line, v_fun, match_files, match_fun): Debugging support scrubbed. * parser.y (parse_once): Adapt to debug_set_state interface change. * protsym.c: Regenerated. * signal.h (debug_depth): Declaration removed. (EJ_DBG_MEMB, EJ_DBG_SAVE, EJ_DBG_REST): Macros removed. (EJ_OPT_MEMB, EJ_OPT_SAVE, EJ_OPT_REST): Reduced to unconditionally empty definitions for future use. * unwind.c (uw_push_debug): Function removed. * unwind.h (uw_frtype_t): UW_DBG enum member removed. (struct uw_debug): struct declaration removed. (union uw_frame): db member removed. (uw_push_debug): Declaration removed. * txr.1: Debugger doc removed.
* unwind: rename env frames.Kaz Kylheku2019-04-061-5/+5
| | | | | | | | | | | | | | | | | | | | | | Unwind frames of type ENV exist for the sake of the pattern language. Let's rename them accordingly. * match.c (tleval, tleval_progn, h_fun, tx_subst_vars, v_bind, v_output, v_filter, v_fun): Occurrences of the macros uw_env_begin and uw_env_end are renamed. * unwind.c (uw_env_stack): Renamed to uw_menv_stack. (uw_unwind_to_exit_point, uw_abscond_to_exit_point, uw_find_env, uw_pop_frame, revive_cont): Follow rename of UW_ENV to UW_MENV and uw_env_stack to uw_menv_stack. (uw_push_env): Renamed to uw_push_match_env, and updated to follow renames. * unwind.h (enum uw_frtype, uw_frtype_t): UW_ENV renamed to UW_MENV. (uw_push_env): Renamed to uw_push_match_env. (uw_env_begin, uw_env_end): Renamed to uw_match_env_begin an uw_match_env_end.
* Copyright year bump 2019.Kaz Kylheku2019-01-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/asm.tl, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/compiler.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/trace.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/vm-param.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, vm.c, vm.h, vmop.h, win/cleansvg.txr: Extended Copyright line to 2018.
* defvar: warn about prior lexical uses.Kaz Kylheku2018-10-261-0/+1
| | | | | | | | | | | | | | | | | | | Now that the compiler has a more efficient treatment of global lexical variables, code which accesses global variables that have not yet been defined will misbehave if the intent is to for those variables to be dynamically scoped. There is such a bug in the op expander, in fact. * eval.c (me_def_variable): When defvar/defparm are expanding, they now check whether there is an outstanding unbound warning against the variable. If so, then a warning is issued that the variable was previously used lexically and is now being marked special. * unwind.c (uw_warning_exists): New function. * unwind.h (uw_warning_exists): Declared.
* bugfix: fatal exception on missing .txr_history.Kaz Kylheku2018-05-271-0/+9
| | | | | | | | | | | The new abstraction layer used by linenoise throws exceptions, but linenoise excpects a null pointer when a file open fails. * parser.c (lino_open, lino_open8): Catch error exceptions and convert to null return, using new macros to reduce repetitive coding. * unwind.h (ignerr_begin, ignerr_end): New macros.
* vm: integrate with delimited continuations.Kaz Kylheku2018-03-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It doesn't Just Work out of the box. Here is why. The struct vm state is declared somewhere on the stack, and then the vm executes various recursive functions. A block is established by vm_block(). Then if a continuation is captured up to that block, it will not include that part of the stack which holds the VM state. When the continuation is restarted, the struct vm * pointers inside the stack will be garbage. The solution: when a continuation is captured to a prompt that is set up by the VM block instruction (vm_block function), we put information into the block which says "don't just capture me plus some slack: please capture the stack all the way up to this specific address here". That address, of course, is just past the VM state, ensuring that the VM state is included in the snapshot. In short: a delimited continuation terminating in a prompt set up by the VM just include the entire VM context from the stack frame where the struct vm on down (i.e. up the stack) to the capture point. * unwind.c (uw_push_block): Initialize cont_bottom member to zero. Interpreted blocks leave this as zero. Blocks set up by the VM override it. (revive_cont): Critical: the range check must include the orig_end endpoint, because when the struct vm is captured into the continuation it is right at the end of the capture memory, and the prompt block's cont_bottom member points exactly to orig_end: one element past the struct vm. The cont_bottom member must be adjusted by delta so that continuations captured by the revived VM inside the continuation get the adjusted cont_bottom at their current stack location. (capture_cont): If the block is publishing a non-zer cont_bottom value, then take that value if it is a higher address than the lim (including the UW_CONT_FRAME_AFTER slack). * unwind.h (struct uw_block): New member, cont_bottom. By means of this, a block can indicate a higher address to which a continuation capture can extend. * vm.c (vm_block): Publish the address one byte past the virtual machine state as the stack bottom for continuations.
* Copyright year bump 2018.Kaz Kylheku2018-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, buf.c, buf.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, ffi.c, ffi.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, itypes.c, itypes.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, protsym.c, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/doloop.tl, share/txr/stdlib/error.tl, share/txr/stdlib/except.tl, share/txr/stdlib/ffi.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/keyparams.tl, share/txr/stdlib/op.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/pmac.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/stream-wrap.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.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, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, strudel.c, strudel.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, win/cleansvg.txr: Extended Copyright line to 2018.
* txr -i honored despite parse-time exception.Kaz Kylheku2017-09-061-0/+11
| | | | | | | | | | | | | | | | | | | | | If an error is thrown while parsing a .txr file or while reading and evaluating the forms of a .tl file. * parser.y (parse_once, parse): Wording change in message when exception is caught. Only exceptions derived from error are caught. * txr.c (parse_once_noerr, read_eval_stream_noerr): New static functions. (txr_main): Use parse_once_noerr and read_eval_stream_noerr instead of parse_once and read_eval_stream. Don't exit if a TXR file has parser errors; in that situation, exit only if interactive mode is not requested, otherwise go interactive. Make sure *self-path* is registered to the name of the input source in this case also. * unwind.h (ignerr_func_body): New macro.
* Get continuations working on aarch64.Kaz Kylheku2017-08-161-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * unwind.c (UW_CONT_FRAME_BEFORE, UW_CONT_FRAME_AFTER): New preprocessor symbols. (revive_cont): The "frame slack" zero-filled padding logic is replaced by capturing an actual part of the real stack before the uw_stack unwind frame. On aarch64, there is content there we must actually capture. Experiment shows that exactly 128 bytes is enough, and that corresponds to the frame_slack value. (capture_cont): Capture UW_CONT_FRAME_BEFORE bytes before the uw_stack unwind frame location. Also, the "capture_extra" is replaced by UW_CONT_FRAME_AFTER constant, to harmonize. * unwind.h (UW_FRAME_ALIGN): New preprocessor symbol. (union uw_frame): On aarch64, we ask the compiler, via a GCC-specific attribute syntax, to align the address of frame objects to a 16 byte boundary. This solves a crash in the continuation code. Continuation capture is keyed to unwind frame addresses. When a captured continuation is revived onto the stack, the delta between its original address and the revive address must be a multiple of 16. The reason is that this preserves the stack and frame pointer alignment. Certain instructions on the aarch64, require the stack pointer to be 16 byte aligned. There are other ways we could achieve this, but the easiest is to align the original frames to 16 bytes.
* Restore package and package alist in handlers.Kaz Kylheku2017-03-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When setting up a handler frame, we note down the current package alist and package in the frame. Then when invoking the handler, we rebind the *package* and *package-alist* special variables. This is a needed security measure for sandboxing. Since handlers do not unwind (and therefore do not restore special variables) a handler in sandboxed code could catch an exception from non-sandboxed code that has changed *package* or *package-alist*, and take advantage of those changed values to escape from the sandbox. * unwind.c (uw_push_handler): Store current package and package-alist into new fields in the handler frame. (invoke_handler): Set up a new dynamic environment and bind *package* and *package-alist* around the handler call, to the values noted in the frame. Thus the handler executes with whatever package context was current when the handler was established. * unwind.h (struct uw_handler): New members, package and package_alist. * txr.1: Add paragraph to Exception Handling about this issue.
* Use non-hacky representation for deferrable warnings.Kaz Kylheku2017-02-101-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Deferrable warnings now get their own subtype, defr-warning. The tag is a regular argument: no funny dotted argument list. * eval.c (eval_defr_warn): Throw new style deferrable warning. (me_op, no_warn_expand): Catch defr-warning rather than warning. Use uw_muffle_warning to suppress it. (gather_free_refs): Parse new representation of deferrable warning. (expand_with_free_refs): Catch defr-warning rather than warning. * lib.c (defr_warning_s): New symbol variable defined. (obj_init): Initialize defr_warning_s. * lib.h (defr_warning_s): Declared. * share/txr/stdlib/error.tl (compile-defr-warning): Throw new-style deferrable warning. * unwind.c (uw_muffle_deferrable_warning): Function removed. (uw_throw): Bugfix: handle warnings by checking by subtype rather than exactly for the warning type. Distinguish deferrable warnings by subtype rather than argument list shape. (uw_defer_warning): Take the new style args and reconstruct the (msg . tag) representation for a deferred warning, so the other functions don't have to change. (uw_late_init): Register defr-warning as exception subtype of warning. * unwind.h (uw_muffle_deferrable_warning): Decl removed. * txr.1: Adjusted all documentation touching on the subject of the representation of deferrable warnings.
* Better way for releasing deferred warnings.Kaz Kylheku2017-02-101-0/+1
| | | | | | | | | | | | | | | | | | | | We should be re-throwing deferred warnings as ordinary warnings, not dumping them to a stream. * eval.c (eval_exception): Use uw_release_deferred_warnings instead of uw_dupm_deferred_warnings. (load): Likewise. * parser.c (read_eval_ret_last): Likewise. * txr.c (txr_main): Likewise. * unwind.c (uw_release_deferred_warnings): New function. * unwind.h (uw_release_deferred_warnings): Declared. * txr.1: Documented release-deferred-warnings and updated documentation for dump-deferred-warnings.
* Muffle only deferrable warnings in sys:expand.Kaz Kylheku2017-02-091-0/+1
| | | | | | | | | | | | | | | | | The problem is that if some macrology is performing its own expansion with sys:expand, and if all warnings are muffled in sys:expand, it means that some warnings will never be seen. Expansion is the last chance to produce warnings issued by macros. Once they are expanded, a redundant expansion pass won't issue the warnings any more. * eval.c (no_warn_expand); Use the uw_muffle_deferrable_warning handler isntead of uw_muffle_warnings. * unwind.c (uw_muffle_deferrable_warning): New function. * unwind.h (uw_muffle_deferrable_warning): Declared.
* Bump copyright year to 2017.Kaz Kylheku2017-01-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * LICENSE, LICENSE-CYG, 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, ftw.c, ftw.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, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/getopts.tl, share/txr/stdlib/getput.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/package.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/tagbody.tl, share/txr/stdlib/termios.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: Add 2017 to all copyright headers and strings.
* Extend deferred warnings system with tentative defs.Kaz Kylheku2017-01-151-0/+2
| | | | | | | | | | | | | | | | | | | | Tentative defs record the fact that some definition has been seen at expansion time, even though that definition has not been put into effect. They suppress warnings. * unwind.c (tentative_defs): New static variable. (uw_defer_warning): Throw away the warning if it matches a tentative def. (uw_register_tentative_def, uw_tentative_def_exists): New functions. (uw_dump_deferred_warnings): Purge the tag from the list of deferred defs also. (uw_init): gc-protect tentative_defs. Register intrinsics register-tentative-def and tentative-def-exists. * unwind.h (uw_register_tentative_def, uw_tentative_def_exists): Declared.
* Deferred warnings.Kaz Kylheku2017-01-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Warnings about undefined functions and variables are now deferred during loading, so forward references do not generate nuisance diagnostics. * eval.c (load_recursive_s): New symbol variable. (eval_defr_warn): New static function. (op_defvarl, op_defun): Purge any deferred warning about the given function or variable not being defined. (load): Rebind the sys:*load-recursive* special var to true around the load. After the load, dump deferred warnings if the prior binding of sys:*load-recursive* is false. Discard deferred warnings in the case of termination by a nonlocal control transfer. (do_expand): Treat unbound vars and functions as deferrable warnings, specially tagged for individual purging frkm the deferred list. (eval_init): Intern sys:*load-recursive* and initialize load_recursive_s variable. * eval.h (load_recursive_s): Declared. * parse.c (repl_warning): Accept variable arguments. Check whether we are loading and if so, defer deferrable (repl): Adjustment for altered signature of repl_warning. warnings. * txr.c (txr_main): dump deferred warnings after evaluating Lisp stream. * unwind.c (deferred_warnings): New static variable. (uw_throw): When a deferrable warning is caught, suppress the usual message and add it to the deferred_warnings list. (uw_defer_warning, uw_dump_deferred_warnings, uw_dump_deferred_warnings, uw_purge_deferred_warnings): New functions. (uw_late_init): gc-protect deferred_warnings. * unwind.h (uw_defer_warning, uw_dump_deferred_warnings, uw_dump_deferred_warnings, uw_purge_deferred_warnings): New functions declared.
* New function: find-frames.Kaz Kylheku2016-12-201-0/+1
| | | | | | | | | | | | | * unwind.c (uw_find_frames_impl): New static function, made from uw_find_frame. (uw_find_frame): Reduced to wrapper around uw_find_frames_impl. (uw_find_frames): New function. (uw_late_init): Register find-frames intrinsic. * unwind.h (uw_find_frames): Declared. * txr.1: Documented.
* Eliminate duplicated warning-suppressing function.Kaz Kylheku2016-11-281-0/+1
| | | | | | | | | | | | | | * eval.c (warning_continue): Static function removed. (no_warn_expand): Use uw_muffle_warning instead of removed function. * parser.y (warning_continue): Static function removed. (parse_once): Use uw_muffle_warning instead of removed function. * unwind.c (uw_muffle_warning): New function. * unwind.h (uw_muffle_warning): Declared.
* Let guard frames optionally pass through unwinding.Kaz Kylheku2016-10-261-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | We have a bug in that when an exception occurs in a context called from obj_print, the guard for stopping continuation captures across obj_print also unintentially blocks the unwinding. Let's make the unwinding blockage optional * unwind.c (uw_unwind_to_exit_point): If a UW_GUARD is encountered, do not abort if the uw_ok flag is set; keep unwinding. (uw_push_guard): New uw_ok argument, initializes the uw_ok member of a guard frame. * unwind.h (struct uw_guard): New struct type. (union uw_frame): New member gu of type struct uw_guard. (uw_push_guard): Declaration updated. * ftw.c (ftw_callback): Pass zero as new uw_push_guard argument: no unwinding across the POSIX library function ftw. * glob.c (errfunc_thunk): Likewise, no unwinding across the library function glob. * lib.c (obj_print): Pass 1 as new uw_push_guard argument: continuations can't be captured, but unwinding is okay.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-011-16/+17
| | | | | | | | | | | | | | | | | | | | * 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, ftw.c, ftw.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/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.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/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.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, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* Adding panic macro, which throws a panic exception.Kaz Kylheku2016-05-071-0/+10
| | | | | | | | | | | * 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.
* Harden glob: continuations, exceptions, re-entry.Kaz Kylheku2016-04-111-0/+3
| | | | | | | | | | | | | | | | | | | * glob.c (s_exit_point): New static variable. (errfunc_thunk): Set up a continuation guard frame, so the error function cannot capture a continuation across glob's stack frames. Intercept all unwinding with a simple unwind block, save the exit point in the global variable and then stop the unwinding by setting the unwind frame's exit point to null. (glob_wrap): Check for glob being re-entered and throw error if so. If the glob callback bailed due to unwinding (as seen by a non-null value in the exit point global variable), clean up the glob memory with globfree and continue the unwinding to the exit point. unwind.h (uw_curr_exit_point): New macro for accessing saved exit point in pure unwind frame.
* Remove frame popping action from uw_continue.Kaz Kylheku2016-04-111-4/+3
| | | | | | | | | | | | * 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.
* New frame type to block bad unwinding and cont capture.Kaz Kylheku2016-04-081-1/+2
| | | | | | | | | | | | | | | | | | 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.
* 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.
* Copy envs for middle-of-binding continuations.Kaz Kylheku2015-11-051-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Implementing sys:abscond-from operator.Kaz Kylheku2015-10-281-0/+1
| | | | | | | | | | | | | | | | | | | | | * 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-1/+1
| | | | | | | | | | | | | | * 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.
* Move noreturn macro.Kaz Kylheku2015-10-281-6/+0
| | | | | | * lib.h (noreturn): Defined here. * unwind.h (noreturn): Removed from here.
* TXR gets delimited continuations.Kaz Kylheku2015-10-251-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Adding find-frame function.Kaz Kylheku2015-10-151-0/+1
| | | | | | | | | | | | * 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-0/+2
| | | | | | | | | | | | | | * 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-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Use of new args for function calls in interpreter.Kaz Kylheku2015-08-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Slight internal representation change of string-only exceptions.Kaz Kylheku2015-02-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+1
| | | | | | | | | | | | | | | | | | | (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.
* * unwind.h (uw_block_begin): Get rid of the unused typedef trick,Kaz Kylheku2014-07-261-3/+3
| | | | | | | replace with do { } while (0), since we don't have any instances of a uw_block_begin followed by declarations. (uw_catch_begin): Move SYMVAR and EXCVAR inside the do/while block, so that the expansion doesn't begin with a declaration.
* * 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.
* * Makefile: install the LICENSE and METALICENSE files into the dataKaz Kylheku2014-07-071-0/+1
| | | | | | | | | | | | directory. * txr.c (help): Help text updated to document --license option. (license): New function. (txr_main): Implement --license option. * unwind.h (uw_catch): Add cast to suppress warning about unused symbol. * txr.1: Document --license option.
* * eval.c (op_dwim): Gutted down to just a few lines.Kaz Kylheku2014-02-061-13/+0
| | | | | | | | | | | | Basically the dwim operator is just a Lisp-1 version of the call operator now. It doesn't have to do anything funny with non-function objects, since they are callable. * lib.c (chr_str, chr_str_set, vecref, vecref_l): Replace inappropriate internal assertions with error exceptions. * unwind.h (numeric_assert, range_bug_unless): Unused macros removed.
* First cut at signal handling support.Kaz Kylheku2013-12-121-23/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Bumping copyrights to 2014 and expressing them as year ranges.Kaz Kylheku2013-12-101-1/+1
| | | | Fixing some errors in copyright comments.