-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_conflict.c
77 lines (70 loc) · 1.8 KB
/
check_conflict.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <time.h>
#include <setjmp.h>
#include <ctype.h>
#include "lapi.h"
#include "lauxlib.h"
#include "lcode.h"
#include "lctype.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "llex.h"
#include "llimits.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lopnames.h"
#include "lparser.h"
#include "lprefix.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "luaconf.h"
#include "lua.h"
#include "lualib.h"
#include "lundump.h"
#include "lvm.h"
#include "lzio.h"
struct LHS_assign {
struct LHS_assign *prev;
expdesc v; /* variable (global, local, upvalue, or indexed) */
};
extern void luaK_reserveregs(FuncState *, int);
extern int luaK_codeABCk(FuncState *, OpCode, int, int, int, int);
extern int luaK_codeABCk(FuncState *, OpCode, int, int, int, int);
extern void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
FuncState *fs = ls->fs;
int extra = fs->freereg;
int conflict = 0;
for (; lh; lh = lh->prev) {
if ((VINDEXED <= (lh->v.k) && (lh->v.k) <= VINDEXSTR)) {
if (lh->v.k == VINDEXUP) {
if (v->k == VUPVAL && lh->v.u.ind.t == v->u.info) {
conflict = 1;
lh->v.k = VINDEXSTR;
lh->v.u.ind.t = extra;
}
}
else {
if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.sidx) {
conflict = 1;
lh->v.u.ind.t = extra;
}
if (lh->v.k == VINDEXED && v->k == VLOCAL &&
lh->v.u.ind.idx == v->u.var.sidx) {
conflict = 1;
lh->v.u.ind.idx = extra;
}
}
}
}
if (conflict) {
if (v->k == VLOCAL)
luaK_codeABCk(fs,OP_MOVE,extra,v->u.var.sidx,0,0);
else
luaK_codeABCk(fs,OP_GETUPVAL,extra,v->u.info,0,0);
luaK_reserveregs(fs, 1);
}
}