diff options
Diffstat (limited to 'lstate.h')
-rw-r--r-- | lstate.h | 50 |
1 files changed, 40 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.148 2017/11/03 17:22:54 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.146 2017/11/02 11:28:56 roberto Exp $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -81,21 +81,47 @@ typedef struct stringtable { | |||
81 | } stringtable; | 81 | } stringtable; |
82 | 82 | ||
83 | 83 | ||
84 | /* | ||
85 | ** Information about a call. | ||
86 | */ | ||
87 | typedef struct CallInfo { | ||
88 | StkId func; /* function index in the stack */ | ||
89 | StkId top; /* top for this function */ | ||
90 | struct CallInfo *previous, *next; /* dynamic call link */ | ||
91 | union { | ||
92 | struct { /* only for Lua functions */ | ||
93 | const Instruction *savedpc; | ||
94 | } l; | ||
95 | struct { /* only for C functions */ | ||
96 | lua_KFunction k; /* continuation in case of yields */ | ||
97 | ptrdiff_t old_errfunc; | ||
98 | lua_KContext ctx; /* context info. in case of yields */ | ||
99 | } c; | ||
100 | } u; | ||
101 | union { | ||
102 | int funcidx; /* called-function index */ | ||
103 | int nyield; /* number of values yielded */ | ||
104 | } u2; | ||
105 | short nresults; /* expected number of results from this function */ | ||
106 | unsigned short callstatus; | ||
107 | } CallInfo; | ||
108 | |||
84 | 109 | ||
85 | /* | 110 | /* |
86 | ** Bits in CallInfo status | 111 | ** Bits in CallInfo status |
87 | */ | 112 | */ |
88 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ | 113 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ |
89 | #define CIST_HOOKED (1<<1) /* call is running a debug hook */ | 114 | #define CIST_LUA (1<<1) /* call is running a Lua function */ |
90 | #define CIST_FRESH (1<<2) /* call is running on a fresh invocation | 115 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ |
116 | #define CIST_FRESH (1<<3) /* call is running on a fresh invocation | ||
91 | of luaV_execute */ | 117 | of luaV_execute */ |
92 | #define CIST_YPCALL (1<<3) /* call is a yieldable protected call */ | 118 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ |
93 | #define CIST_TAIL (1<<4) /* call was tail called */ | 119 | #define CIST_TAIL (1<<5) /* call was tail called */ |
94 | #define CIST_HOOKYIELD (1<<5) /* last hook called yielded */ | 120 | #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ |
95 | #define CIST_LEQ (1<<6) /* using __lt for __le */ | 121 | #define CIST_LEQ (1<<7) /* using __lt for __le */ |
96 | #define CIST_FIN (1<<7) /* call is running a finalizer */ | 122 | #define CIST_FIN (1<<8) /* call is running a finalizer */ |
97 | 123 | ||
98 | #define isLua(func) isLfunction(s2v(func)) | 124 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) |
99 | 125 | ||
100 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ | 126 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ |
101 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) | 127 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) |
@@ -162,7 +188,7 @@ struct lua_State { | |||
162 | lu_byte status; | 188 | lu_byte status; |
163 | StkId top; /* first free slot in the stack */ | 189 | StkId top; /* first free slot in the stack */ |
164 | global_State *l_G; | 190 | global_State *l_G; |
165 | StkId func; /* current function */ | 191 | CallInfo *ci; /* call info for current function */ |
166 | const Instruction *oldpc; /* last pc traced */ | 192 | const Instruction *oldpc; /* last pc traced */ |
167 | StkId stack_last; /* last free slot in the stack */ | 193 | StkId stack_last; /* last free slot in the stack */ |
168 | StkId stack; /* stack base */ | 194 | StkId stack; /* stack base */ |
@@ -170,6 +196,7 @@ struct lua_State { | |||
170 | GCObject *gclist; | 196 | GCObject *gclist; |
171 | struct lua_State *twups; /* list of threads with open upvalues */ | 197 | struct lua_State *twups; /* list of threads with open upvalues */ |
172 | struct lua_longjmp *errorJmp; /* current error recover point */ | 198 | struct lua_longjmp *errorJmp; /* current error recover point */ |
199 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ | ||
173 | volatile lua_Hook hook; | 200 | volatile lua_Hook hook; |
174 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | 201 | ptrdiff_t errfunc; /* current error handling function (stack index) */ |
175 | int stacksize; | 202 | int stacksize; |
@@ -225,6 +252,9 @@ union GCUnion { | |||
225 | 252 | ||
226 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); | 253 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); |
227 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); | 254 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); |
255 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); | ||
256 | LUAI_FUNC void luaE_freeCI (lua_State *L); | ||
257 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); | ||
228 | 258 | ||
229 | 259 | ||
230 | #endif | 260 | #endif |