summaryrefslogtreecommitdiff
path: root/libs/liblua/src/lstate.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/liblua/src/lstate.h')
-rw-r--r--libs/liblua/src/lstate.h195
1 files changed, 153 insertions, 42 deletions
diff --git a/libs/liblua/src/lstate.h b/libs/liblua/src/lstate.h
index 56b3741000..2e8bd6c486 100644
--- a/libs/liblua/src/lstate.h
+++ b/libs/liblua/src/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $
+** $Id: lstate.h $
** Global State
** See Copyright Notice in lua.h
*/
@@ -15,7 +15,6 @@
/*
-
** Some notes about garbage-collected objects: All objects in Lua must
** be kept somehow accessible until being freed, so all objects always
** belong to one (and only one) of these lists, using field 'next' of
@@ -27,6 +26,22 @@
** 'fixedgc': all objects that are not to be collected (currently
** only small strings, such as reserved words).
**
+** For the generational collector, some of these lists have marks for
+** generations. Each mark points to the first element in the list for
+** that particular generation; that generation goes until the next mark.
+**
+** 'allgc' -> 'survival': new objects;
+** 'survival' -> 'old': objects that survived one collection;
+** 'old' -> 'reallyold': objects that became old in last collection;
+** 'reallyold' -> NULL: objects old for more than one cycle.
+**
+** 'finobj' -> 'finobjsur': new objects marked for finalization;
+** 'finobjsur' -> 'finobjold': survived """";
+** 'finobjold' -> 'finobjrold': just old """";
+** 'finobjrold' -> NULL: really old """".
+*/
+
+/*
** Moreover, there is another set of lists that control gray objects.
** These lists are linked by fields 'gclist'. (All objects that
** can become gray have such a field. The field is not the same
@@ -43,9 +58,77 @@
** 'weak': tables with weak values to be cleared;
** 'ephemeron': ephemeron tables with white->white entries;
** 'allweak': tables with weak keys and/or weak values to be cleared.
-** The last three lists are used only during the atomic phase.
+*/
+
+
+/*
+** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
+** how many "C calls" it still can do in the C stack, to avoid C-stack
+** overflow. This count is very rough approximation; it considers only
+** recursive functions inside the interpreter, as non-recursive calls
+** can be considered using a fixed (although unknown) amount of stack
+** space.
+**
+** The count has two parts: the lower part is the count itself; the
+** higher part counts the number of non-yieldable calls in the stack.
+** (They are together so that we can change both with one instruction.)
+**
+** Because calls to external C functions can use an unknown amount
+** of space (e.g., functions using an auxiliary buffer), calls
+** to these functions add more than one to the count (see CSTACKCF).
+**
+** The proper count excludes the number of CallInfo structures allocated
+** by Lua, as a kind of "potential" calls. So, when Lua calls a function
+** (and "consumes" one CallInfo), it needs neither to decrement nor to
+** check 'nCcalls', as its use of C stack is already accounted for.
+*/
+
+/* number of "C stack slots" used by an external C function */
+#define CSTACKCF 10
+
+
+/*
+** The C-stack size is sliced in the following zones:
+** - larger than CSTACKERR: normal stack;
+** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
+** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
+** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
+** (Because the counter can be decremented CSTACKCF at once, we need
+** the so called "buffer zones", with at least that size, to properly
+** detect a change from one zone to the next.)
*/
+#define CSTACKERR (8 * CSTACKCF)
+#define CSTACKMARK (CSTACKERR - (CSTACKCF + 2))
+#define CSTACKERRMARK (CSTACKCF + 2)
+
+
+/* initial limit for the C-stack of threads */
+#define CSTACKTHREAD (2 * CSTACKERR)
+
+
+/* true if this thread does not have non-yieldable calls in the stack */
+#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
+
+/* real number of C calls */
+#define getCcalls(L) ((L)->nCcalls & 0xffff)
+
+
+/* Increment the number of non-yieldable calls */
+#define incnny(L) ((L)->nCcalls += 0x10000)
+
+/* Decrement the number of non-yieldable calls */
+#define decnny(L) ((L)->nCcalls -= 0x10000)
+
+/* Increment the number of non-yieldable calls and decrement nCcalls */
+#define incXCcalls(L) ((L)->nCcalls += 0x10000 - CSTACKCF)
+
+/* Decrement the number of non-yieldable calls and increment nCcalls */
+#define decXCcalls(L) ((L)->nCcalls -= 0x10000 - CSTACKCF)
+
+
+
+
struct lua_longjmp; /* defined in ldo.c */
@@ -69,8 +152,8 @@ struct lua_longjmp; /* defined in ldo.c */
/* kinds of Garbage Collection */
-#define KGC_NORMAL 0
-#define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */
+#define KGC_INC 0 /* incremental gc */
+#define KGC_GEN 1 /* generational gc */
typedef struct stringtable {
@@ -82,12 +165,6 @@ typedef struct stringtable {
/*
** Information about a call.
-** When a thread yields, 'func' is adjusted to pretend that the
-** top function has only the yielded values in its stack; in that
-** case, the actual 'func' value is saved in field 'extra'.
-** When a function calls another with a continuation, 'extra' keeps
-** the function index so that, in case of errors, the continuation
-** function can be called with the correct top.
*/
typedef struct CallInfo {
StkId func; /* function index in the stack */
@@ -95,8 +172,9 @@ typedef struct CallInfo {
struct CallInfo *previous, *next; /* dynamic call link */
union {
struct { /* only for Lua functions */
- StkId base; /* base for this function */
const Instruction *savedpc;
+ volatile l_signalT trap;
+ int nextraargs; /* # of extra arguments in vararg functions */
} l;
struct { /* only for C functions */
lua_KFunction k; /* continuation in case of yields */
@@ -104,7 +182,14 @@ typedef struct CallInfo {
lua_KContext ctx; /* context info. in case of yields */
} c;
} u;
- ptrdiff_t extra;
+ union {
+ int funcidx; /* called-function index */
+ int nyield; /* number of values yielded */
+ struct { /* info about transferred values (for call/return hooks) */
+ unsigned short ftransfer; /* offset of first value transferred */
+ unsigned short ntransfer; /* number of values transferred */
+ } transferinfo;
+ } u2;
short nresults; /* expected number of results from this function */
unsigned short callstatus;
} CallInfo;
@@ -114,17 +199,22 @@ typedef struct CallInfo {
** Bits in CallInfo status
*/
#define CIST_OAH (1<<0) /* original value of 'allowhook' */
-#define CIST_LUA (1<<1) /* call is running a Lua function */
+#define CIST_C (1<<1) /* call is running a C function */
#define CIST_HOOKED (1<<2) /* call is running a debug hook */
-#define CIST_FRESH (1<<3) /* call is running on a fresh invocation
- of luaV_execute */
-#define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
-#define CIST_TAIL (1<<5) /* call was tail called */
-#define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
-#define CIST_LEQ (1<<7) /* using __lt for __le */
-#define CIST_FIN (1<<8) /* call is running a finalizer */
+#define CIST_YPCALL (1<<3) /* call is a yieldable protected call */
+#define CIST_TAIL (1<<4) /* call was tail called */
+#define CIST_HOOKYIELD (1<<5) /* last hook called yielded */
+#define CIST_FIN (1<<6) /* call is running a finalizer */
+#define CIST_TRAN (1<<7) /* 'ci' has transfer information */
+#if defined(LUA_COMPAT_LT_LE)
+#define CIST_LEQ (1<<8) /* using __lt for __le */
+#endif
+
+/* active function is a Lua function */
+#define isLua(ci) (!((ci)->callstatus & CIST_C))
-#define isLua(ci) ((ci)->callstatus & CIST_LUA)
+/* call is running Lua code (not a hook) */
+#define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
@@ -139,15 +229,22 @@ typedef struct global_State {
void *ud; /* auxiliary data to 'frealloc' */
l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
- lu_mem GCmemtrav; /* memory traversed by the GC */
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
+ lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */
stringtable strt; /* hash table for strings */
TValue l_registry;
+ TValue nilvalue; /* a nil value */
unsigned int seed; /* randomized seed for hashes */
lu_byte currentwhite;
lu_byte gcstate; /* state of garbage collector */
lu_byte gckind; /* kind of GC running */
+ lu_byte genminormul; /* control for minor generational collections */
+ lu_byte genmajormul; /* control for major generational collections */
lu_byte gcrunning; /* true if GC is running */
+ lu_byte gcemergency; /* true if this is an emergency collection */
+ lu_byte gcpause; /* size of pause between successive GCs */
+ lu_byte gcstepmul; /* GC "speed" */
+ lu_byte gcstepsize; /* (log2 of) GC granularity */
GCObject *allgc; /* list of all collectable objects */
GCObject **sweepgc; /* current position of sweep in list */
GCObject *finobj; /* list of collectable objects with finalizers */
@@ -158,17 +255,23 @@ typedef struct global_State {
GCObject *allweak; /* list of all-weak tables */
GCObject *tobefnz; /* list of userdata to be GC */
GCObject *fixedgc; /* list of objects not to be collected */
+ /* fields for generational collector */
+ GCObject *survival; /* start of objects that survived one GC cycle */
+ GCObject *old; /* start of old objects */
+ GCObject *reallyold; /* old objects with more than one cycle */
+ GCObject *finobjsur; /* list of survival objects with finalizers */
+ GCObject *finobjold; /* list of old objects with finalizers */
+ GCObject *finobjrold; /* list of really old objects with finalizers */
struct lua_State *twups; /* list of threads with open upvalues */
- unsigned int gcfinnum; /* number of finalizers to call in each GC step */
- int gcpause; /* size of pause between successive GCs */
- int gcstepmul; /* GC 'granularity' */
lua_CFunction panic; /* to be called in unprotected errors */
struct lua_State *mainthread;
- const lua_Number *version; /* pointer to version number */
- TString *memerrmsg; /* memory-error message */
+ TString *memerrmsg; /* message for memory-allocation errors */
TString *tmname[TM_N]; /* array with tag-method names */
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
+ lua_WarnFunction warnf; /* warning function */
+ void *ud_warn; /* auxiliary data to 'warnf' */
+ unsigned int Cstacklimit; /* current limit for the C stack */
} global_State;
@@ -177,8 +280,9 @@ typedef struct global_State {
*/
struct lua_State {
CommonHeader;
- unsigned short nci; /* number of items in 'ci' list */
lu_byte status;
+ lu_byte allowhook;
+ unsigned short nci; /* number of items in 'ci' list */
StkId top; /* first free slot in the stack */
global_State *l_G;
CallInfo *ci; /* call info for current function */
@@ -192,13 +296,11 @@ struct lua_State {
CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
volatile lua_Hook hook;
ptrdiff_t errfunc; /* current error handling function (stack index) */
+ l_uint32 nCcalls; /* number of allowed nested C calls - 'nci' */
int stacksize;
int basehookcount;
int hookcount;
- unsigned short nny; /* number of non-yieldable calls in stack */
- unsigned short nCcalls; /* number of nested C calls */
- l_signalT hookmask;
- lu_byte allowhook;
+ volatile l_signalT hookmask;
};
@@ -216,6 +318,7 @@ union GCUnion {
struct Table h;
struct Proto p;
struct lua_State th; /* thread */
+ struct UpVal upv;
};
@@ -224,19 +327,22 @@ union GCUnion {
/* macros to convert a GCObject into a specific value */
#define gco2ts(o) \
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
-#define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))
-#define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))
-#define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))
+#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
+#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
+#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
-#define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))
-#define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))
-#define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))
+#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
+#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
+#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
+#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
-/* macro to convert a Lua object into a GCObject */
-#define obj2gco(v) \
- check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))
+/*
+** macro to convert a Lua object into a GCObject
+** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
+*/
+#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
/* actual number of total bytes allocated */
@@ -247,7 +353,12 @@ LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
LUAI_FUNC void luaE_freeCI (lua_State *L);
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
+LUAI_FUNC void luaE_enterCcall (lua_State *L);
+LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
+LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
+
+#define luaE_exitCcall(L) ((L)->nCcalls++)
#endif