** check whether, in an assignment to an upvalue/local variable, the ** upvalue/local variable is begin used in a previous assignment to a ** table. If so, save original upvalue/local value in a safe place and ** use this safe copy in the previous assignment. */
| 1317 | ** use this safe copy in the previous assignment. |
| 1318 | */ |
| 1319 | static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { |
| 1320 | FuncState *fs = ls->fs; |
| 1321 | int extra = fs->freereg; /* eventual position to save local variable */ |
| 1322 | int conflict = 0; |
| 1323 | for (; lh; lh = lh->prev) { /* check all previous assignments */ |
| 1324 | if (vkisindexed(lh->v.k)) { /* assignment to table field? */ |
| 1325 | if (lh->v.k == VINDEXUP) { /* is table an upvalue? */ |
| 1326 | if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) { |
| 1327 | conflict = 1; /* table is the upvalue being assigned now */ |
| 1328 | lh->v.k = VINDEXSTR; |
| 1329 | lh->v.u.ind.t = extra; /* assignment will use safe copy */ |
| 1330 | } |
| 1331 | } |
| 1332 | else { /* table is a register */ |
| 1333 | if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) { |
| 1334 | conflict = 1; /* table is the local being assigned now */ |
| 1335 | lh->v.u.ind.t = extra; /* assignment will use safe copy */ |
| 1336 | } |
| 1337 | /* is index the local being assigned? */ |
| 1338 | if (lh->v.k == VINDEXED && v->k == VLOCAL && |
| 1339 | lh->v.u.ind.idx == v->u.var.ridx) { |
| 1340 | conflict = 1; |
| 1341 | lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ |
| 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | } |
| 1346 | if (conflict) { |
| 1347 | /* copy upvalue/local value to a temporary (in position 'extra') */ |
| 1348 | if (v->k == VLOCAL) |
| 1349 | luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0); |
| 1350 | else |
| 1351 | luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0); |
| 1352 | luaK_reserveregs(fs, 1); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | /* |
| 1357 | ** Parse and compile a multiple assignment. The first "variable" |
no test coverage detected