-/* Copyright (C) 2010 Free Software Foundation, Inc.
+/* Copyright (C) 2010, 2011 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
# include <config.h>
#endif
+#include <alloca.h>
+
#include "libguile/_scm.h"
#include "libguile/control.h"
#include "libguile/objcodes.h"
\f
-SCM scm_sys_default_prompt_tag;
-
SCM
-scm_c_make_prompt (SCM vm, SCM k, scm_t_uint8 escape_only_p,
- scm_t_int64 vm_cookie)
+scm_c_make_prompt (SCM k, SCM *fp, SCM *sp, scm_t_uint8 *abort_ip,
+ scm_t_uint8 escape_only_p, scm_t_int64 vm_cookie,
+ SCM winds)
{
scm_t_bits tag;
- SCM ret;
struct scm_prompt_registers *regs;
tag = scm_tc7_prompt;
if (escape_only_p)
tag |= (SCM_F_PROMPT_ESCAPE<<8);
- ret = scm_words (tag, 5);
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;
+ regs->fp = fp;
+ regs->sp = sp;
+ regs->ip = abort_ip;
regs->cookie = vm_cookie;
- 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 scm_double_cell (tag, SCM_UNPACK (k), (scm_t_bits)regs,
+ SCM_UNPACK (winds));
+}
- return ret;
+/* 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;
}
+
#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
#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)\
+#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
static const type sym[]
-#define SCM_STATIC_ALIGNED_ARRAY(alignment, 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)\
+#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); \
+SCM_SNARF_INIT(sym = scm_malloc_pointerless (sizeof(sym##__unaligned); \
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))
+ SCM_PACK (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0))
#define SCM_STATIC_OBJCODE(sym) \
SCM_DECLARE_STATIC_ALIGNED_ARRAY (scm_t_uint8, sym##__bytecode); \
scm_vector (scm_list_2 (vm_cont, intwinds)),
SCM_BOOL_F);
SCM_SET_CELL_WORD_0 (ret,
- SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_CONTINUATION);
+ SCM_CELL_WORD_0 (ret) | SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION);
return ret;
}
-SCM
+void
scm_c_abort (SCM vm, SCM tag, size_t n, SCM *argv, scm_t_int64 cookie)
{
SCM cont, winds, prompt = SCM_BOOL_F;
}
}
- /* 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 we didn't find anything, raise an error. */
if (scm_is_false (prompt))
- {
- 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));
- }
+ scm_misc_error ("abort", "Abort to unknown prompt", scm_list_1 (tag));
cont = reify_partial_continuation (vm, prompt, winds, cookie);
/* Unwind once more, beyond the prompt. */
winds = SCM_CDR (winds), delta++;
-
+
/* Unwind */
scm_dowinds (winds, delta);
+ /* Unwinding may have changed the current thread's VM, so use the
+ new one. */
+ vm = scm_the_vm ();
+
/* Restore VM regs */
SCM_VM_DATA (vm)->fp = SCM_PROMPT_REGISTERS (prompt)->fp;
SCM_VM_DATA (vm)->sp = SCM_PROMPT_REGISTERS (prompt)->sp;
}
#undef FUNC_NAME
+void
+scm_i_prompt_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
+{
+ scm_puts ("#<prompt ", port);
+ scm_intprint (SCM_UNPACK (exp), 16, port);
+ scm_putc ('>', port);
+}
+
void
scm_init_control (void)
{
-#include "control.x"
- 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);
+#include "libguile/control.x"
}
/*