** 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. */
| 1150 | ** use this safe copy in the previous assignment. |
| 1151 | */ |
| 1152 | static void check_conflict(LexState *ls, struct LHS_assign *lh, expdesc *v) { |
| 1153 | FuncState *fs = ls->fs; |
| 1154 | int extra = fs->freereg; /* eventual position to save local variable */ |
| 1155 | int conflict = 0; |
| 1156 | for (; lh; lh = lh->prev) { /* check all previous assignments */ |
| 1157 | if (lh->v.k == VINDEXED) { /* assigning to a table? */ |
| 1158 | /* table is the upvalue/local being assigned now? */ |
| 1159 | if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) { |
| 1160 | conflict = 1; |
| 1161 | lh->v.u.ind.vt = VLOCAL; |
| 1162 | lh->v.u.ind.t = extra; /* previous assignment will use safe copy */ |
| 1163 | } |
| 1164 | /* index is the local being assigned? (index cannot be upvalue) */ |
| 1165 | if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) { |
| 1166 | conflict = 1; |
| 1167 | lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | if (conflict) { |
| 1172 | /* copy upvalue/local value to a temporary (in position 'extra') */ |
| 1173 | OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; |
| 1174 | luaK_codeABC(fs, op, extra, v->u.info, 0); |
| 1175 | luaK_reserveregs(fs, 1); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | static void assignment(LexState *ls, struct LHS_assign *lh, int nvars) { |
no test coverage detected