MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / check_conflict

Function check_conflict

lib/lua/src/lparser.c:1331–1366  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

1329** use this safe copy in the previous assignment.
1330*/
1331static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
1332 FuncState *fs = ls->fs;
1333 int extra = fs->freereg; /* eventual position to save local variable */
1334 int conflict = 0;
1335 for (; lh; lh = lh->prev) { /* check all previous assignments */
1336 if (vkisindexed(lh->v.k)) { /* assignment to table field? */
1337 if (lh->v.k == VINDEXUP) { /* is table an upvalue? */
1338 if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {
1339 conflict = 1; /* table is the upvalue being assigned now */
1340 lh->v.k = VINDEXSTR;
1341 lh->v.u.ind.t = extra; /* assignment will use safe copy */
1342 }
1343 }
1344 else { /* table is a register */
1345 if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) {
1346 conflict = 1; /* table is the local being assigned now */
1347 lh->v.u.ind.t = extra; /* assignment will use safe copy */
1348 }
1349 /* is index the local being assigned? */
1350 if (lh->v.k == VINDEXED && v->k == VLOCAL &&
1351 lh->v.u.ind.idx == v->u.var.ridx) {
1352 conflict = 1;
1353 lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */
1354 }
1355 }
1356 }
1357 }
1358 if (conflict) {
1359 /* copy upvalue/local value to a temporary (in position 'extra') */
1360 if (v->k == VLOCAL)
1361 luaK_codeABC(fs, OP_MOVE, extra, v->u.var.ridx, 0);
1362 else
1363 luaK_codeABC(fs, OP_GETUPVAL, extra, v->u.info, 0);
1364 luaK_reserveregs(fs, 1);
1365 }
1366}
1367
1368/*
1369** Parse and compile a multiple assignment. The first "variable"

Callers 1

restassignFunction · 0.85

Calls 1

luaK_reserveregsFunction · 0.85

Tested by

no test coverage detected