diff options
Diffstat (limited to '')
-rw-r--r-- | lparser.h | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -37,21 +37,27 @@ typedef enum { | |||
37 | info = result register */ | 37 | info = result register */ |
38 | VLOCAL, /* local variable; var.ridx = register index; | 38 | VLOCAL, /* local variable; var.ridx = register index; |
39 | var.vidx = relative index in 'actvar.arr' */ | 39 | var.vidx = relative index in 'actvar.arr' */ |
40 | VGLOBAL, /* global variable; | ||
41 | info = relative index in 'actvar.arr' (or -1 for | ||
42 | implicit declaration) */ | ||
40 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ | 43 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ |
41 | VCONST, /* compile-time <const> variable; | 44 | VCONST, /* compile-time <const> variable; |
42 | info = absolute index in 'actvar.arr' */ | 45 | info = absolute index in 'actvar.arr' */ |
43 | VINDEXED, /* indexed variable; | 46 | VINDEXED, /* indexed variable; |
44 | ind.t = table register; | 47 | ind.t = table register; |
45 | ind.idx = key's R index */ | 48 | ind.idx = key's R index; |
49 | ind.ro = true if it represents a read-only global; | ||
50 | ind.keystr = if key is a string, index in 'k' of that string; | ||
51 | -1 if key is not a string */ | ||
46 | VINDEXUP, /* indexed upvalue; | 52 | VINDEXUP, /* indexed upvalue; |
47 | ind.t = table upvalue; | 53 | ind.idx = key's K index; |
48 | ind.idx = key's K index */ | 54 | ind.* as in VINDEXED */ |
49 | VINDEXI, /* indexed variable with constant integer; | 55 | VINDEXI, /* indexed variable with constant integer; |
50 | ind.t = table register; | 56 | ind.t = table register; |
51 | ind.idx = key's value */ | 57 | ind.idx = key's value */ |
52 | VINDEXSTR, /* indexed variable with literal string; | 58 | VINDEXSTR, /* indexed variable with literal string; |
53 | ind.t = table register; | 59 | ind.idx = key's K index; |
54 | ind.idx = key's K index */ | 60 | ind.* as in VINDEXED */ |
55 | VJMP, /* expression is a test/comparison; | 61 | VJMP, /* expression is a test/comparison; |
56 | info = pc of corresponding jump instruction */ | 62 | info = pc of corresponding jump instruction */ |
57 | VRELOC, /* expression can put result in any register; | 63 | VRELOC, /* expression can put result in any register; |
@@ -75,10 +81,12 @@ typedef struct expdesc { | |||
75 | struct { /* for indexed variables */ | 81 | struct { /* for indexed variables */ |
76 | short idx; /* index (R or "long" K) */ | 82 | short idx; /* index (R or "long" K) */ |
77 | lu_byte t; /* table (register or upvalue) */ | 83 | lu_byte t; /* table (register or upvalue) */ |
84 | lu_byte ro; /* true if variable is read-only */ | ||
85 | int keystr; /* index in 'k' of string key, or -1 if not a string */ | ||
78 | } ind; | 86 | } ind; |
79 | struct { /* for local variables */ | 87 | struct { /* for local variables */ |
80 | lu_byte ridx; /* register holding the variable */ | 88 | lu_byte ridx; /* register holding the variable */ |
81 | unsigned short vidx; /* compiler index (in 'actvar.arr') */ | 89 | short vidx; /* index in 'actvar.arr' */ |
82 | } var; | 90 | } var; |
83 | } u; | 91 | } u; |
84 | int t; /* patch list of 'exit when true' */ | 92 | int t; /* patch list of 'exit when true' */ |
@@ -87,12 +95,21 @@ typedef struct expdesc { | |||
87 | 95 | ||
88 | 96 | ||
89 | /* kinds of variables */ | 97 | /* kinds of variables */ |
90 | #define VDKREG 0 /* regular */ | 98 | #define VDKREG 0 /* regular local */ |
91 | #define RDKCONST 1 /* constant */ | 99 | #define RDKCONST 1 /* local constant */ |
92 | #define RDKTOCLOSE 2 /* to-be-closed */ | 100 | #define RDKTOCLOSE 2 /* to-be-closed */ |
93 | #define RDKCTC 3 /* compile-time constant */ | 101 | #define RDKCTC 3 /* local compile-time constant */ |
102 | #define GDKREG 4 /* regular global */ | ||
103 | #define GDKCONST 5 /* global constant */ | ||
104 | |||
105 | /* variables that live in registers */ | ||
106 | #define varinreg(v) ((v)->vd.kind <= RDKTOCLOSE) | ||
107 | |||
108 | /* test for global variables */ | ||
109 | #define varglobal(v) ((v)->vd.kind >= GDKREG) | ||
110 | |||
94 | 111 | ||
95 | /* description of an active local variable */ | 112 | /* description of an active variable */ |
96 | typedef union Vardesc { | 113 | typedef union Vardesc { |
97 | struct { | 114 | struct { |
98 | TValuefields; /* constant value (if it is a compile-time constant) */ | 115 | TValuefields; /* constant value (if it is a compile-time constant) */ |
@@ -111,7 +128,7 @@ typedef struct Labeldesc { | |||
111 | TString *name; /* label identifier */ | 128 | TString *name; /* label identifier */ |
112 | int pc; /* position in code */ | 129 | int pc; /* position in code */ |
113 | int line; /* line where it appeared */ | 130 | int line; /* line where it appeared */ |
114 | lu_byte nactvar; /* number of active variables in that position */ | 131 | short nactvar; /* number of active variables in that position */ |
115 | lu_byte close; /* true for goto that escapes upvalues */ | 132 | lu_byte close; /* true for goto that escapes upvalues */ |
116 | } Labeldesc; | 133 | } Labeldesc; |
117 | 134 | ||
@@ -156,7 +173,7 @@ typedef struct FuncState { | |||
156 | int firstlocal; /* index of first local var (in Dyndata array) */ | 173 | int firstlocal; /* index of first local var (in Dyndata array) */ |
157 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ | 174 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ |
158 | short ndebugvars; /* number of elements in 'f->locvars' */ | 175 | short ndebugvars; /* number of elements in 'f->locvars' */ |
159 | lu_byte nactvar; /* number of active local variables */ | 176 | short nactvar; /* number of active variable declarations */ |
160 | lu_byte nups; /* number of upvalues */ | 177 | lu_byte nups; /* number of upvalues */ |
161 | lu_byte freereg; /* first free register */ | 178 | lu_byte freereg; /* first free register */ |
162 | lu_byte iwthabs; /* instructions issued since last absolute line info */ | 179 | lu_byte iwthabs; /* instructions issued since last absolute line info */ |