MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / check_conflict

Function check_conflict

extlibs/lua/src/lparser.c:1312–1347  ·  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

1310** use this safe copy in the previous assignment.
1311*/
1312static 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"

Callers 1

restassignFunction · 0.85

Calls 1

luaK_reserveregsFunction · 0.85

Tested by

no test coverage detected