2010-01-31 00:01:11 +01:00
|
|
|
|
/* Copyright (C) 2010 Free Software Foundation, Inc.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
|
|
# include <config.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "libguile/_scm.h"
|
|
|
|
|
|
#include "libguile/control.h"
|
2010-02-22 23:00:19 +01:00
|
|
|
|
#include "libguile/objcodes.h"
|
|
|
|
|
|
#include "libguile/instructions.h"
|
2010-02-02 22:59:55 +01:00
|
|
|
|
#include "libguile/vm.h"
|
2010-01-31 00:01:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-24 18:55:34 +01:00
|
|
|
|
SCM scm_sys_default_prompt_tag;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-02 22:59:55 +01:00
|
|
|
|
SCM
|
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.
2010-02-22 21:53:24 +01:00
|
|
|
|
scm_c_make_prompt (SCM vm, SCM k, scm_t_uint8 escape_only_p,
|
|
|
|
|
|
scm_t_int64 vm_cookie)
|
2010-02-02 22:59:55 +01:00
|
|
|
|
{
|
|
|
|
|
|
scm_t_bits tag;
|
|
|
|
|
|
SCM ret;
|
|
|
|
|
|
struct scm_prompt_registers *regs;
|
|
|
|
|
|
|
|
|
|
|
|
tag = scm_tc7_prompt;
|
|
|
|
|
|
if (escape_only_p)
|
2010-02-24 23:19:41 +01:00
|
|
|
|
tag |= (SCM_F_PROMPT_ESCAPE<<8);
|
2010-02-18 23:56:12 +01:00
|
|
|
|
ret = scm_words (tag, 5);
|
2010-02-02 22:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
regs = scm_gc_malloc_pointerless (sizeof (*regs), "prompt registers");
|
|
|
|
|
|
regs->fp = SCM_VM_DATA (vm)->fp;
|
|
|
|
|
|
regs->sp = SCM_VM_DATA (vm)->sp;
|
|
|
|
|
|
regs->ip = SCM_VM_DATA (vm)->ip;
|
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.
2010-02-22 21:53:24 +01:00
|
|
|
|
regs->cookie = vm_cookie;
|
2010-02-02 22:59:55 +01:00
|
|
|
|
|
|
|
|
|
|
SCM_SET_CELL_OBJECT (ret, 1, k);
|
|
|
|
|
|
SCM_SET_CELL_WORD (ret, 2, (scm_t_bits)regs);
|
|
|
|
|
|
SCM_SET_CELL_OBJECT (ret, 3, scm_i_dynwinds ());
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-02-25 13:17:34 +01:00
|
|
|
|
/* Only to be called if the SCM_PROMPT_SETJMP returns 1 */
|
|
|
|
|
|
SCM
|
|
|
|
|
|
scm_i_prompt_pop_abort_args_x (SCM prompt)
|
|
|
|
|
|
{
|
|
|
|
|
|
size_t i, n;
|
|
|
|
|
|
SCM vals = SCM_EOL;
|
|
|
|
|
|
|
|
|
|
|
|
n = scm_to_size_t (SCM_PROMPT_REGISTERS (prompt)->sp[0]);
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
vals = scm_cons (SCM_PROMPT_REGISTERS (prompt)->sp[-(i + 1)], vals);
|
|
|
|
|
|
|
|
|
|
|
|
/* The abort did reset the VM's registers, but then these values
|
|
|
|
|
|
were pushed on; so we need to pop them ourselves. */
|
|
|
|
|
|
SCM_VM_DATA (scm_the_vm ())->sp -= n + 1;
|
|
|
|
|
|
/* FIXME NULLSTACK */
|
|
|
|
|
|
|
|
|
|
|
|
return vals;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-22 23:00:19 +01:00
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
|
|
#define OBJCODE_HEADER(main,meta) 0, 0, 0, main, 0, 0, 0, meta+8
|
|
|
|
|
|
#define META_HEADER(meta) 0, 0, 0, meta, 0, 0, 0, 0
|
|
|
|
|
|
#else
|
|
|
|
|
|
#define OBJCODE_HEADER(main,meta) main, 0, 0, 0, meta+8, 0, 0, 0
|
|
|
|
|
|
#define META_HEADER(meta) meta, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define ROUND_UP(len,align) (((len-1)|(align-1))+1)
|
|
|
|
|
|
#define ALIGN_PTR(type,p,align) (type*)(ROUND_UP (((scm_t_bits)p), align))
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SCM_ALIGNED
|
|
|
|
|
|
#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym)\
|
|
|
|
|
|
static const type sym[]
|
|
|
|
|
|
#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym)\
|
|
|
|
|
|
static SCM_ALIGNED (alignment) const type sym[]
|
|
|
|
|
|
#else
|
|
|
|
|
|
#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym)\
|
|
|
|
|
|
static type *sym
|
|
|
|
|
|
#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
|
|
|
|
|
|
SCM_SNARF_INIT(sym = scm_malloc (sizeof(sym##__unaligned) + alignment - 1); \
|
|
|
|
|
|
sym = ALIGN_PTR (type, sym, alignment); \
|
|
|
|
|
|
memcpy (sym, sym##__unaligned, sizeof(sym##__unaligned));) \
|
|
|
|
|
|
static type *sym = NULL; \
|
|
|
|
|
|
static const type sym##__unaligned[]
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define STATIC_OBJCODE_TAG \
|
|
|
|
|
|
SCM_PACK (scm_tc7_objcode | (SCM_F_OBJCODE_IS_STATIC << 8))
|
|
|
|
|
|
|
|
|
|
|
|
#define SCM_STATIC_OBJCODE(sym) \
|
|
|
|
|
|
SCM_DECLARE_STATIC_ALIGNED_ARRAY (scm_t_uint8, sym##__bytecode); \
|
|
|
|
|
|
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_cell, sym##__cells) = { \
|
|
|
|
|
|
{ STATIC_OBJCODE_TAG, SCM_PACK (sym##__bytecode) }, \
|
|
|
|
|
|
{ SCM_BOOL_F, SCM_PACK (0) } \
|
|
|
|
|
|
}; \
|
|
|
|
|
|
static const SCM sym = SCM_PACK (sym##__cells); \
|
|
|
|
|
|
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_uint8, sym##__bytecode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCM_STATIC_OBJCODE (cont_objcode) = {
|
|
|
|
|
|
/* Like in continuations.c, but with partial-cont-call. */
|
|
|
|
|
|
OBJCODE_HEADER (8, 19),
|
|
|
|
|
|
/* leave args on the stack */
|
|
|
|
|
|
/* 0 */ scm_op_object_ref, 0, /* push scm_vm_cont object */
|
|
|
|
|
|
/* 2 */ scm_op_object_ref, 1, /* push internal winds */
|
2010-02-24 17:43:02 +01:00
|
|
|
|
/* 4 */ scm_op_partial_cont_call, /* and go! */
|
|
|
|
|
|
/* 5 */ scm_op_nop, scm_op_nop, scm_op_nop, /* pad to 8 bytes */
|
2010-02-22 23:00:19 +01:00
|
|
|
|
/* 8 */
|
|
|
|
|
|
|
|
|
|
|
|
/* We could put some meta-info to say that this proc is a continuation. Not sure
|
|
|
|
|
|
how to do that, though. */
|
|
|
|
|
|
META_HEADER (19),
|
|
|
|
|
|
/* 0 */ scm_op_make_eol, /* bindings */
|
|
|
|
|
|
/* 1 */ scm_op_make_eol, /* sources */
|
2010-02-24 17:43:02 +01:00
|
|
|
|
/* 2 */ scm_op_make_int8, 0, scm_op_make_int8, 5, /* arity: from ip 0 to ip 7 */
|
2010-02-22 23:00:19 +01:00
|
|
|
|
/* 6 */ scm_op_make_int8_0, /* the arity is 0 required args */
|
|
|
|
|
|
/* 7 */ scm_op_make_int8_0, /* 0 optionals */
|
|
|
|
|
|
/* 8 */ scm_op_make_true, /* and a rest arg */
|
|
|
|
|
|
/* 9 */ scm_op_list, 0, 5, /* make a list of those 5 vals */
|
|
|
|
|
|
/* 12 */ scm_op_list, 0, 1, /* and the arities will be a list of that one list */
|
|
|
|
|
|
/* 15 */ scm_op_list, 0, 3, /* pack bindings, sources, and arities into list */
|
|
|
|
|
|
/* 18 */ scm_op_return /* and return */
|
|
|
|
|
|
/* 19 */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
|
|
|
|
|
reify_partial_continuation (SCM vm, SCM prompt, SCM extwinds,
|
|
|
|
|
|
scm_t_int64 cookie)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM vm_cont, dynwinds, intwinds = SCM_EOL, ret;
|
|
|
|
|
|
scm_t_uint32 flags;
|
|
|
|
|
|
|
|
|
|
|
|
/* No need to reify if the continuation is never referenced in the handler. */
|
|
|
|
|
|
if (SCM_PROMPT_ESCAPE_P (prompt))
|
|
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
|
|
|
|
|
dynwinds = scm_i_dynwinds ();
|
|
|
|
|
|
while (!scm_is_eq (dynwinds, extwinds))
|
|
|
|
|
|
{
|
|
|
|
|
|
intwinds = scm_cons (scm_car (dynwinds), intwinds);
|
|
|
|
|
|
dynwinds = scm_cdr (dynwinds);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
flags = SCM_F_VM_CONT_PARTIAL;
|
|
|
|
|
|
if (cookie >= 0 && SCM_PROMPT_REGISTERS (prompt)->cookie == cookie)
|
|
|
|
|
|
flags |= SCM_F_VM_CONT_REWINDABLE;
|
|
|
|
|
|
|
2010-02-24 16:56:05 +01:00
|
|
|
|
/* Since non-escape continuations should begin with a thunk application, the
|
|
|
|
|
|
first bit of the stack should be a frame, with the saved fp equal to the fp
|
|
|
|
|
|
that was current when the prompt was made. */
|
|
|
|
|
|
if ((SCM*)(SCM_PROMPT_REGISTERS (prompt)->sp[1])
|
|
|
|
|
|
!= SCM_PROMPT_REGISTERS (prompt)->fp)
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
|
|
/* Capture from the top of the thunk application frame up to the end. Set an
|
|
|
|
|
|
MVRA only, as the post-abort code is in an MV context. */
|
|
|
|
|
|
vm_cont = scm_i_vm_capture_stack (SCM_PROMPT_REGISTERS (prompt)->sp + 4,
|
2010-02-22 23:00:19 +01:00
|
|
|
|
SCM_VM_DATA (vm)->fp,
|
|
|
|
|
|
SCM_VM_DATA (vm)->sp,
|
2010-02-24 16:56:05 +01:00
|
|
|
|
NULL,
|
|
|
|
|
|
SCM_VM_DATA (vm)->ip,
|
2010-02-22 23:00:19 +01:00
|
|
|
|
flags);
|
|
|
|
|
|
|
|
|
|
|
|
ret = scm_make_program (cont_objcode,
|
2010-02-24 17:43:02 +01:00
|
|
|
|
scm_vector (scm_list_2 (vm_cont, intwinds)),
|
2010-02-22 23:00:19 +01:00
|
|
|
|
SCM_BOOL_F);
|
|
|
|
|
|
SCM_SET_CELL_WORD_0 (ret,
|
|
|
|
|
|
SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_CONTINUATION);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-02-19 16:55:36 +01:00
|
|
|
|
SCM
|
2010-02-22 23:00:19 +01:00
|
|
|
|
scm_c_abort (SCM vm, SCM tag, size_t n, SCM *argv, scm_t_int64 cookie)
|
2010-02-19 16:55:36 +01:00
|
|
|
|
{
|
2010-02-22 23:00:19 +01:00
|
|
|
|
SCM cont, winds, prompt = SCM_BOOL_F;
|
2010-02-19 16:55:36 +01:00
|
|
|
|
long delta;
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
|
|
/* Search the wind list for an appropriate prompt.
|
|
|
|
|
|
"Waiter, please bring us the wind list." */
|
|
|
|
|
|
for (winds = scm_i_dynwinds (), delta = 0;
|
|
|
|
|
|
scm_is_pair (winds);
|
|
|
|
|
|
winds = SCM_CDR (winds), delta++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SCM elt = SCM_CAR (winds);
|
|
|
|
|
|
if (SCM_PROMPT_P (elt) && scm_is_eq (SCM_PROMPT_TAG (elt), tag))
|
|
|
|
|
|
{
|
|
|
|
|
|
prompt = elt;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If we didn't find anything, print a message and abort the process
|
|
|
|
|
|
right here. If you don't want this, establish a catch-all around
|
|
|
|
|
|
any code that might throw up. */
|
|
|
|
|
|
if (scm_is_false (prompt))
|
|
|
|
|
|
{
|
2010-02-24 18:55:34 +01:00
|
|
|
|
if (scm_is_eq (tag, scm_fluid_ref (scm_sys_default_prompt_tag)))
|
|
|
|
|
|
{
|
|
|
|
|
|
fprintf (stderr, "No prompt found for abort to default prompt tag!\n");
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
scm_misc_error ("abort", "abort to unknown tag", scm_list_1 (tag));
|
2010-02-19 16:55:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-02-22 23:00:19 +01:00
|
|
|
|
cont = reify_partial_continuation (vm, prompt, winds, cookie);
|
|
|
|
|
|
|
2010-02-19 16:55:36 +01:00
|
|
|
|
/* Unwind once more, beyond the prompt. */
|
|
|
|
|
|
winds = SCM_CDR (winds), delta++;
|
|
|
|
|
|
|
|
|
|
|
|
/* Unwind */
|
|
|
|
|
|
scm_dowinds (winds, delta);
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore VM regs */
|
|
|
|
|
|
SCM_VM_DATA (vm)->fp = SCM_PROMPT_REGISTERS (prompt)->fp;
|
|
|
|
|
|
SCM_VM_DATA (vm)->sp = SCM_PROMPT_REGISTERS (prompt)->sp;
|
|
|
|
|
|
SCM_VM_DATA (vm)->ip = SCM_PROMPT_REGISTERS (prompt)->ip;
|
|
|
|
|
|
|
|
|
|
|
|
/* Since we're jumping down, we should always have enough space */
|
|
|
|
|
|
if (SCM_VM_DATA (vm)->sp + n + 1 >= SCM_VM_DATA (vm)->stack_limit)
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
|
|
/* Push vals */
|
2010-02-22 23:00:19 +01:00
|
|
|
|
*(++(SCM_VM_DATA (vm)->sp)) = cont;
|
2010-02-19 16:55:36 +01:00
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
|
*(++(SCM_VM_DATA (vm)->sp)) = argv[i];
|
|
|
|
|
|
*(++(SCM_VM_DATA (vm)->sp)) = scm_from_size_t (n+1); /* +1 for continuation */
|
|
|
|
|
|
|
|
|
|
|
|
/* Jump! */
|
|
|
|
|
|
SCM_I_LONGJMP (SCM_PROMPT_REGISTERS (prompt)->regs, 1);
|
|
|
|
|
|
|
|
|
|
|
|
/* Shouldn't get here */
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
}
|
2010-02-02 22:59:55 +01:00
|
|
|
|
|
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.
2010-02-22 21:53:24 +01:00
|
|
|
|
SCM_DEFINE (scm_at_abort, "@abort", 2, 0, 0, (SCM tag, SCM args),
|
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.
2010-02-19 22:44:24 +01:00
|
|
|
|
"Abort to the nearest prompt with tag @var{tag}.")
|
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.
2010-02-22 21:53:24 +01:00
|
|
|
|
#define FUNC_NAME s_scm_at_abort
|
2010-01-31 00:01:11 +01:00
|
|
|
|
{
|
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.
2010-02-19 22:44:24 +01:00
|
|
|
|
SCM *argv;
|
|
|
|
|
|
size_t i, n;
|
|
|
|
|
|
|
|
|
|
|
|
SCM_VALIDATE_LIST_COPYLEN (SCM_ARG2, args, n);
|
|
|
|
|
|
argv = alloca (sizeof (SCM)*n);
|
|
|
|
|
|
for (i = 0; i < n; i++, args = scm_cdr (args))
|
|
|
|
|
|
argv[i] = scm_car (args);
|
|
|
|
|
|
|
2010-02-22 23:00:19 +01:00
|
|
|
|
scm_c_abort (scm_the_vm (), tag, n, argv, -1);
|
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.
2010-02-19 22:44:24 +01:00
|
|
|
|
|
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.
2010-02-22 21:53:24 +01:00
|
|
|
|
/* Oh, what, you're still here? The abort must have been reinstated. Actually,
|
|
|
|
|
|
that's quite impossible, given that we're already in C-land here, so...
|
|
|
|
|
|
abort! */
|
|
|
|
|
|
|
|
|
|
|
|
abort ();
|
2010-01-31 00:01:11 +01:00
|
|
|
|
}
|
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.
2010-02-19 22:44:24 +01:00
|
|
|
|
#undef FUNC_NAME
|
2010-01-31 00:01:11 +01:00
|
|
|
|
|
2010-02-24 18:55:34 +01:00
|
|
|
|
void
|
|
|
|
|
|
scm_init_control (void)
|
2010-01-31 00:01:11 +01:00
|
|
|
|
{
|
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.
2010-02-19 22:44:24 +01:00
|
|
|
|
#include "control.x"
|
2010-02-24 18:55:34 +01:00
|
|
|
|
scm_sys_default_prompt_tag = scm_make_fluid ();
|
|
|
|
|
|
scm_fluid_set_x (scm_sys_default_prompt_tag, scm_gensym (SCM_UNDEFINED));
|
|
|
|
|
|
scm_c_define ("%default-prompt-tag", scm_sys_default_prompt_tag);
|
2010-01-31 00:01:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|