simplify treatmenet of begin0 and discarding expressions

Since `begin0` at the bytecode level always evaluates an initial
expression in non-tail position, we don't have to work so hard
to ensure that an extra expression sticks around.
This commit is contained in:
Gustavo Massaccesi 2014-12-01 15:20:37 -03:00 committed by Matthew Flatt
parent 60934f1415
commit 2d95c39051
2 changed files with 7 additions and 22 deletions

View File

@ -2926,7 +2926,7 @@ Scheme_Object *scheme_make_sequence_compilation(Scheme_Object *seq, int opt)
to a bad .zo */
Scheme_Object *list, *v, *good;
Scheme_Sequence *o;
int count, i, k, total, last, first, setgood, addconst;
int count, i, k, total, last, first, setgood;
Scheme_Type type;
type = scheme_sequence_type;
@ -2973,23 +2973,19 @@ Scheme_Object *scheme_make_sequence_compilation(Scheme_Object *seq, int opt)
if (count == 1) {
if (opt < -1) {
/* can't optimize away a begin0 at read time; it's too late, since the
return is combined with EXPD_BEGIN0 */
addconst = 1;
/* can't optimize away a begin0 reading a .zo time */
} else if ((opt < 0) && !scheme_omittable_expr(SCHEME_CAR(seq), 1, -1, 0, NULL, NULL, 0, 0, 1)) {
/* We can't optimize (begin0 expr cont) to expr because
exp is not in tail position in the original (so we'd mess
up continuation marks). */
addconst = 1;
} else
return good;
} else
addconst = 0;
}
o = scheme_malloc_sequence(count + addconst);
o = scheme_malloc_sequence(count);
o->so.type = ((opt < 0) ? scheme_begin0_sequence_type : scheme_sequence_type);
o->count = count + addconst;
o->count = count;
--total;
for (i = k = 0; i < count; k++) {
@ -3014,9 +3010,6 @@ Scheme_Object *scheme_make_sequence_compilation(Scheme_Object *seq, int opt)
o->array[i++] = v;
}
if (addconst)
o->array[i] = scheme_void;
return (Scheme_Object *)o;
}

View File

@ -4370,8 +4370,7 @@ case_lambda_shift(Scheme_Object *data, int delta, int after_depth)
static Scheme_Object *
begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
{
int i, count, drop = 0, prev_size, single_result = 0, preserves_marks = 0;
int kclock, sclock, movable;
int i, count, drop = 0, prev_size, single_result = 0, preserves_marks = 0, kclock, sclock;
Scheme_Sequence *s = (Scheme_Sequence *)obj;
Scheme_Object *inside = NULL, *expr, *orig_first;
int id_offset = 0;
@ -4417,7 +4416,7 @@ begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
info->preserves_marks = 1;
info->single_result = single_result;
if (drop && (s->count - drop) == 1 && (preserves_marks == 1)) {
if ((s->count - drop) == 1 && (preserves_marks == 1)) {
/* If the first expression preserves marks we can drop the begin0 */
return s->array[0];
}
@ -4458,13 +4457,6 @@ begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
expr = (Scheme_Object *)s2;
}
} else {
if (drop && (s->count - drop) == 1) {
/* can't drop down to 1 expression */
s->array[s->count-1] = scheme_void;
--drop;
info->size += 1;
}
if (drop) {
Scheme_Sequence *s2;
int j = 0;