** 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. */
| 1106 | ** use this safe copy in the previous assignment. |
| 1107 | */ |
| 1108 | static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) { |
| 1109 | FuncState *fs = ls->fs; |
| 1110 | int extra = fs->freereg; /* eventual position to save local variable */ |
| 1111 | int conflict = 0; |
| 1112 | for (; lh; lh = lh->prev) { /* check all previous assignments */ |
| 1113 | if (lh->v.k == VINDEXED) { /* assigning to a table? */ |
| 1114 | /* table is the upvalue/local being assigned now? */ |
| 1115 | if (lh->v.u.ind.vt == v->k && lh->v.u.ind.t == v->u.info) { |
| 1116 | conflict = 1; |
| 1117 | lh->v.u.ind.vt = VLOCAL; |
| 1118 | lh->v.u.ind.t = extra; /* previous assignment will use safe copy */ |
| 1119 | } |
| 1120 | /* index is the local being assigned? (index cannot be upvalue) */ |
| 1121 | if (v->k == VLOCAL && lh->v.u.ind.idx == v->u.info) { |
| 1122 | conflict = 1; |
| 1123 | lh->v.u.ind.idx = extra; /* previous assignment will use safe copy */ |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | if (conflict) { |
| 1128 | /* copy upvalue/local value to a temporary (in position 'extra') */ |
| 1129 | OpCode op = (v->k == VLOCAL) ? OP_MOVE : OP_GETUPVAL; |
| 1130 | luaK_codeABC(fs, op, extra, v->u.info, 0); |
| 1131 | luaK_reserveregs(fs, 1); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | |
| 1136 | static void assignment (LexState *ls, struct LHS_assign *lh, int nvars) { |
no test coverage detected