syntax-local-lift-values-expression (v4.2.0.3)

svn: r15107
This commit is contained in:
Matthew Flatt 2009-06-06 15:13:43 +00:00
parent 3bb875b4f7
commit 933f578002
7 changed files with 119 additions and 51 deletions

View File

@ -425,6 +425,15 @@ Other syntactic forms can capture lifts by using
@transform-time[]}
@defproc[(syntax-local-lift-values-expression [n exact-nonnegative-integer?] [stx syntax?])
(listof identifier?)]{
Like @scheme[syntax-local-lift-expression], but binds the result to
@scheme[n] identifiers, and returns a list of the @scheme[n]
identifiers.
@transform-time[]}
@defproc[(syntax-local-lift-context)
any/c]{

View File

@ -1,5 +1,5 @@
{
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,49,46,53,46,54,50,0,0,0,1,0,0,3,0,12,0,
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,50,46,48,46,51,50,0,0,0,1,0,0,3,0,12,0,
17,0,20,0,27,0,40,0,47,0,51,0,58,0,63,0,68,0,72,0,78,
0,92,0,106,0,109,0,115,0,119,0,121,0,132,0,134,0,148,0,155,0,
177,0,179,0,193,0,1,1,27,1,35,1,43,1,53,1,89,1,128,1,167,
@ -14,13 +14,13 @@
115,61,120,73,108,101,116,114,101,99,45,118,97,108,117,101,115,66,108,97,109,
98,100,97,1,20,112,97,114,97,109,101,116,101,114,105,122,97,116,105,111,110,
45,107,101,121,61,118,73,100,101,102,105,110,101,45,118,97,108,117,101,115,97,
35,11,8,136,232,95,159,2,15,35,35,159,2,14,35,35,159,2,14,35,35,
35,11,8,129,232,95,159,2,15,35,35,159,2,14,35,35,159,2,14,35,35,
16,20,2,3,2,1,2,5,2,1,2,6,2,1,2,7,2,1,2,8,2,
1,2,9,2,1,2,10,2,1,2,4,2,1,2,11,2,1,2,12,2,1,
97,36,11,8,136,232,93,159,2,14,35,36,16,2,2,2,161,2,1,36,2,
2,2,1,2,2,96,11,11,8,136,232,16,0,96,37,11,8,136,232,16,0,
97,36,11,8,129,232,93,159,2,14,35,36,16,2,2,2,161,2,1,36,2,
2,2,1,2,2,96,11,11,8,129,232,16,0,96,37,11,8,129,232,16,0,
13,16,4,35,29,11,11,2,1,11,18,16,2,99,64,104,101,114,101,8,31,
8,30,8,29,8,28,8,27,93,8,224,15,58,0,0,95,9,8,224,15,58,
8,30,8,29,8,28,8,27,93,8,224,8,58,0,0,95,9,8,224,8,58,
0,0,2,1,27,248,22,135,4,23,196,1,249,22,128,4,80,158,38,35,251,
22,75,2,16,248,22,90,23,200,2,12,249,22,65,2,17,248,22,92,23,202,
1,27,248,22,135,4,23,196,1,249,22,128,4,80,158,38,35,251,22,75,2,
@ -29,16 +29,16 @@
36,28,248,22,73,248,22,67,23,195,2,248,22,66,193,249,22,128,4,80,158,
38,35,251,22,75,2,16,248,22,66,23,200,2,249,22,65,2,12,248,22,67,
23,202,1,11,18,16,2,101,10,8,31,8,30,8,29,8,28,8,27,16,4,
11,11,2,18,3,1,7,101,110,118,57,56,51,50,16,4,11,11,2,19,3,
1,7,101,110,118,57,56,51,51,93,8,224,16,58,0,0,95,9,8,224,16,
11,11,2,18,3,1,7,101,110,118,57,56,50,51,16,4,11,11,2,19,3,
1,7,101,110,118,57,56,50,52,93,8,224,9,58,0,0,95,9,8,224,9,
58,0,0,2,1,27,248,22,67,248,22,135,4,23,197,1,28,248,22,73,23,
194,2,20,15,159,36,35,36,28,248,22,73,248,22,67,23,195,2,248,22,66,
193,249,22,128,4,80,158,38,35,250,22,75,2,20,248,22,75,249,22,75,248,
22,75,2,21,248,22,66,23,202,2,251,22,75,2,16,2,21,2,21,249,22,
65,2,4,248,22,67,23,205,1,18,16,2,101,11,8,31,8,30,8,29,8,
28,8,27,16,4,11,11,2,18,3,1,7,101,110,118,57,56,51,53,16,4,
11,11,2,19,3,1,7,101,110,118,57,56,51,54,93,8,224,17,58,0,0,
95,9,8,224,17,58,0,0,2,1,248,22,135,4,193,27,248,22,135,4,194,
28,8,27,16,4,11,11,2,18,3,1,7,101,110,118,57,56,50,54,16,4,
11,11,2,19,3,1,7,101,110,118,57,56,50,55,93,8,224,10,58,0,0,
95,9,8,224,10,58,0,0,2,1,248,22,135,4,193,27,248,22,135,4,194,
249,22,65,248,22,75,248,22,66,196,248,22,67,195,27,248,22,67,248,22,135,
4,23,197,1,249,22,128,4,80,158,38,35,28,248,22,53,248,22,129,4,248,
22,66,23,198,2,27,249,22,2,32,0,89,162,8,44,36,42,9,222,33,39,
@ -68,9 +68,9 @@
16,28,249,22,165,8,248,22,129,4,248,22,66,23,201,2,64,101,108,115,101,
10,248,22,66,23,198,2,250,22,76,2,20,9,248,22,67,23,201,1,249,22,
65,2,3,248,22,67,23,203,1,100,8,31,8,30,8,29,8,28,8,27,16,
4,11,11,2,18,3,1,7,101,110,118,57,56,53,56,16,4,11,11,2,19,
3,1,7,101,110,118,57,56,53,57,93,8,224,18,58,0,0,18,16,2,158,
94,10,64,118,111,105,100,8,47,95,9,8,224,18,58,0,0,2,1,27,248,
4,11,11,2,18,3,1,7,101,110,118,57,56,52,57,16,4,11,11,2,19,
3,1,7,101,110,118,57,56,53,48,93,8,224,11,58,0,0,18,16,2,158,
94,10,64,118,111,105,100,8,47,95,9,8,224,11,58,0,0,2,1,27,248,
22,67,248,22,135,4,196,249,22,128,4,80,158,38,35,28,248,22,53,248,22,
129,4,248,22,66,197,250,22,75,2,26,248,22,75,248,22,66,199,248,22,90,
198,27,248,22,129,4,248,22,66,197,250,22,75,2,26,248,22,75,248,22,66,
@ -100,7 +100,7 @@
EVAL_ONE_SIZED_STR((char *)expr, 2048);
}
{
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,49,46,53,46,54,59,0,0,0,1,0,0,13,0,18,0,
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,50,46,48,46,51,59,0,0,0,1,0,0,13,0,18,0,
35,0,50,0,68,0,84,0,94,0,112,0,132,0,148,0,166,0,197,0,226,
0,248,0,6,1,12,1,26,1,31,1,41,1,49,1,77,1,109,1,154,1,
199,1,223,1,6,2,8,2,65,2,155,3,196,3,31,5,135,5,239,5,100,
@ -342,12 +342,12 @@
EVAL_ONE_SIZED_STR((char *)expr, 5016);
}
{
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,49,46,53,46,54,8,0,0,0,1,0,0,6,0,19,0,
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,50,46,48,46,51,8,0,0,0,1,0,0,6,0,19,0,
34,0,48,0,62,0,76,0,115,0,0,0,6,1,0,0,65,113,117,111,116,
101,29,94,2,1,67,35,37,117,116,105,108,115,11,29,94,2,1,69,35,37,
110,101,116,119,111,114,107,11,29,94,2,1,68,35,37,112,97,114,97,109,122,
11,29,94,2,1,68,35,37,101,120,112,111,98,115,11,29,94,2,1,68,35,
37,107,101,114,110,101,108,11,97,35,11,8,142,234,98,159,2,2,35,35,159,
37,107,101,114,110,101,108,11,97,35,11,8,135,234,98,159,2,2,35,35,159,
2,3,35,35,159,2,4,35,35,159,2,5,35,35,159,2,6,35,35,159,2,
6,35,35,16,0,159,35,20,103,159,35,16,1,11,16,0,83,158,41,20,100,
144,69,35,37,98,117,105,108,116,105,110,29,11,11,11,11,11,18,96,11,42,
@ -360,7 +360,7 @@
EVAL_ONE_SIZED_STR((char *)expr, 299);
}
{
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,49,46,53,46,54,52,0,0,0,1,0,0,11,0,38,0,
static MZCOMPILED_STRING_FAR unsigned char expr[] = {35,126,7,52,46,50,46,48,46,51,52,0,0,0,1,0,0,11,0,38,0,
44,0,57,0,71,0,93,0,119,0,131,0,149,0,169,0,181,0,197,0,220,
0,0,1,5,1,10,1,15,1,24,1,29,1,60,1,64,1,72,1,81,1,
89,1,192,1,237,1,1,2,30,2,61,2,117,2,127,2,174,2,184,2,191,

View File

@ -109,6 +109,7 @@ static Scheme_Object *local_module_definitions(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_module_imports(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_module_expanding_provides(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_lift_expr(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_lift_exprs(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_lift_context(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_lift_end_statement(int argc, Scheme_Object *argv[]);
static Scheme_Object *local_lift_require(int argc, Scheme_Object *argv[]);
@ -555,6 +556,7 @@ static void make_kernel_env(void)
GLOBAL_PRIM_W_ARITY("rename-transformer-target", rename_transformer_target, 1, 1, env);
GLOBAL_PRIM_W_ARITY("syntax-local-lift-expression", local_lift_expr, 1, 1, env);
GLOBAL_PRIM_W_ARITY("syntax-local-lift-values-expression", local_lift_exprs, 2, 2, env);
GLOBAL_PRIM_W_ARITY("syntax-local-lift-context", local_lift_context, 0, 0, env);
GLOBAL_PRIM_W_ARITY("syntax-local-lift-module-end-declaration", local_lift_end_statement, 1, 1, env);
GLOBAL_PRIM_W_ARITY("syntax-local-lift-require", local_lift_require, 2, 2, env);
@ -4894,25 +4896,42 @@ local_module_expanding_provides(int argc, Scheme_Object *argv[])
}
static Scheme_Object *
local_lift_expr(int argc, Scheme_Object *argv[])
do_local_lift_expr(const char *who, int stx_pos, int argc, Scheme_Object *argv[])
{
Scheme_Env *menv;
Scheme_Comp_Env *env, *orig_env;
Scheme_Object *id, *local_mark, *expr, *data, *vec, *id_sym;
Scheme_Object *id, *ids, *rev_ids, *local_mark, *expr, *data, *vec, *id_sym;
Scheme_Lift_Capture_Proc cp;
Scheme_Object *orig_expr;
int count;
char buf[24];
expr = argv[0];
if (stx_pos) {
if (SCHEME_INTP(argv[0])) {
count = SCHEME_INT_VAL(argv[0]);
} else if (SCHEME_BIGNUMP(argv[0])) {
if (SCHEME_BIGPOS(argv[0]))
scheme_raise_out_of_memory(NULL, NULL);
count = -1;
} else
count = -1;
if (count < 0)
scheme_wrong_type(who, "exact nonnegative integer", 0, argc, argv);
} else
count = 1;
expr = argv[stx_pos];
if (!SCHEME_STXP(expr))
scheme_wrong_type("syntax-local-lift-expression", "syntax", 0, argc, argv);
scheme_wrong_type(who, "syntax", stx_pos, argc, argv);
env = orig_env = scheme_current_thread->current_local_env;
local_mark = scheme_current_thread->current_local_mark;
if (!env)
scheme_raise_exn(MZEXN_FAIL_CONTRACT,
"syntax-local-lift-expression: not currently transforming");
"%s: not currently transforming",
who);
while (env && !COMPILE_DATA(env)->lifts) {
env = env->next;
@ -4932,11 +4951,17 @@ local_lift_expr(int argc, Scheme_Object *argv[])
will generate new bindings. But lots of things work better or faster
when different bindings have different symbols. Use env->genv->id_counter
to help keep name generation deterministic within a module. */
sprintf(buf, "lifted.%d", env->genv->id_counter++);
id_sym = scheme_intern_exact_parallel_symbol(buf, strlen(buf));
rev_ids = scheme_null;
while (count--) {
sprintf(buf, "lifted.%d", env->genv->id_counter++);
id_sym = scheme_intern_exact_parallel_symbol(buf, strlen(buf));
id = scheme_datum_to_syntax(id_sym, scheme_false, scheme_false, 0, 0);
id = scheme_add_remove_mark(id, scheme_new_mark());
id = scheme_datum_to_syntax(id_sym, scheme_false, scheme_false, 0, 0);
id = scheme_add_remove_mark(id, scheme_new_mark());
rev_ids = scheme_make_pair(id, rev_ids);
}
ids = scheme_reverse(rev_ids);
vec = COMPILE_DATA(env)->lifts;
cp = *(Scheme_Lift_Capture_Proc *)SCHEME_VEC_ELS(vec)[1];
@ -4952,15 +4977,35 @@ local_lift_expr(int argc, Scheme_Object *argv[])
expr = scheme_stx_activate_certs(expr);
orig_expr = expr;
expr = cp(data, &id, expr, orig_env);
expr = cp(data, &ids, expr, orig_env);
expr = scheme_make_pair(expr, SCHEME_VEC_ELS(vec)[0]);
SCHEME_VEC_ELS(vec)[0] = expr;
SCHEME_EXPAND_OBSERVE_LOCAL_LIFT(scheme_get_expand_observe(), id, orig_expr);
rev_ids = scheme_null;
for (; !SCHEME_NULLP(ids); ids = SCHEME_CDR(ids)) {
id = SCHEME_CAR(ids);
SCHEME_EXPAND_OBSERVE_LOCAL_LIFT(scheme_get_expand_observe(), id, orig_expr);
id = scheme_add_remove_mark(id, local_mark);
rev_ids = scheme_make_pair(id, rev_ids);
}
ids = scheme_reverse(rev_ids);
id = scheme_add_remove_mark(id, local_mark);
return id;
return ids;
}
static Scheme_Object *
local_lift_expr(int argc, Scheme_Object *argv[])
{
Scheme_Object *ids;
ids = do_local_lift_expr("syntax-local-lift-expression", 0, argc, argv);
return SCHEME_CAR(ids);
}
static Scheme_Object *
local_lift_exprs(int argc, Scheme_Object *argv[])
{
return do_local_lift_expr("syntax-local-lift-values-expression", 1, argc, argv);
}
static Scheme_Object *

View File

@ -6254,17 +6254,21 @@ Scheme_Object *scheme_expand_expr(Scheme_Object *form, Scheme_Comp_Env *env,
return scheme_compile_expand_expr(form, env, erec, drec, 0);
}
static Scheme_Object *pair_lifted(Scheme_Object *_ip, Scheme_Object **_id, Scheme_Object *expr, Scheme_Comp_Env *env)
static Scheme_Object *pair_lifted(Scheme_Object *_ip, Scheme_Object **_ids, Scheme_Object *expr, Scheme_Comp_Env *env)
{
Scheme_Comp_Env **ip = (Scheme_Comp_Env **)_ip, *naya;
Scheme_Object *ids, *id;
naya = scheme_new_compilation_frame(1, SCHEME_CAPTURE_LIFTED, (*ip)->next, NULL);
(*ip)->next = naya;
*ip = naya;
scheme_add_compilation_binding(0, *_id, naya);
for (ids = *_ids; !SCHEME_NULLP(ids); ids = SCHEME_CDR(ids)) {
id = SCHEME_CAR(ids);
scheme_add_compilation_binding(0, id, naya);
}
return icons(icons(*_id, scheme_null), icons(expr, scheme_null));
return icons(*_ids, icons(expr, scheme_null));
}
static Scheme_Object *add_lifts_as_let(Scheme_Object *obj, Scheme_Object *l, Scheme_Comp_Env *env,
@ -9346,15 +9350,18 @@ Scheme_Object *scheme_generate_lifts_key(void)
}
Scheme_Object *
scheme_make_lifted_defn(Scheme_Object *sys_wraps, Scheme_Object **_id, Scheme_Object *expr, Scheme_Comp_Env *env)
scheme_make_lifted_defn(Scheme_Object *sys_wraps, Scheme_Object **_ids, Scheme_Object *expr, Scheme_Comp_Env *env)
{
Scheme_Object *l;
Scheme_Object *l, *ids, *id;
/* Registers marked id: */
scheme_tl_id_sym(env->genv, *_id, scheme_false, 2, NULL, NULL);
/* Registers marked ids: */
for (ids = *_ids; !SCHEME_NULLP(ids); ids = SCHEME_CDR(ids)) {
id = SCHEME_CAR(ids);
scheme_tl_id_sym(env->genv, id, scheme_false, 2, NULL, NULL);
}
l = icons(scheme_datum_to_syntax(define_values_symbol, scheme_false, sys_wraps, 0, 0),
icons(scheme_make_pair(*_id, scheme_null),
icons(*_ids,
icons(expr,
scheme_null)));

View File

@ -5759,27 +5759,34 @@ static Scheme_Object *add_req(Scheme_Object *imods, Scheme_Object *requires)
return requires;
}
static Scheme_Object *add_lifted_defn(Scheme_Object *data, Scheme_Object **_id, Scheme_Object *expr, Scheme_Comp_Env *_env)
static Scheme_Object *add_lifted_defn(Scheme_Object *data, Scheme_Object **_ids, Scheme_Object *expr, Scheme_Comp_Env *_env)
{
Scheme_Comp_Env *env;
Scheme_Object *self_modidx, *rn, *name, *id;
Scheme_Object *self_modidx, *rn, *name, *ids, *id, *new_ids = scheme_null;
env = (Scheme_Comp_Env *)SCHEME_VEC_ELS(data)[0];
self_modidx = SCHEME_VEC_ELS(data)[1];
rn = SCHEME_VEC_ELS(data)[2];
for (ids = *_ids; !SCHEME_NULLP(ids); ids = SCHEME_CDR(ids)) {
id = SCHEME_CAR(ids);
name = scheme_tl_id_sym(env->genv, *_id, scheme_false, 2, NULL, NULL);
name = scheme_tl_id_sym(env->genv, id, scheme_false, 2, NULL, NULL);
/* Create the bucket, indicating that the name will be defined: */
scheme_add_global_symbol(name, scheme_undefined, env->genv);
/* Create the bucket, indicating that the name will be defined: */
scheme_add_global_symbol(name, scheme_undefined, env->genv);
/* Add a renaming: */
scheme_extend_module_rename(rn, self_modidx, name, name, self_modidx, name, 0, NULL, NULL, NULL, 0);
/* Add a renaming: */
scheme_extend_module_rename(rn, self_modidx, name, name, self_modidx, name, 0, NULL, NULL, NULL, 0);
id = scheme_add_rename(*_id, rn);
*_id = id;
id = scheme_add_rename(id, rn);
new_ids = cons(id, new_ids);
}
return scheme_make_lifted_defn(scheme_sys_wraps(env), _id, expr, _env);
new_ids = scheme_reverse(new_ids);
*_ids = new_ids;
return scheme_make_lifted_defn(scheme_sys_wraps(env), _ids, expr, _env);
}
static Scheme_Object *make_require_form(Scheme_Object *module_path, long phase, Scheme_Object *mark)

View File

@ -13,7 +13,7 @@
#define USE_COMPILED_STARTUP 1
#define EXPECTED_PRIM_COUNT 951
#define EXPECTED_PRIM_COUNT 952
#ifdef MZSCHEME_SOMETHING_OMITTED
# undef USE_COMPILED_STARTUP

View File

@ -13,12 +13,12 @@
consistently.)
*/
#define MZSCHEME_VERSION "4.2.0.2"
#define MZSCHEME_VERSION "4.2.0.3"
#define MZSCHEME_VERSION_X 4
#define MZSCHEME_VERSION_Y 2
#define MZSCHEME_VERSION_Z 0
#define MZSCHEME_VERSION_W 2
#define MZSCHEME_VERSION_W 3
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)