aboutsummaryrefslogtreecommitdiff
path: root/src/lua/lparser.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lua/lparser.h (renamed from src/lua-5.3/lparser.h)77
1 files changed, 57 insertions, 20 deletions
diff --git a/src/lua-5.3/lparser.h b/src/lua/lparser.h
index f45b23c..618cb01 100644
--- a/src/lua-5.3/lparser.h
+++ b/src/lua/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.76.1.1 2017/04/19 17:20:42 roberto Exp $ 2** $Id: lparser.h $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -30,56 +30,88 @@ typedef enum {
30 VFALSE, /* constant false */ 30 VFALSE, /* constant false */
31 VK, /* constant in 'k'; info = index of constant in 'k' */ 31 VK, /* constant in 'k'; info = index of constant in 'k' */
32 VKFLT, /* floating constant; nval = numerical float value */ 32 VKFLT, /* floating constant; nval = numerical float value */
33 VKINT, /* integer constant; nval = numerical integer value */ 33 VKINT, /* integer constant; ival = numerical integer value */
34 VKSTR, /* string constant; strval = TString address;
35 (string is fixed by the lexer) */
34 VNONRELOC, /* expression has its value in a fixed register; 36 VNONRELOC, /* expression has its value in a fixed register;
35 info = result register */ 37 info = result register */
36 VLOCAL, /* local variable; info = local register */ 38 VLOCAL, /* local variable; var.sidx = stack index (local register);
39 var.vidx = relative index in 'actvar.arr' */
37 VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 40 VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */
41 VCONST, /* compile-time constant; info = absolute index in 'actvar.arr' */
38 VINDEXED, /* indexed variable; 42 VINDEXED, /* indexed variable;
39 ind.vt = whether 't' is register or upvalue; 43 ind.t = table register;
40 ind.t = table register or upvalue; 44 ind.idx = key's R index */
41 ind.idx = key's R/K index */ 45 VINDEXUP, /* indexed upvalue;
46 ind.t = table upvalue;
47 ind.idx = key's K index */
48 VINDEXI, /* indexed variable with constant integer;
49 ind.t = table register;
50 ind.idx = key's value */
51 VINDEXSTR, /* indexed variable with literal string;
52 ind.t = table register;
53 ind.idx = key's K index */
42 VJMP, /* expression is a test/comparison; 54 VJMP, /* expression is a test/comparison;
43 info = pc of corresponding jump instruction */ 55 info = pc of corresponding jump instruction */
44 VRELOCABLE, /* expression can put result in any register; 56 VRELOC, /* expression can put result in any register;
45 info = instruction pc */ 57 info = instruction pc */
46 VCALL, /* expression is a function call; info = instruction pc */ 58 VCALL, /* expression is a function call; info = instruction pc */
47 VVARARG /* vararg expression; info = instruction pc */ 59 VVARARG /* vararg expression; info = instruction pc */
48} expkind; 60} expkind;
49 61
50 62
51#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 63#define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR)
52#define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 64#define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR)
65
53 66
54typedef struct expdesc { 67typedef struct expdesc {
55 expkind k; 68 expkind k;
56 union { 69 union {
57 lua_Integer ival; /* for VKINT */ 70 lua_Integer ival; /* for VKINT */
58 lua_Number nval; /* for VKFLT */ 71 lua_Number nval; /* for VKFLT */
72 TString *strval; /* for VKSTR */
59 int info; /* for generic use */ 73 int info; /* for generic use */
60 struct { /* for indexed variables (VINDEXED) */ 74 struct { /* for indexed variables */
61 short idx; /* index (R/K) */ 75 short idx; /* index (R or "long" K) */
62 lu_byte t; /* table (register or upvalue) */ 76 lu_byte t; /* table (register or upvalue) */
63 lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */
64 } ind; 77 } ind;
78 struct { /* for local variables */
79 lu_byte sidx; /* index in the stack */
80 unsigned short vidx; /* compiler index (in 'actvar.arr') */
81 } var;
65 } u; 82 } u;
66 int t; /* patch list of 'exit when true' */ 83 int t; /* patch list of 'exit when true' */
67 int f; /* patch list of 'exit when false' */ 84 int f; /* patch list of 'exit when false' */
68} expdesc; 85} expdesc;
69 86
70 87
71/* description of active local variable */ 88/* kinds of variables */
72typedef struct Vardesc { 89#define VDKREG 0 /* regular */
73 short idx; /* variable index in stack */ 90#define RDKCONST 1 /* constant */
91#define RDKTOCLOSE 2 /* to-be-closed */
92#define RDKCTC 3 /* compile-time constant */
93
94/* description of an active local variable */
95typedef union Vardesc {
96 struct {
97 TValuefields; /* constant value (if it is a compile-time constant) */
98 lu_byte kind;
99 lu_byte sidx; /* index of the variable in the stack */
100 short pidx; /* index of the variable in the Proto's 'locvars' array */
101 TString *name; /* variable name */
102 } vd;
103 TValue k; /* constant value (if any) */
74} Vardesc; 104} Vardesc;
75 105
76 106
107
77/* description of pending goto statements and label statements */ 108/* description of pending goto statements and label statements */
78typedef struct Labeldesc { 109typedef struct Labeldesc {
79 TString *name; /* label identifier */ 110 TString *name; /* label identifier */
80 int pc; /* position in code */ 111 int pc; /* position in code */
81 int line; /* line where it appeared */ 112 int line; /* line where it appeared */
82 lu_byte nactvar; /* local level where it appears in current block */ 113 lu_byte nactvar; /* number of active variables in that position */
114 lu_byte close; /* goto that escapes upvalues */
83} Labeldesc; 115} Labeldesc;
84 116
85 117
@@ -93,7 +125,7 @@ typedef struct Labellist {
93 125
94/* dynamic structures used by the parser */ 126/* dynamic structures used by the parser */
95typedef struct Dyndata { 127typedef struct Dyndata {
96 struct { /* list of active local variables */ 128 struct { /* list of all active local variables */
97 Vardesc *arr; 129 Vardesc *arr;
98 int n; 130 int n;
99 int size; 131 int size;
@@ -115,17 +147,22 @@ typedef struct FuncState {
115 struct BlockCnt *bl; /* chain of current blocks */ 147 struct BlockCnt *bl; /* chain of current blocks */
116 int pc; /* next position to code (equivalent to 'ncode') */ 148 int pc; /* next position to code (equivalent to 'ncode') */
117 int lasttarget; /* 'label' of last 'jump label' */ 149 int lasttarget; /* 'label' of last 'jump label' */
118 int jpc; /* list of pending jumps to 'pc' */ 150 int previousline; /* last line that was saved in 'lineinfo' */
119 int nk; /* number of elements in 'k' */ 151 int nk; /* number of elements in 'k' */
120 int np; /* number of elements in 'p' */ 152 int np; /* number of elements in 'p' */
153 int nabslineinfo; /* number of elements in 'abslineinfo' */
121 int firstlocal; /* index of first local var (in Dyndata array) */ 154 int firstlocal; /* index of first local var (in Dyndata array) */
122 short nlocvars; /* number of elements in 'f->locvars' */ 155 int firstlabel; /* index of first label (in 'dyd->label->arr') */
156 short ndebugvars; /* number of elements in 'f->locvars' */
123 lu_byte nactvar; /* number of active local variables */ 157 lu_byte nactvar; /* number of active local variables */
124 lu_byte nups; /* number of upvalues */ 158 lu_byte nups; /* number of upvalues */
125 lu_byte freereg; /* first free register */ 159 lu_byte freereg; /* first free register */
160 lu_byte iwthabs; /* instructions issued since last absolute line info */
161 lu_byte needclose; /* function needs to close upvalues when returning */
126} FuncState; 162} FuncState;
127 163
128 164
165LUAI_FUNC int luaY_nvarstack (FuncState *fs);
129LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 166LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
130 Dyndata *dyd, const char *name, int firstchar); 167 Dyndata *dyd, const char *name, int firstchar);
131 168