aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-10-16 20:59:32 +0300
committerArnold D. Robbins <arnold@skeeve.com>2013-10-16 20:59:32 +0300
commitbafdfda0467c8f0bb6cd88f124fe9ded0f70cd29 (patch)
treecddcc75b11add3faac45d7f87681f1b3760f6e32
parenta5ccc85f3d186fd4eb691a3301facc76057fd8f3 (diff)
parentc3f03fe1d5a7c1b2c7b8ff843afc506ce2a45811 (diff)
downloadegawk-bafdfda0467c8f0bb6cd88f124fe9ded0f70cd29.tar.gz
egawk-bafdfda0467c8f0bb6cd88f124fe9ded0f70cd29.tar.bz2
egawk-bafdfda0467c8f0bb6cd88f124fe9ded0f70cd29.zip
Merge branch 'gawk-4.1-stable'
-rw-r--r--ChangeLog13
-rw-r--r--NEWS2
-rw-r--r--awkgram.c16
-rw-r--r--awkgram.y16
-rw-r--r--eval.c2
-rw-r--r--main.c4
6 files changed, 32 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index fdd77380..ff928bb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2013-10-16 Arnold D. Robbins <arnold@skeeve.com>
+ Make -O work again. Turns out that C99 bool variables
+ are clamped to zero or one.
+
+ * main.c (do_optimize): Init to false.
+ (main): Set do_optimize to true on -O.
+ * eval.c (setup_frame): Change all uses of do_optimize to be
+ a boolean check instead of a test > 1.
+ * awkgram.y: Ditto.
+ (optimize_assignment): Remove check against do_optimize since
+ it was inited to true anyway.
+
+ Unrelated:
+
* re.c (resetup): Add a comment about the joy of syntax bits.
Unrelated:
diff --git a/NEWS b/NEWS
index 3284ec1c..57db807c 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,8 @@ Changes from 4.1.0 to 4.1.1
5. The debugger now lists source code correctly under Cygwin.
+6. The -O option now works again.
+
XXX. A number of bugs have been fixed. See the ChangeLog.
Changes from 4.0.2 to 4.1.0
diff --git a/awkgram.c b/awkgram.c
index 1ca2791a..74913840 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -2848,7 +2848,7 @@ regular_loop:
(void) list_prepend((yyval), instruction(Op_push_i));
(yyval)->nexti->memory = dupnode(Nnull_string);
} else {
- if (do_optimize > 1
+ if (do_optimize
&& (yyvsp[(3) - (4)])->lasti->opcode == Op_func_call
&& strcmp((yyvsp[(3) - (4)])->lasti->func_name, in_function) == 0
) {
@@ -3518,7 +3518,7 @@ regular_print:
*/
}
- if (do_optimize > 1
+ if (do_optimize
&& (yyvsp[(1) - (2)])->nexti == (yyvsp[(1) - (2)])->lasti && (yyvsp[(1) - (2)])->nexti->opcode == Op_push_i
&& (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti && (yyvsp[(2) - (2)])->nexti->opcode == Op_push_i
) {
@@ -3718,7 +3718,7 @@ regular_print:
(yyval) = list_append(list_append(list_create((yyvsp[(1) - (2)])),
instruction(Op_field_spec)), (yyvsp[(2) - (2)]));
} else {
- if (do_optimize > 1 && (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti
+ if (do_optimize && (yyvsp[(2) - (2)])->nexti == (yyvsp[(2) - (2)])->lasti
&& (yyvsp[(2) - (2)])->nexti->opcode == Op_push_i
&& ((yyvsp[(2) - (2)])->nexti->memory->flags & (MPFN|MPZN)) == 0
) {
@@ -6705,7 +6705,7 @@ mk_function(INSTRUCTION *fi, INSTRUCTION *def)
thisfunc = fi->func_body;
assert(thisfunc != NULL);
- if (do_optimize > 1 && def->lasti->opcode == Op_pop) {
+ if (do_optimize && def->lasti->opcode == Op_pop) {
/* tail call which does not return any value. */
INSTRUCTION *t;
@@ -7233,7 +7233,7 @@ mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
/* do any numeric constant folding */
ip1 = s1->nexti;
- if (do_optimize > 1
+ if (do_optimize
&& ip1 == s1->lasti && ip1->opcode == Op_push_i
&& (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
&& (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
@@ -7652,10 +7652,8 @@ optimize_assignment(INSTRUCTION *exp)
i2 = NULL;
i1 = exp->lasti;
- if ( ! do_optimize
- || ( i1->opcode != Op_assign
- && i1->opcode != Op_field_assign)
- )
+ if ( i1->opcode != Op_assign
+ && i1->opcode != Op_field_assign)
return list_append(exp, instruction(Op_pop));
for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
diff --git a/awkgram.y b/awkgram.y
index 6f1cc299..9786ca7a 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -852,7 +852,7 @@ non_compound_stmt
(void) list_prepend($$, instruction(Op_push_i));
$$->nexti->memory = dupnode(Nnull_string);
} else {
- if (do_optimize > 1
+ if (do_optimize
&& $3->lasti->opcode == Op_func_call
&& strcmp($3->lasti->func_name, in_function) == 0
) {
@@ -1356,7 +1356,7 @@ common_exp
*/
}
- if (do_optimize > 1
+ if (do_optimize
&& $1->nexti == $1->lasti && $1->nexti->opcode == Op_push_i
&& $2->nexti == $2->lasti && $2->nexti->opcode == Op_push_i
) {
@@ -1494,7 +1494,7 @@ non_post_simp_exp
$$ = list_append(list_append(list_create($1),
instruction(Op_field_spec)), $2);
} else {
- if (do_optimize > 1 && $2->nexti == $2->lasti
+ if (do_optimize && $2->nexti == $2->lasti
&& $2->nexti->opcode == Op_push_i
&& ($2->nexti->memory->flags & (MPFN|MPZN)) == 0
) {
@@ -4157,7 +4157,7 @@ mk_function(INSTRUCTION *fi, INSTRUCTION *def)
thisfunc = fi->func_body;
assert(thisfunc != NULL);
- if (do_optimize > 1 && def->lasti->opcode == Op_pop) {
+ if (do_optimize && def->lasti->opcode == Op_pop) {
/* tail call which does not return any value. */
INSTRUCTION *t;
@@ -4685,7 +4685,7 @@ mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
/* do any numeric constant folding */
ip1 = s1->nexti;
- if (do_optimize > 1
+ if (do_optimize
&& ip1 == s1->lasti && ip1->opcode == Op_push_i
&& (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
&& (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
@@ -5104,10 +5104,8 @@ optimize_assignment(INSTRUCTION *exp)
i2 = NULL;
i1 = exp->lasti;
- if ( ! do_optimize
- || ( i1->opcode != Op_assign
- && i1->opcode != Op_field_assign)
- )
+ if ( i1->opcode != Op_assign
+ && i1->opcode != Op_field_assign)
return list_append(exp, instruction(Op_pop));
for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
diff --git a/eval.c b/eval.c
index 3ae43a8a..ac9e7729 100644
--- a/eval.c
+++ b/eval.c
@@ -1241,7 +1241,7 @@ setup_frame(INSTRUCTION *pc)
arg_count = (pc + 1)->expr_count;
/* tail recursion optimization */
- tail_optimize = ((pc + 1)->tail_call && do_optimize > 1
+ tail_optimize = ((pc + 1)->tail_call && do_optimize
&& ! do_debug && ! do_profile);
if (tail_optimize) {
diff --git a/main.c b/main.c
index 76fd5652..eea28657 100644
--- a/main.c
+++ b/main.c
@@ -133,7 +133,7 @@ static bool disallow_var_assigns = false; /* true for --exec */
static void add_preassign(enum assign_type type, char *val);
int do_flags = false;
-bool do_optimize = true; /* apply default optimizations */
+bool do_optimize = false; /* apply default optimizations */
static int do_nostalgia = false; /* provide a blast from the past */
static int do_binary = false; /* hands off my data! */
static int do_version = false; /* print version info */
@@ -438,7 +438,7 @@ main(int argc, char **argv)
break;
case 'O':
- do_optimize++;
+ do_optimize = true;
break;
case 'p':