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