summaryrefslogtreecommitdiff
path: root/libguile/memoize.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2010-02-19 22:44:24 +0100
committerAndy Wingo <wingo@pobox.com>2010-02-19 22:44:24 +0100
commit747022e4cb5faef6e0a2c73f046bacd93bb99ab8 (patch)
treeb37adc0822d4dafd24f6d8ee4ce1ac340ac56d45 /libguile/memoize.c
parent0bc8874c0461d532ca0251cf20af9bc5193b3cfa (diff)
downloadguile-747022e4cb5faef6e0a2c73f046bacd93bb99ab8.tar.gz
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.
Diffstat (limited to 'libguile/memoize.c')
-rw-r--r--libguile/memoize.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/libguile/memoize.c b/libguile/memoize.c
index 4c1a1017b..e2fcfee0d 100644
--- a/libguile/memoize.c
+++ b/libguile/memoize.c
@@ -223,6 +223,8 @@ scm_t_bits scm_tc16_memoized;
MAKMEMO (SCM_M_MODULE_REF, scm_cons (mod, scm_cons (var, public)))
#define MAKMEMO_MOD_SET(val, mod, var, public) \
MAKMEMO (SCM_M_MODULE_SET, scm_cons (val, scm_cons (mod, scm_cons (var, public))))
+#define MAKMEMO_PROMPT(tag, exp, handler) \
+ MAKMEMO (SCM_M_PROMPT, scm_cons (tag, scm_cons (exp, handler)))
@@ -247,6 +249,7 @@ static const char *const memoized_tags[] =
"toplevel-set!",
"module-ref",
"module-set!",
+ "prompt",
};
static int
@@ -276,6 +279,7 @@ static SCM scm_m_let (SCM xorig, SCM env);
static SCM scm_m_letrec (SCM xorig, SCM env);
static SCM scm_m_letstar (SCM xorig, SCM env);
static SCM scm_m_or (SCM xorig, SCM env);
+static SCM scm_m_at_prompt (SCM xorig, SCM env);
static SCM scm_m_quote (SCM xorig, SCM env);
static SCM scm_m_set_x (SCM xorig, SCM env);
@@ -413,6 +417,7 @@ SCM_SYNTAX (s_let, "let", scm_m_let);
SCM_SYNTAX (s_letrec, "letrec", scm_m_letrec);
SCM_SYNTAX (s_letstar, "let*", scm_m_letstar);
SCM_SYNTAX (s_or, "or", scm_m_or);
+SCM_SYNTAX (s_at_prompt, "@prompt", scm_m_at_prompt);
SCM_SYNTAX (s_quote, "quote", scm_m_quote);
SCM_SYNTAX (s_set_x, "set!", scm_m_set_x);
SCM_SYNTAX (s_atapply, "@apply", scm_m_apply);
@@ -439,6 +444,7 @@ SCM_GLOBAL_SYMBOL (scm_sym_let, "let");
SCM_GLOBAL_SYMBOL (scm_sym_letrec, "letrec");
SCM_GLOBAL_SYMBOL (scm_sym_letstar, "let*");
SCM_GLOBAL_SYMBOL (scm_sym_or, "or");
+SCM_GLOBAL_SYMBOL (scm_sym_at_prompt, "@prompt");
SCM_GLOBAL_SYMBOL (scm_sym_quote, "quote");
SCM_GLOBAL_SYMBOL (scm_sym_set_x, "set!");
SCM_SYMBOL (sym_eval, "eval");
@@ -981,6 +987,17 @@ scm_m_or (SCM expr, SCM env SCM_UNUSED)
}
static SCM
+scm_m_at_prompt (SCM expr, SCM env)
+{
+ ASSERT_SYNTAX (scm_ilength (expr) >= 0, s_bad_expression, expr);
+ ASSERT_SYNTAX (scm_ilength (expr) == 4, s_expression, expr);
+
+ return MAKMEMO_PROMPT (memoize (CADR (expr), env),
+ memoize (CADDR (expr), env),
+ memoize (CADDDR (expr), env));
+}
+
+static SCM
scm_m_quote (SCM expr, SCM env SCM_UNUSED)
{
SCM quotee;
@@ -1159,6 +1176,11 @@ unmemoize (const SCM expr)
scm_i_finite_list_copy (CADR (args)),
CADDR (args)),
unmemoize (CAR (args)));
+ case SCM_M_PROMPT:
+ return scm_list_4 (scm_sym_at_prompt,
+ unmemoize (CAR (args)),
+ unmemoize (CADR (args)),
+ unmemoize (CDDR (args)));
default:
abort ();
}