summaryrefslogtreecommitdiff
path: root/libguile/control.c
AgeCommit message (Collapse)AuthorFilesLines
2011-07-28fix list validation bug in @abortAndy Wingo1-1/+2
* libguile/control.c (scm_at_abort): Fix to ensure that we store the return of scm_ilength in a signed integer, even if later we copy it to an unsigned. See http://article.gmane.org/gmane.lisp.guile.devel/12685.
2011-05-13more care regarding SCM_PACK and SCM_UNPACKAndy Wingo1-1/+1
* libguile/control.c (reify_partial_continuation): * libguile/eval.c (RETURN_BOOT_CLOSURE): * libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x) * libguile/frames.h (SCM_FRAME_SET_RETURN_ADDRESS): (SCM_FRAME_SET_MV_RETURN_ADDRESS, SCM_FRAME_SET_DYNAMIC_LINK): * libguile/goops.c (scm_class_of, scm_primitive_generic_generic) (scm_c_extend_primitive_generic, compute_getters_n_setters) (scm_sys_initialize_object): * libguile/guardians.c (finalize_guarded): * libguile/list.c (SCM_I_CONS): * libguile/macros.c (scm_i_make_primitive_macro) (scm_make_syntax_transformer): * libguile/memoize.c (MAKMEMO, SCM_MAKE_MEMOIZER) (SCM_MAKE_REST_MEMOIZER): * libguile/modules.c (scm_module_reverse_lookup) * libguile/print.c (iprin1): * libguile/promises.c (scm_make_promise) * libguile/srcprop.c (scm_make_srcprops): * libguile/vectors.c (scm_c_vector_ref): * libguile/vm-engine.c (vm_engine) * libguile/vm-i-scheme.c (REL, add1, sub1): * libguile/vm-i-system.c (new_frame, call_cc) * libguile/weaks.h (SCM_WEAK_PAIR_WORD_DELETED_P): Be more careful about SCM_PACK / SCM_UNPACK.
2011-03-29fix prompt and abort with the boot evaluatorAndy Wingo1-4/+4
* libguile/control.h: * libguile/control.c (scm_i_prompt_pop_abort_args_x): Take a VM instead of a prompt, given that it's the VM's registers that record the abort arguments, not the prompt registers (which actually point right below the abort values). * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Pass the vm instead of a prompt.
2011-01-27objcode type is an enumeration, not flagsAndy Wingo1-2/+2
* libguile/objcodes.h (SCM_OBJCODE_TYPE_MMAP) (SCM_OBJCODE_TYPE_BYTEVECTOR, SCM_OBJCODE_TYPE_SLICE) (SCM_OBJCODE_TYPE_STATIC): Enumerate objcode types instead of expressing them as flags. (SCM_OBJCODE_TYPE): Type is held in bits 8-15. (SCM_OBJCODE_FLAGS): Flags are now shifted by 16 bits, not 8. (SCM_MAKE_OBJCODE_TAG): New helper. * libguile/continuations.c (STATIC_OBJCODE_TAG): * libguile/control.c (STATIC_OBJCODE_TAG): * libguile/foreign.c (STATIC_OBJCODE_TAG): * libguile/gsubr.c (STATIC_OBJCODE_TAG): * libguile/smob.c (STATIC_OBJCODE_TAG): * libguile/objcodes.c (make_objcode_by_mmap, scm_c_make_objcode_slice) (scm_bytecode_to_objcode): : Use SCM_MAKE_OBJCODE_TAG.
2010-11-19Include <alloca.h> wherever `alloca' is used.Ludovic Courtès1-0/+2
Patch provided by <carlo.bramix@libero.it> (tiny change). * libguile/control.c, libguile/fluids.c, libguile/foreign.c, libguile/hashtab.c, libguile/strings.c: Include <alloca.h>.
2010-09-27Have `@abort' honor VM changes by winds.Ludovic Courtès1-1/+5
* libguile/control.c (scm_c_abort): Update VM after the `scm_dowinds' call. * test-suite/tests/control.test ("the-vm"): New test prefix.
2010-07-17use scm_malloc_pointerless to alloc aligned blocks in fallbackAndy Wingo1-5/+4
* libguile/continuations.c (SCM_DECLARE_STATIC_ALIGNED_ARRAY) (SCM_STATIC_ALIGNED_ARRAY) * libguile/control.c (SCM_DECLARE_STATIC_ALIGNED_ARRAY) (SCM_STATIC_ALIGNED_ARRAY): Tweak backslashes. Use scm_malloc_pointerless to ensure alignment.
2010-05-30Fix parenthesizing of the `ROUND_UP' macro; factorize.Ludovic Courtès1-1/+0
* libguile/_scm.h (ROUND_UP): New macro. * libguile/continuations.c (ROUND_UP): Remove. * libguile/control.c (ROUND_UP): Remove. * libguile/foreign.c (ROUND_UP): Remove.
2010-03-11add abort to unknown prompt testAndy Wingo1-1/+1
* libguile/control.c (scm_c_abort): Change error string if a prompt isn't found. * test-suite/tests/control.test ("abort to unknown prompt"): New test.
2010-03-11remove internal treatment of default prompt tag, it seems there was no needAndy Wingo1-17/+2
* libguile/control.h (scm_sys_default_prompt_tag): * libguile/control.c (scm_init_control): Remove the logic that defined %default-prompt-tag. (scm_c_abort): Remove check for default prompt tag, it wasn't useful. * libguile/throw.c (sym_pre_init_catch_tag): Define as the pre-init prompt tag. (pre_init_catch, pre_init_throw): Use sym_pre_init_catch_tag. * module/ice-9/boot-9.scm (default-prompt-tag): Define as a simple value, not a fluid. Perhaps we can expose it as a fluid later.
2010-03-04partial continuations print as #<partial-continuation ...>Andy Wingo1-1/+1
* libguile/control.c (reify_partial_continuation): * libguile/programs.c (scm_i_program_print): * libguile/programs.h (SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION) (SCM_PROGRAM_IS_PARTIAL_CONTINUATION): Distinguish partial continuations from full continuations.
2010-03-04add printers for prompts and with-fluids objectsAndy Wingo1-0/+8
* libguile/control.c: * libguile/control.h (scm_i_prompt_print): * libguile/fluids.c: * libguile/fluids.h (scm_i_with_fluids_print): * libguile/print.c (iprin1): Add printers for prompts and with-fluids objects.
2010-03-02Use libguile/control.x explicitly.Ken Raeburn1-1/+1
2010-02-26rewinding prompts worksAndy Wingo1-8/+4
* libguile/control.h (SCM_PROMPT_HANDLER): Remove, it was unused. (SCM_PROMPT_DYNWINDS): Rename from SCM_PROMPT_DYNENV. * libguile/control.c: (scm_c_make_prompt): Take another arg, the winds that are to be in place for the prompt. Fix allocation to be 4 words instead of 5 (the handler was never used). * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt to scm_c_make_prompt change. * libguile/vm-i-system.c (partial-cont-call): Grovel the new elements of the wind list in order to call setjmp() on the new prompts. Pass cookie to vm_reinstate_partial_continuation. (prompt): Adapt to scm_c_make_prompt change. * libguile/vm.c (vm_reinstate_partial_continuation): Take a cookie arg, used when winding captured prompts onto the stack. Winding a prompt implies making a new prompt, actually -- with new registers, a new jump buffer, new winds, etc. * test-suite/tests/control.test ("rewinding prompts"): Add a test for rewinding prompts.
2010-02-26fix a prompt bugAndy Wingo1-6/+6
* libguile/control.h: * libguile/control.c (scm_c_make_prompt): Instead of taking a VM arg, take the registers directly. (scm_c_abort): Declare as returning void. In fact it will never return. * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt to prompt API change. * libguile/vm-i-system.c (prompt): Pass the abort ip as the ip to scm_c_make_prompt. This fixes a bug in which we used the "offset" local var, but it wasn't guaranteed to be around after a longjmp.
2010-02-25simplify handling of nonlocal prompt returns from cAndy Wingo1-0/+20
* libguile/control.h: * libguile/control.c (scm_i_prompt_pop_abort_args_x): New helper. * libguile/eval.c (eval): Use the new helper.
2010-02-24fix escape-only promptsAndy Wingo1-1/+1
* libguile/control.c (scm_c_make_prompt): Whoops, set the escape-only flag properly here.
2010-02-24add %default-prompt-tag, and error (not abort()) on an abort to bad tagAndy Wingo1-4/+15
* libguile/init.c (scm_i_init_guile): Call scm_init_control after initing fluids. * libguile/control.h (scm_sys_default_prompt_tag): New internal var. * libguile/control.c (scm_c_abort): If abort is called for an unknown tag, raise an exception, except if the tag was the default prompt tag, in which case really abort -- to prevent recursion when some other patches land. (scm_init_control): Define %default-prompt-tag in the default environment.
2010-02-24rewind the dynamic state when entering a partial continuationAndy Wingo1-5/+4
* libguile/control.c (cont_objcode): * libguile/vm-i-system.c (partial-cont-call): * libguile/vm.c (vm_reinstate_partial_continuation): Don't keep the "external winds" in a partial continuation, as they aren't logically part of the continuation. Reinstate the "internal winds" when entering a partial continuation. Things seem to work!
2010-02-24record IP in partial continuationsAndy Wingo1-3/+12
* libguile/control.c (reify_partial_continuation): Assert some invariants, and record the IP as the MVRA of the continuation.
2010-02-22actually capture partial continuationsAndy Wingo1-4/+113
* libguile/control.c (cont_objcode): Along with a bunch of boilerplate that certainly needs to go in some central place, define this continuation-calling trampoline. (reify_partial_continuation): New function, returns a procedure that when called will reinstate a partial continuation. (scm_c_abort): Take an extra arg, the cookie. Actually reify a continuation. (scm_at_abort): Adapt to scm_c_abort change. * libguile/control.h: Declare scm_c_abort change. * libguile/vm-i-system.c (partial_cont_call): New instruction. (call/cc, tail-call/cc): Adapt to scm_i_vm_capture_stack change. (abort): Pass vm_cookie to abort. * libguile/vm.h (SCM_F_VM_CONT_PARTIAL, SCM_F_VM_CONT_REWINDABLE): New flags. (struct scm_vm_cont): Add flags field. (SCM_VM_CONT_PARTIAL_P, SCM_VM_CONT_REWINDABLE_P): New predicates. * libguile/vm.c (scm_i_vm_capture_stack): Rename from vm_capture_continuation, and make internal instead of static. Take a flags argument. (scm_i_vm_capture_continuation): Adapt to scm_i_vm_capture_stack change. (vm_abort): Plumb cookie to scm_c_abort. (vm_reinstate_partial_continuation): New stub.
2010-02-22abort always dispatches to VM bytecode, to detect same-invocation abortsAndy Wingo1-20/+10
* libguile/control.h: * libguile/control.c (scm_c_make_prompt): Take an extra arg, a cookie. Continuations will be rewindable only if the abort has the same cookie as the prompt. (scm_at_abort): Redefine from scm_abort, and instead of taking rest args, take the abort values as a list directly. Also, don't allow rewinding, because we won't support rewinding the C stack with delimited continuations. * libguile/eval.c (eval): Adapt to scm_c_make_prompt change. * libguile/vm-engine.c (vm_engine): Use vp->cookie to get a unique value corresponding to this VM invocation. * libguile/vm-i-system.c (prompt): Pass the cookie to scm_c_make_prompt. (abort): Take an additional tail arg. * libguile/vm.c (vm_abort): Parse out the abort tail arg. This is for the @abort case, or the (apply abort ...) case. (make_vm): Initialize the cookie to 0. * libguile/vm.h (struct scm_vm): Add cookie. * module/ice-9/boot-9.scm (abort): Define here as a trampoline to @abort. Needed to make sure that a call to abort dispatches to a VM opcode, so the cookie will be the same. * module/language/tree-il.scm (<tree-il>): Add a "tail" field to <abort>, for the (apply abort ...) case, or (@abort tag args). Should be #<const ()> in the normal case. Add support throughout. * module/language/tree-il/analyze.scm (analyze-lexicals): Add abort-tail support here too. * module/language/tree-il/compile-glil.scm (flatten): Compile the tail argument appropriately. * module/language/tree-il/primitives.scm (*primitive-expand-table*): Fix @abort and abort cases to pass the tail arg to make-abort.
2010-02-19prompt as part of guile's primitive languageAndy Wingo1-36/+34
* libguile/control.h: * libguile/control.c: Remove scm_atcontrol and scm_atprompt. (scm_c_make_prompt): Remove handler arg, as the handler is inline. (scm_abort): New primitive, exported to Scheme as `abort'. The compiler will also recognize calls to `abort', but this is the base case. (scm_init_control): Remove scm_register_control, just have this function, which adds `abort' to the `(guile)' module. * libguile/eval.c (eval): Add SCM_M_PROMPT case. * libguile/init.c (scm_i_init_guile): Change scm_register_control call into a nice orderly scm_init_control call. * libguile/memoize.h: (scm_sym_at_prompt, SCM_M_PROMPT): * libguile/memoize.c (MAKMEMO_PROMPT, scm_m_at_prompt, unmemoize): Add prompt support to the memoizer. * libguile/vm-i-system.c (prompt): Fix to not expect a handler on the stack. * module/ice-9/boot-9.scm (prompt): Add definition in terms of @prompt. * module/ice-9/control.scm: Simplify, and don't play with the compiler here, now that prompt and abort are primitive. * module/ice-9/eval.scm (primitive-eval): Add a prompt case. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): Add @prompt and prompt.
2010-02-19add scm_c_abort, wire it up to the abort opcodeAndy Wingo1-0/+58
* libguile/control.h: * libguile/control.c (scm_c_abort): Add an implementation of `abort', but it doesn't reify the continuation yet. * libguile/vm-i-system.c (abort): * libguile/vm.c (vm_abort): Wire up the call to `abort', avoiding consing the args into a list. * module/language/tree-il/compile-glil.scm (flatten): Add some compily bits that can allow the abort to be resumed.
2010-02-19prompt handlers are always inlineAndy Wingo1-4/+1
* libguile/control.h (SCM_F_PROMPT_INLINE, SCM_PROMPT_INLINE_P): Remove; prompts always have "inline" handlers now. * libguile/control.c (scm_c_make_prompt): Remove inline_handler_p arg. * libguile/vm-i-system.c (prompt): * module/language/assembly/decompile-bytecode.scm (decode-load-program): * module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt to prompt changes. * module/language/glil.scm (make-glil-prompt, glil-prompt-inline?): Remove inline? flag. (parse-glil, unparse-glil): * module/language/glil/compile-assembly.scm (glil->assembly): Adapt to <glil-prompt> change. * module/language/tree-il/compile-glil.scm (flatten): Require the handler of a <prompt> to be a lambda-case. * module/language/tree-il/primitives.scm (*primitive-expand-table*): Ensure that the handler of a <prompt> is a lambda-case. * module/language/tree-il/inline.scm (inline!): Simplify a degenerate case: (lambda args (apply (lambda ...) args)) => (lambda ...).
2010-02-19<prompt> has no pre-unwind-handler, it's unnecessaryAndy Wingo1-5/+4
* libguile/control.h: * libguile/control.c (scm_c_make_prompt, SCM_PROMPT_PRE_UNWIND_HANDLER): * libguile/vm-i-system.c (prompt) * module/language/tree-il.scm (<prompt> prompt-pre-unwind-handler): * module/language/tree-il/analyze.scm: * module/language/tree-il/compile-glil.scm: * module/language/tree-il/inline.scm: * module/language/tree-il/primitives.scm: Remove the "pre-unwind" handler from prompt; it turns out not to be necessary. Adapt all references.
2010-02-08connect a few more wires to promptensteinAndy Wingo1-0/+31
* libguile/tags.h (scm_tc7_prompt): Allocate a tc7 for prompt objects. * libguile/control.h (SCM_F_PROMPT_INLINE, SCM_F_PROMPT_ESCAPE) (SCM_PROMPT_P, SCM_PROMPT_FLAGS, SCM_PROMPT_INLINE_P) (SCM_PROMPT_ESCAPE_P, SCM_PROMPT_TAG, SCM_PROMPT_REGISTERS) (SCM_PROMPT_DYNENV, SCM_PROMPT_HANDLER) (SCM_PROMPT_PRE_UNWIND_HANDLER, SCM_PROMPT_SETJMP) (struct scm_prompt_registers): * libguile/control.c (scm_c_make_prompt): Flesh out a simple prompts implementation. * libguile/vm-i-system.c (prompt): Wire up the implementation. * libguile/vm.c: Add a needed #include.
2010-01-31add @control and @prompt stub primitivesAndy Wingo1-0/+72
* libguile/Makefile.am: * libguile/control.c: * libguile/control.h: * libguile/init.c: Add stub @control and @prompt primitives, for use when bootstrapping (ice-9 control).