summaryrefslogtreecommitdiff
path: root/libguile/control.c
Commit message (Expand)AuthorAgeFilesLines
* VM continuations store FP/SP by offset...* libguile/continuations.c (scm_i_continuation_to_frame): * libguile/stacks.c (scm_make_stack): * libguile/vm.c (scm_i_vm_cont_to_frame, scm_i_vm_capture_stack): (vm_return_to_continuation_inner) (struct vm_reinstate_partial_continuation_data): (vm_reinstate_partial_continuation_inner): (vm_reinstate_partial_continuation): * libguile/vm.h (sstruct scm_vm_cont): Simplify VM continuations by recording the top FP by offset, not value + reloc. * libguile/frames.c (frame_offset, scm_i_vm_frame_offset): Remove unused functions. * libguile/frames.h (SCM_VALIDATE_VM_FRAME, scm_i_vm_frame_offset): Remove. * libguile/control.c (reify_partial_continuation): Once we know the base_fp, relocate the dynamic stack. * libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_relocate_prompts): New function. (scm_dynstack_wind_prompt): Adapt to add new fp offset. Andy Wingo2017-02-121-0/+2
* Add suspendable-continuation?...* doc/ref/api-control.texi (Prompt Primitives): Document suspendable-continuation?. * libguile/control.c (scm_suspendable_continuation_p): New procedure. (scm_init_ice_9_control): New extension procedure, defines suspendable-continuation?. (scm_init_control): Register scm_init_ice_9_control. * libguile/eval.c (eval): * libguile/throw.c (catch): * libguile/continuations.c (scm_i_make_continuation): Restore resumable prompt cookie after continuation invocation. * libguile/vm.c (scm_call_n): Arrange to set resumable_prompt_cookie during invocation of VM. * libguile/vm.h (struct scm_vm): Add resumable_prompt_cookie member. * module/ice-9/control.scm: Export suspendable-continuation?. * test-suite/tests/control.test ("suspendable-continuation?"): New test. Andy Wingo2016-12-121-0/+25
* Rename union scm_vm_stack_element members...* libguile/frames.h (union scm_vm_stack_element): Rename members from scm, ip, etc to as_scm, as_ip, etc. Adapt users. Andy Wingo2015-10-211-3/+3
* VM stack grows downward...Adapt VM stack to grow downward. This will make native compilation look more like the VM code, as we will be able to use native CALL instructions, taking proper advantage of the return address buffer. * libguile/continuations.c (scm_i_continuation_to_frame): Record offsets from stack top. * libguile/control.c (scm_i_prompt_pop_abort_args_x): Adapt for reversed order of arguments, and instead of relying on the abort to push on the number of arguments, make the caller save the stack depth, which allows us to compute the number of arguments ourselves. (reify_partial_continuation, scm_c_abort): Adapt to reversed stack order. * libguile/dynstack.c (scm_dynstack_wind_prompt): Since we wind the stack in a downward direction, subtract the reloc instead of adding it. * libguile/dynstack.h (SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY): Remove flag; instead rely on prompt-establishing code to save the stack depth. * libguile/eval.c (eval): Remove extraneous "volatile" declarations for variables that are not re-set between the setjmp and any longjmp. Adapt to save stack depth before instating the prompt. * libguile/foreign.c (scm_i_foreign_call): Adapt to receive arguments in reverse order. * libguile/frames.c (frame_stack_top, scm_i_frame_stack_top): Adapt to compute stack top instead of stack bottom. (scm_c_frame_closure): Adapt to stack growth change. (scm_frame_num_locals, scm_frame_local_ref, scm_frame_set_x): Use union data type to access stack. (RELOC): Reformat. (scm_c_frame_previous): Adapt to stack growth change. * libguile/frames.h: Adapt stack diagram to indicate that the stack grows up. (union scm_vm_stack_element): New data type used to access items on the stack. (SCM_FRAME_PREVIOUS_SP) (SCM_FRAME_RETURN_ADDRESS, SCM_FRAME_SET_RETURN_ADDRESS) (SCM_FRAME_DYNAMIC_LINK, SCM_FRAME_SET_DYNAMIC_LINK) (SCM_FRAME_LOCAL, SCM_FRAME_NUM_LOCALS): Adapt to stack representation change. (SCM_FRAME_SLOT): New helper. (SCM_VM_FRAME_FP, SCM_VM_FRAME_SP): Adapt to stack growth change. * libguile/stacks.c (scm_make_stack): Record offsets from top of stack. * libguile/throw.c (catch): Adapt to scm_i_prompt_pop_abort_args_x change. * libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME): (FRAME_LOCALS_COUNT_FROM): Adapt to stack growth change. (LOCAL_ADDRESS): Use SCM_FRAME_SLOT to get the address as the proper data type. (RETURN_ONE_VALUE, RETURN_VALUE_LIST): Adapt to stack growth change. (apply): Shuffling up the SMOB apply args can cause the stack to expand, so use ALLOC_FRAME instead of RESET_FRAME. (vm_engine): Adapt for stack growth change. * libguile/vm.c (vm_increase_sp, vm_push_sp, vm_restore_sp): Adapt to stack representation change. (scm_i_vm_cont_to_frame): Adapt to take offsets from the top. (scm_i_vm_capture_stack): Adapt to capture from the top. (vm_return_to_continuation_inner): Adapt for data type changes. (vm_return_to_continuation): Likewise, and instead of looping, just splat the saved arguments on with memcpy. (vm_dispatch_hook): Adapt to receive arguments in the reverse order. Adapt callers. (vm_abort): There is never a tail argument. Adapt to stack representation change. (vm_reinstate_partial_continuation) (vm_reinstate_partial_continuation_inner): Adapt to stack growth change. (allocate_stack, free_stack): Adapt to data type change. (expand_stack): Don't try to mremap(), as you can't grow a mapping from the bottom. Without knowing that there's a free mapping space right below the old stack, which there usually isn't on Linux, we have to copy. We can't use MAP_GROWSDOWN because Linux is buggy. (make_vm): Adapt to stack representation changes. (return_unused_stack_to_os): Round down instead of up, as the stack grows down. (scm_i_vm_mark_stack): Adapt to walk up the stack. (scm_i_vm_free_stack): Adapt to scm_vm changes. (vm_expand_stack_inner, reset_stack_limit, vm_expand_stack): Adapt to the stack growing down. (scm_call_n): Adapt to the stack growing down. Don't allow argv to point into the stack. * libguile/vm.h (struct scm_vm, struct scm_vm_cont): Adapt to hold the stack top and bottom. Andy Wingo2015-10-211-32/+29
* scm_the_vm now returns raw struct scm_vm pointer...* libguile/vm.h (scm_the_vm): Return struct scm_vm*. (scm_c_vm_run): Remove. * libguile/control.c: * libguile/eval.c: * libguile/throw.c: * libguile/vm.c: Adapt. Andy Wingo2013-11-211-1/+1
* scm_i_prompt_pop_abort_args_x takes struct scm_vm* as arg...* libguile/control.h: * libguile/control.c (scm_i_prompt_pop_abort_args_x): Change to take VP as an arg, not VM. * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): Adapt. Andy Wingo2013-11-211-4/+4
* Remove last use of SCM vm in VM...* libguile/control.h: * libguile/control.c (reify_partial_continuation, scm_c_abort): Take struct scm_vm *vp as an arg. * libguile/dynstack.h: Remove control.h include. * libguile/vm.c (vm_abort): Take struct scm_vm *vp as an arg. * libguile/vm-engine.c (abort): Adapt to vm_abort change. Andy Wingo2013-11-211-21/+17
* The dynamic stack records SP and FP values as offsets...* libguile/dynstack.h: * libguile/dynstack.c (PROMPT_FP, PROMPT_SP): (scm_dynstack_push_prompt, scm_dynstack_find_prompt): Prompts on the dynstack are recorded as offsets from the base stack address in this thread. * libguile/control.c (scm_c_abort): * libguile/eval.c (eval): * libguile/stacks.c (find_prompt, narrow_stack): * libguile/throw.c (pre_init_catch): * libguile/vm-engine.c (prompt): Adapt. Andy Wingo2013-11-211-1/+6
* Change SCM_PACK_RTL macros to SCM_PACK_OP / SCM_PACK_OP_ARG...* libguile/instructions.h: Guard in BUILDING_LIBGUILE. (SCM_PACK_OP_24): (SCM_PACK_OP_8_8_8): (SCM_PACK_OP_8_16): (SCM_PACK_OP_16_8): (SCM_PACK_OP_12_12): Rename from SCM_PACK_RTL_*, and splice in the opcode. (SCM_PACK_OP_ARG_8_24): New helper. * libguile/vm.c: * libguile/gsubr.c: * libguile/foreign.c: * libguile/control.c: * libguile/continuations.c: Adapt. Andy Wingo2013-11-191-1/+1
* scm_rtl_op_* -> scm_op_*...* libguile/instructions.h (scm_opcode): Rename from scm_rtl_opcode. Rename opcodes from scm_rtl_op_* to scm_op_*. * libguile/continuations.c: * libguile/control.c: * libguile/foreign.c: * libguile/gsubr.c: * libguile/instructions.c: * libguile/vm.c: Adapt. Andy Wingo2013-11-191-1/+1
* Remove RTL_ infix from macros...* libguile/programs.h (SCM_PROGRAM_P): (SCM_PROGRAM_CODE): (SCM_PROGRAM_FREE_VARIABLES): (SCM_PROGRAM_FREE_VARIABLE_REF): (SCM_PROGRAM_FREE_VARIABLE_SET): (SCM_PROGRAM_NUM_FREE_VARIABLES): (SCM_VALIDATE_PROGRAM): Remove RTL_ infix. * libguile/continuations.c: * libguile/continuations.h: * libguile/control.c: * libguile/foreign.c: * libguile/frames.c: * libguile/gsubr.c: * libguile/gsubr.h: * libguile/procprop.c: * libguile/procs.c: * libguile/programs.c: * libguile/stacks.c: * libguile/vm-engine.c: Adapt. Andy Wingo2013-11-191-1/+1
* Rename scm_tc7_rtl_program to scm_tc7_program...* libguile/tags.h (scm_tc7_program): Rename from scm_tc7_rtl_program. * libguile/continuations.c: * libguile/control.c: * libguile/evalext.c: * libguile/foreign.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/print.c: * libguile/programs.c: * libguile/programs.h: * libguile/vm-engine.c: Adapt users. * module/system/vm/assembler.scm: Rename a tc7-rtl-program local to tc7-program. * libguile/tags.h (scm_tc7_program): Rename from scm_tc7_rtl_program. * libguile/continuations.c: * libguile/control.c: * libguile/evalext.c: * libguile/foreign.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/print.c: * libguile/programs.c: * libguile/programs.h: * libguile/vm-engine.c: Adapt users. * module/system/vm/assembler.scm: Rename a tc7-rtl-program local to tc7-program. Andy Wingo2013-11-191-1/+1
* All instruction pointers are now scm_t_uint32*...* libguile/frames.h (SCM_FRAME_RTL_RETURN_ADDRESS) (SCM_FRAME_SET_RTL_RETURN_ADDRESS): Remove. The variants without _RTL now work fine. (struct scm_vm_frame): Change the return address to be a scm_t_uint32*. (struct scm_frame): Change IP to be scm_t_uint32*. * libguile/frames.c (scm_c_make_frame) * libguile/control.c (reify_partial_continuation, scm_c_abort) * libguile/dynstack.c (PROMPT_IP) (scm_dynstack_push_prompt, scm_dynstack_find_prompt) * libguile/dynstack.h: * libguile/vm-engine.c (SYNC_IP, RETURN_ONE_VALUE) (call, return-values, prompt): Adapt. Andy Wingo2013-11-191-2/+4
* Frame pointer points to local 0 instead of local 1...* libguile/frames.h: Change so that fp points at local 0 instead of local 1, and clean up a bit. (struct scm_vm_frame): Remove program, and rename stack to locals. (SCM_FRAME_DATA_ADDRESS): Remove; it was redundant with SCM_FRAME_LOWER_ADDRESS. (SCM_FRAME_STACK_ADDRESS): Remove; replace with the new SCM_FRAME_LOCALS_ADDRESS. (SCM_FRAME_UPPER_ADDRESS): Remove; unused. (SCM_FRAME_NUM_LOCALS, SCM_FRAME_PREVIOUS_SP): New defines. (SCM_FRAME_BYTE_CAST, SCM_FRAME_STACK_CAST): Remove; unused; (SCM_FRAME_LOCAL): New define, replaces SCM_FRAME_VARIABLE. (SCM_FRAME_PROGRAM): Add cautionary commentary. * libguile/frames.c: Adapt static asserts. (scm_frame_num_locals, scm_frame_local_ref, scm_frame_local_set_x): Adapt. This means that frame-local-ref 0 now returns the procedure. * libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME) (FRAME_LOCALS_COUNT, LOCAL_REF, LOCAL_SET, RETURN_VALUE_LIST): Adapt to change in fp. (LOCAL_ADDRESS): New helper. (POP_CONTINUATION_HOOK): Reimplement, taking the previous FP as an argument. (ABORT_CONTINUATION_HOOK): Reimplement, taking no arguments. (RETURN_ONE_VALUE): Reimplement. (RETURN_VALUE_LIST): Adapt to FP change. (halt, return-values, subr-call, foreign-call, prompt) (continuation-call, compose-continuation, call/cc, abort): Adapt to FP change, mostly via using LOCAL_ADDRESS, etc abstractions instead of using the raw frame pointer. * libguile/control.c (reify_partial_continuation): Update for fp change. * libguile/vm.c (vm_reinstate_partial_continuation): Adapt to removal of SCM_FRAME_UPPER_ADDRESS. * module/system/vm/frame.scm (frame-call-representation): Adapt to frame-local-ref change. * module/system/vm/trace.scm (print-return): Remove unused frame-num-locals call. Andy Wingo2013-11-171-1/+1
* Remove MVRA accessors in libguile...* libguile/vm.c (scm_i_vm_capture_stack): Remove MVRA argument, in preparation for removing MVRA from frames. (scm_i_capture_current_stack): Adapt to scm_i_vm_capture_stack change. (vm_reinstate_partial_continuation): Remove references to MVRA. * libguile/vm.h (struct scm_vm_cont): Remove mvra member. * libguile/vm-engine.c (call): Set MVRA to 0. Will remove later. (return-values): Return to RA. (call/cc): Remove MVRA from capture call. * libguile/frames.c: * libguile/frames.h (SCM_FRAME_MV_RETURN_ADDRESS) (SCM_FRAME_RTL_MV_RETURN_ADDRESS, scm_frame_mv_return_address): Remove accessors. * libguile/control.c (reify_partial_continuation): Adapt to scm_i_vm_capture_stack change. Andy Wingo2013-11-151-3/+1
* Walk the stack to determine extent of partial continuation...* libguile/control.c (reify_partial_continuation): Walk the stack to determine the bottom of the captured stack. Andy Wingo2013-10-271-6/+13
* Partial continuations are RTL stubs...* libguile/control.c: Implement partial continuations as RTL programs. * libguile/programs.c (scm_i_rtl_program_minimum_arity): Add partial continuation case. * libguile/vm-engine.c (compose-continuation): Fix to look for vm_cont from the free variables. * libguile/vm-i-system.c (abort): Poison continuations captured in the stack VM, as the can't be rewound by the RTL stubs. Andy Wingo2013-10-271-67/+18
* Add SCM_F_DYNSTACK_PROMPT_PUSH_NARGS prompt flag...* libguile/dynstack.h (scm_t_dynstack_prompt_flags): New flag, SCM_F_DYNSTACK_PROMPT_PUSH_NARGS, set if the continuation expects the number of args to be pushed on the top of the stack. * libguile/control.c (scm_c_abort): Only push nargs if requested. * libguile/eval.c (eval): * libguile/throw.c (pre_init_catch): * libguile/vm-i-system.c (prompt): Set SCM_F_DYNSTACK_PROMPT_PUSH_NARGS. Andy Wingo2013-10-141-1/+2
* abort-to-prompt* instead of @abort...* libguile/control.h: * libguile/control.c (scm_abort_to_prompt_star): Rename from scm_at_abort. * module/ice-9/boot-9.scm (abort-to-prompt): Use abort-to-prompt*. * module/language/tree-il/primitives.scm: Handle abort-to-prompt* instead of @abort. Andy Wingo2013-06-251-4/+6
* dynstack: pushing a prompt no longer allocates memory...* libguile/control.h: Remove scm_t_prompt_registers and scm_c_make_prompt_registers. (scm_c_abort): Take a pointer to a jmpbuf instead of a cookie. It will serve the same purpose. * libguile/control.c (reify_partial_continuation, scm_at_abort): Adapt to new prompt representation. * libguile/dynstack.h: * libguile/dynstack.c (scm_dynstack_push_prompt): Prompts now have 5 words instead of 2, as they now push the fp, sp, ip, and jmpbuf on the stack separately. This avoids allocation. (scm_dynstack_find_prompt): Likewise, add return values for fp, sp, etc. (scm_dynstack_wind_prompt): Replaces scm_dynstack_relocate_prompt. * libguile/eval.c (eval): * libguile/stacks.c (find_prompt): * libguile/throw.c (pre_init_catch): Adapt to the new prompt mechanism. * libguile/vm-engine.c (vm_engine): Setjmp an on-stack jmpbuf every time the VM enters. We can then re-use that jmpbuf for all prompts in that invocation. * libguile/vm-i-system.c (partial_cont_call): Adapt to change in prompt representation. We don't need to wind here any more, since we pass in the prompt's jmpbuf. (prompt): Adapt to scm_dynstack_push_prompt change. (abort): Adapt to vm_abort change. * libguile/vm.h (struct scm_vm): No more cookie. * libguile/vm.c (vm_abort): Adapt to scm_c_abort change. (vm_reinstate_partial_continuation): Rewind the dynamic stack here, now that we do have a valid jmpbuf. (make_vm): No need to initialize a cookie. Andy Wingo2012-03-071-29/+25
* the dynamic stack is really a stack now, instead of a list...* libguile/dynstack.h: * libguile/dynstack.c: New files, implementing the dynamic stack as a true stack instead of a linked list. This lowers the cost of dynwinds: frames, winders, prompts, with-fluids, and dynamic-wind. For the most part, we allocate these items directly on the stack. * libguile/dynwinds.h: * libguile/dynwinds.c: Adapt all manipulators of the wind stack to use interfaces from dynstack.c. Remove heap-allocated winder and frame object types. (scm_dowinds, scm_i_dowinds): Remove these. The first was exported, but it was not a public interface. * libguile/continuations.c: * libguile/continuations.h (scm_t_contregs): Continuation objects reference scm_t_dynstack* values now. Adapt to the new interfaces. * libguile/control.c: * libguile/control.h: There is no longer a scm_tc7_prompt kind of object that can be allocated on the heap. Instead, the prompt flags, key, and registers are pushed on the dynwind stack. (The registers are still on the heap.) Also, since the vm_cont will reference the dynwinds, make the partial continuation stub take just one extra arg, instead of storing the intwinds separately in the object table. * libguile/fluids.c: * libguile/fluids.h: No more with-fluids objects; instead, the fluids go on the dynstack. The values still have to be on the heap, though. (scm_prepare_fluids, scm_swap_fluids): New internal functions, replacing scm_i_make_with_fluids and scm_i_swap_with_fluids. * libguile/print.c: Remove prompt and with-fluids printers. * libguile/tags.h: Revert prompt and with-fluids tc7 values to what they were before they were allocated. * libguile/vm-i-system.c (partial_cont_call): Just pop the vmcont, the intwinds will not be passed as a second arg. Rewind the dynamic stack from within the VM, so that any rewinder sees valid prompt entries. (call_cc, tail_call_cc): Adapt to pass the dynstack to scm_i_vm_capture_stack. (prompt, wind, unwind, wind_fluids, unwind_fluids): Adapt to the new interfaces. * libguile/vm.h (scm_i_capture_current_stack): Rename from scm_i_vm_capture_continuation. (scm_i_vm_capture_stack): Take a dynstack as an argument. * libguile/vm.c (vm_reinstate_partial_continuation): Don't wind here, as that could result in winders seeing invalid prompts. * libguile/eval.c: * libguile/root.c: * libguile/stacks.c: * libguile/threads.c: * libguile/threads.h: * libguile/throw.c: Adapt other users of dynwinds to use the dynstack. Andy Wingo2012-03-031-71/+48
* Merge remote-tracking branch 'origin/stable-2.0'...Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c Andy Wingo2012-02-081-18/+17
|\
| * fix compilation of control.c, continuations.c when SCM_ALIGNED is not defined...* libguile/control.c: * libguile/continuations.c: Fix for the case in which SCM_ALIGNED is not defined. Though I wonder, perhaps we should just error out in those cases. Andy Wingo2012-02-041-18/+17
* | locking for putc, puts...* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions. Andy Wingo2011-11-081-2/+2
|/
* fix list validation bug in @abort...* 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. Andy Wingo2011-07-281-1/+2
* more care regarding SCM_PACK and SCM_UNPACK...* 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. Andy Wingo2011-05-131-1/+1
* fix prompt and abort with the boot evaluator...* 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. Andy Wingo2011-03-291-4/+4
* objcode type is an enumeration, not flags...* 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. Andy Wingo2011-01-271-2/+2
* Include <alloca.h> wherever `alloca' is used....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>. Ludovic Courtès2010-11-191-0/+2
* Have `@abort' honor VM changes by winds....* libguile/control.c (scm_c_abort): Update VM after the `scm_dowinds' call. * test-suite/tests/control.test ("the-vm"): New test prefix. Ludovic Courtès2010-09-271-1/+5
* use scm_malloc_pointerless to alloc aligned blocks in fallback...* 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. Andy Wingo2010-07-171-5/+4
* Fix parenthesizing of the `ROUND_UP' macro; factorize....* 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. Ludovic Courtès2010-05-301-1/+0
* add abort to unknown prompt test...* 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. Andy Wingo2010-03-111-1/+1
* remove internal treatment of default prompt tag, it seems there was no need...* 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. Andy Wingo2010-03-111-17/+2
* partial continuations print as #<partial-continuation ...>...* 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. Andy Wingo2010-03-041-1/+1
* add printers for prompts and with-fluids objects...* 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. Andy Wingo2010-03-041-0/+8
* Use libguile/control.x explicitly.Ken Raeburn2010-03-021-1/+1
* rewinding prompts works...* 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. Andy Wingo2010-02-261-8/+4
* fix a prompt bug...* 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. Andy Wingo2010-02-261-6/+6
* simplify handling of nonlocal prompt returns from c...* libguile/control.h: * libguile/control.c (scm_i_prompt_pop_abort_args_x): New helper. * libguile/eval.c (eval): Use the new helper. Andy Wingo2010-02-251-0/+20
* fix escape-only prompts...* libguile/control.c (scm_c_make_prompt): Whoops, set the escape-only flag properly here. Andy Wingo2010-02-241-1/+1
* add %default-prompt-tag, and error (not abort()) on an abort to bad tag...* 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. Andy Wingo2010-02-241-4/+15
* rewind the dynamic state when entering a partial continuation...* 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! Andy Wingo2010-02-241-5/+4
* record IP in partial continuations...* libguile/control.c (reify_partial_continuation): Assert some invariants, and record the IP as the MVRA of the continuation. Andy Wingo2010-02-241-3/+12
* actually capture partial continuations...* 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. Andy Wingo2010-02-221-4/+113
* abort always dispatches to VM bytecode, to detect same-invocation aborts...* 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. Andy Wingo2010-02-221-20/+10
* prompt as part of guile's primitive language...* 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. Andy Wingo2010-02-191-36/+34
* add scm_c_abort, wire it up to the abort opcode...* 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. Andy Wingo2010-02-191-0/+58
* prompt handlers are always inline...* 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 ...). Andy Wingo2010-02-191-4/+1
* <prompt> has no pre-unwind-handler, it's unnecessary...* 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. Andy Wingo2010-02-191-5/+4