Berry fix bug in walrus operator (#18969)

This commit is contained in:
s-hadinger 2023-06-25 23:14:33 +02:00 committed by GitHub
parent 339c1cedb7
commit 090a4bb4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,6 +78,16 @@ static int codeABx(bfuncinfo *finfo, bopcode op, int a, int bx)
return codeinst(finfo, ISET_OP(op) | ISET_RA(a) | ISET_Bx(bx));
}
/* Move value from register b to register a */
static void code_move_nooptim(bfuncinfo *finfo, int a, int b)
{
if (isK(b)) {
codeABx(finfo, OP_LDCONST, a, b & 0xFF);
} else {
codeABC(finfo, OP_MOVE, a, b, 0);
}
}
/* Move value from register b to register a */
/* Check the previous instruction to compact both instruction as one if possible */
/* If b is a constant, add LDCONST or add MOVE otherwise */
@ -95,11 +105,7 @@ static void code_move(bfuncinfo *finfo, int a, int b)
}
}
}
if (isK(b)) {
codeABx(finfo, OP_LDCONST, a, b & 0xFF);
} else {
codeABC(finfo, OP_MOVE, a, b, 0);
}
code_move_nooptim(finfo, a, b);
}
/* Free register at top (checks that it´s a register) */
@ -684,7 +690,11 @@ int be_code_setvar(bfuncinfo *finfo, bexpdesc *e1, bexpdesc *e2, bbool keep_reg)
switch (e1->type) {
case ETLOCAL: /* It can't be ETREG. */
if (e1->v.idx != src) {
code_move(finfo, e1->v.idx, src); /* do explicit move only if needed */
if (keep_reg) {
code_move_nooptim(finfo, e1->v.idx, src); /* always do explicit move */
} else {
code_move(finfo, e1->v.idx, src); /* do explicit move only if needed */
}
}
break;
case ETGLOBAL: /* store to grobal R(A) -> G(Bx) by global index */