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:
parent
60934f1415
commit
2d95c39051
|
@ -2926,7 +2926,7 @@ Scheme_Object *scheme_make_sequence_compilation(Scheme_Object *seq, int opt)
|
||||||
to a bad .zo */
|
to a bad .zo */
|
||||||
Scheme_Object *list, *v, *good;
|
Scheme_Object *list, *v, *good;
|
||||||
Scheme_Sequence *o;
|
Scheme_Sequence *o;
|
||||||
int count, i, k, total, last, first, setgood, addconst;
|
int count, i, k, total, last, first, setgood;
|
||||||
Scheme_Type type;
|
Scheme_Type type;
|
||||||
|
|
||||||
type = scheme_sequence_type;
|
type = scheme_sequence_type;
|
||||||
|
@ -2973,23 +2973,19 @@ Scheme_Object *scheme_make_sequence_compilation(Scheme_Object *seq, int opt)
|
||||||
|
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
if (opt < -1) {
|
if (opt < -1) {
|
||||||
/* can't optimize away a begin0 at read time; it's too late, since the
|
/* can't optimize away a begin0 reading a .zo time */
|
||||||
return is combined with EXPD_BEGIN0 */
|
|
||||||
addconst = 1;
|
|
||||||
} else if ((opt < 0) && !scheme_omittable_expr(SCHEME_CAR(seq), 1, -1, 0, NULL, NULL, 0, 0, 1)) {
|
} 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
|
/* We can't optimize (begin0 expr cont) to expr because
|
||||||
exp is not in tail position in the original (so we'd mess
|
exp is not in tail position in the original (so we'd mess
|
||||||
up continuation marks). */
|
up continuation marks). */
|
||||||
addconst = 1;
|
|
||||||
} else
|
} else
|
||||||
return good;
|
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->so.type = ((opt < 0) ? scheme_begin0_sequence_type : scheme_sequence_type);
|
||||||
o->count = count + addconst;
|
o->count = count;
|
||||||
|
|
||||||
--total;
|
--total;
|
||||||
for (i = k = 0; i < count; k++) {
|
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;
|
o->array[i++] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addconst)
|
|
||||||
o->array[i] = scheme_void;
|
|
||||||
|
|
||||||
return (Scheme_Object *)o;
|
return (Scheme_Object *)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4370,8 +4370,7 @@ case_lambda_shift(Scheme_Object *data, int delta, int after_depth)
|
||||||
static Scheme_Object *
|
static Scheme_Object *
|
||||||
begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
|
begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
|
||||||
{
|
{
|
||||||
int i, count, drop = 0, prev_size, single_result = 0, preserves_marks = 0;
|
int i, count, drop = 0, prev_size, single_result = 0, preserves_marks = 0, kclock, sclock;
|
||||||
int kclock, sclock, movable;
|
|
||||||
Scheme_Sequence *s = (Scheme_Sequence *)obj;
|
Scheme_Sequence *s = (Scheme_Sequence *)obj;
|
||||||
Scheme_Object *inside = NULL, *expr, *orig_first;
|
Scheme_Object *inside = NULL, *expr, *orig_first;
|
||||||
int id_offset = 0;
|
int id_offset = 0;
|
||||||
|
@ -4417,7 +4416,7 @@ begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
|
||||||
info->preserves_marks = 1;
|
info->preserves_marks = 1;
|
||||||
info->single_result = single_result;
|
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 */
|
/* If the first expression preserves marks we can drop the begin0 */
|
||||||
return s->array[0];
|
return s->array[0];
|
||||||
}
|
}
|
||||||
|
@ -4458,13 +4457,6 @@ begin0_optimize(Scheme_Object *obj, Optimize_Info *info, int context)
|
||||||
expr = (Scheme_Object *)s2;
|
expr = (Scheme_Object *)s2;
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
if (drop) {
|
||||||
Scheme_Sequence *s2;
|
Scheme_Sequence *s2;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user