From 8e4ebdf25bb000f7c84e6cba7c01975c01536f44 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 9 Oct 2013 21:32:25 +0300 Subject: Bug fix for $i++ = 3. --- awkgram.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'awkgram.c') diff --git a/awkgram.c b/awkgram.c index 947f4a30..1ca2791a 100644 --- a/awkgram.c +++ b/awkgram.c @@ -7576,8 +7576,13 @@ mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op) case Op_push_array: tp->opcode = Op_push_lhs; break; + case Op_field_assign: + yyerror(_("cannot assign a value to the result of a field post-increment expression")); + break; default: - cant_happen(); + yyerror(_("invalid target of assignment (opcode %s)"), + opcode2str(tp->opcode)); + break; } tp->do_reference = (op->opcode != Op_assign); /* check for uninitialized reference */ -- cgit v1.2.3 From c3f03fe1d5a7c1b2c7b8ff843afc506ce2a45811 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Wed, 16 Oct 2013 20:58:44 +0300 Subject: Fix -O option. --- awkgram.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'awkgram.c') 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) { -- cgit v1.2.3 From 6c09c80378028858d439158d923f94a72d30efc6 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 12 Jan 2014 20:22:55 +0200 Subject: Minor improvements in a few files. --- awkgram.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'awkgram.c') diff --git a/awkgram.c b/awkgram.c index 74913840..7eff2f11 100644 --- a/awkgram.c +++ b/awkgram.c @@ -6856,18 +6856,9 @@ func_use(const char *name, enum defref how) len = strlen(name); ind = hash(name, len, HASHSIZE, NULL); - for (fp = ftable[ind]; fp != NULL; fp = fp->next) { - if (strcmp(fp->name, name) == 0) { - if (how == FUNC_DEFINE) - fp->defined++; - else if (how == FUNC_EXT) { - fp->defined++; - fp->extension++; - } else - fp->used++; - return; - } - } + for (fp = ftable[ind]; fp != NULL; fp = fp->next) + if (strcmp(fp->name, name) == 0) + goto update_value; /* not in the table, fall through to allocate a new one */ @@ -6875,6 +6866,10 @@ func_use(const char *name, enum defref how) memset(fp, '\0', sizeof(struct fdesc)); emalloc(fp->name, char *, len + 1, "func_use"); strcpy(fp->name, name); + fp->next = ftable[ind]; + ftable[ind] = fp; + +update_value: if (how == FUNC_DEFINE) fp->defined++; else if (how == FUNC_EXT) { @@ -6882,8 +6877,6 @@ func_use(const char *name, enum defref how) fp->extension++; } else fp->used++; - fp->next = ftable[ind]; - ftable[ind] = fp; } /* track_ext_func --- add an extension function to the table */ -- cgit v1.2.3