1997-11-19 20:31:19 +03:00
|
|
|
/*
|
2018-07-11 22:11:50 +03:00
|
|
|
** $Id: lstate.h $
|
1997-11-19 20:31:19 +03:00
|
|
|
** Global State
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lstate_h
|
|
|
|
#define lstate_h
|
|
|
|
|
1998-06-03 00:37:04 +04:00
|
|
|
#include "lua.h"
|
2001-12-05 23:15:18 +03:00
|
|
|
|
2022-12-14 22:20:39 +03:00
|
|
|
|
|
|
|
/* Some header files included here need this definition */
|
|
|
|
typedef struct CallInfo CallInfo;
|
|
|
|
|
|
|
|
|
2001-12-05 23:15:18 +03:00
|
|
|
#include "lobject.h"
|
|
|
|
#include "ltm.h"
|
2002-10-08 22:46:08 +04:00
|
|
|
#include "lzio.h"
|
1997-11-19 20:31:19 +03:00
|
|
|
|
|
|
|
|
2008-06-26 23:42:45 +04:00
|
|
|
/*
|
2013-09-11 18:09:55 +04:00
|
|
|
** 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
|
|
|
|
** the 'CommonHeader' for the link:
|
2008-06-26 23:42:45 +04:00
|
|
|
**
|
2014-10-30 21:53:28 +03:00
|
|
|
** 'allgc': all objects not marked for finalization;
|
|
|
|
** 'finobj': all objects marked for finalization;
|
2016-12-22 16:08:50 +03:00
|
|
|
** 'tobefnz': all objects ready to be finalized;
|
2014-10-30 21:53:28 +03:00
|
|
|
** 'fixedgc': all objects that are not to be collected (currently
|
2013-08-22 00:09:51 +04:00
|
|
|
** only small strings, such as reserved words).
|
2017-02-15 21:52:13 +03:00
|
|
|
**
|
2019-05-28 21:46:49 +03:00
|
|
|
** 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;
|
2020-07-29 17:34:08 +03:00
|
|
|
** 'old1' -> 'reallyold': objects that became old in last collection;
|
2019-05-28 21:46:49 +03:00
|
|
|
** 'reallyold' -> NULL: objects old for more than one cycle.
|
|
|
|
**
|
|
|
|
** 'finobj' -> 'finobjsur': new objects marked for finalization;
|
2020-07-29 17:34:08 +03:00
|
|
|
** 'finobjsur' -> 'finobjold1': survived """";
|
|
|
|
** 'finobjold1' -> 'finobjrold': just old """";
|
2019-05-28 21:46:49 +03:00
|
|
|
** 'finobjrold' -> NULL: really old """".
|
2020-07-29 17:34:08 +03:00
|
|
|
**
|
|
|
|
** All lists can contain elements older than their main ages, due
|
|
|
|
** to 'luaC_checkfinalizer' and 'udata2finalize', which move
|
|
|
|
** objects between the normal lists and the "marked for finalization"
|
|
|
|
** lists. Moreover, barriers can age young objects in young lists as
|
|
|
|
** OLD0, which then become OLD1. However, a list never contains
|
|
|
|
** elements younger than their main ages.
|
2020-07-29 23:05:47 +03:00
|
|
|
**
|
|
|
|
** The generational collector also uses a pointer 'firstold1', which
|
|
|
|
** points to the first OLD1 object in the list. It is used to optimize
|
|
|
|
** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'
|
|
|
|
** and 'reallyold', but often the list has no OLD1 objects or they are
|
|
|
|
** after 'old1'.) Note the difference between it and 'old1':
|
|
|
|
** 'firstold1': no OLD1 objects before this point; there can be all
|
|
|
|
** ages after it.
|
|
|
|
** 'old1': no objects younger than OLD1 after this point.
|
2019-05-28 21:46:49 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-15 21:52:13 +03:00
|
|
|
** 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
|
|
|
|
** in all objects, but it always has this name.) Any gray object
|
|
|
|
** must belong to one of these lists, and all objects in these lists
|
2020-08-07 20:53:38 +03:00
|
|
|
** must be gray (with two exceptions explained below):
|
2017-02-15 21:52:13 +03:00
|
|
|
**
|
|
|
|
** 'gray': regular gray objects, still waiting to be visited.
|
|
|
|
** 'grayagain': objects that must be revisited at the atomic phase.
|
|
|
|
** That includes
|
|
|
|
** - black objects got in a write barrier;
|
|
|
|
** - all kinds of weak tables during propagation phase;
|
|
|
|
** - all threads.
|
|
|
|
** '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.
|
2020-07-29 23:05:47 +03:00
|
|
|
**
|
2020-08-07 20:53:38 +03:00
|
|
|
** The exceptions to that "gray rule" are:
|
|
|
|
** - TOUCHED2 objects in generational mode stay in a gray list (because
|
|
|
|
** they must be visited again at the end of the cycle), but they are
|
|
|
|
** marked black because assignments to them must activate barriers (to
|
|
|
|
** move them back to TOUCHED1).
|
|
|
|
** - Open upvales are kept gray to avoid barriers, but they stay out
|
|
|
|
** of gray lists. (They don't even have a 'gclist' field.)
|
2008-06-26 23:42:45 +04:00
|
|
|
*/
|
|
|
|
|
1999-05-10 17:54:01 +04:00
|
|
|
|
2018-07-11 22:11:50 +03:00
|
|
|
|
2018-12-27 19:32:29 +03:00
|
|
|
/*
|
2020-09-23 16:18:01 +03:00
|
|
|
** About 'nCcalls': This count has two parts: the lower 16 bits counts
|
|
|
|
** the number of recursive invocations in the C stack; the higher
|
|
|
|
** 16 bits counts the number of non-yieldable calls in the stack.
|
|
|
|
** (They are together so that we can change and save both with one
|
|
|
|
** instruction.)
|
2019-06-12 16:31:38 +03:00
|
|
|
*/
|
2019-06-18 22:52:22 +03:00
|
|
|
|
|
|
|
|
2018-12-27 19:32:29 +03:00
|
|
|
/* 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)
|
|
|
|
|
2020-09-23 16:18:01 +03:00
|
|
|
/* Non-yieldable call increment */
|
|
|
|
#define nyci (0x10000 | 1)
|
2018-12-27 19:32:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-25 20:22:42 +04:00
|
|
|
struct lua_longjmp; /* defined in ldo.c */
|
2001-12-05 23:15:18 +03:00
|
|
|
|
|
|
|
|
2015-12-14 14:54:49 +03:00
|
|
|
/*
|
2016-12-22 16:08:50 +03:00
|
|
|
** Atomic type (relative to signals) to better ensure that 'lua_sethook'
|
2015-12-14 14:54:49 +03:00
|
|
|
** is thread safe
|
|
|
|
*/
|
|
|
|
#if !defined(l_signalT)
|
|
|
|
#include <signal.h>
|
|
|
|
#define l_signalT sig_atomic_t
|
|
|
|
#endif
|
|
|
|
|
2002-01-26 01:14:54 +03:00
|
|
|
|
2020-10-06 21:50:24 +03:00
|
|
|
/*
|
|
|
|
** Extra stack space to handle TM calls and some other extras. This
|
|
|
|
** space is not included in 'stack_last'. It is used only to avoid stack
|
|
|
|
** checks, either because the element will be promptly popped or because
|
|
|
|
** there will be a stack check soon after the push. Function frames
|
|
|
|
** never use this extra space, so it does not need to be kept clean.
|
|
|
|
*/
|
2002-05-08 21:34:23 +04:00
|
|
|
#define EXTRA_STACK 5
|
2002-01-26 01:14:54 +03:00
|
|
|
|
|
|
|
|
2024-06-20 19:43:33 +03:00
|
|
|
/*
|
|
|
|
** Size of cache for strings in the API. 'N' is the number of
|
|
|
|
** sets (better be a prime) and "M" is the size of each set.
|
|
|
|
** (M == 1 makes a direct cache.)
|
|
|
|
*/
|
|
|
|
#if !defined(STRCACHE_N)
|
|
|
|
#define STRCACHE_N 53
|
|
|
|
#define STRCACHE_M 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-01-26 01:14:54 +03:00
|
|
|
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
|
|
|
|
2022-10-29 18:06:37 +03:00
|
|
|
#define stacksize(th) cast_int((th)->stack_last.p - (th)->stack.p)
|
2020-10-06 21:50:24 +03:00
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
|
2008-02-11 18:45:30 +03:00
|
|
|
/* kinds of Garbage Collection */
|
2017-04-24 19:59:26 +03:00
|
|
|
#define KGC_INC 0 /* incremental gc */
|
2023-12-06 16:49:56 +03:00
|
|
|
#define KGC_GENMINOR 1 /* generational gc in minor (regular) mode */
|
|
|
|
#define KGC_GENMAJOR 2 /* generational in major mode */
|
2008-02-11 18:45:30 +03:00
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
|
1999-05-10 17:54:01 +04:00
|
|
|
typedef struct stringtable {
|
2022-11-29 16:37:08 +03:00
|
|
|
TString **hash; /* array of buckets (linked lists of strings) */
|
2013-08-22 19:21:48 +04:00
|
|
|
int nuse; /* number of elements */
|
2022-11-29 16:37:08 +03:00
|
|
|
int size; /* number of buckets */
|
1997-11-19 20:31:19 +03:00
|
|
|
} stringtable;
|
|
|
|
|
|
|
|
|
2017-11-07 16:25:26 +03:00
|
|
|
/*
|
|
|
|
** Information about a call.
|
2021-01-25 16:39:18 +03:00
|
|
|
** About union 'u':
|
|
|
|
** - field 'l' is used only for Lua functions;
|
|
|
|
** - field 'c' is used only for C functions.
|
|
|
|
** About union 'u2':
|
|
|
|
** - field 'funcidx' is used only by C functions while doing a
|
|
|
|
** protected call;
|
|
|
|
** - field 'nyield' is used only while a function is "doing" an
|
|
|
|
** yield (from the yield until the next resume);
|
2021-02-12 19:36:30 +03:00
|
|
|
** - field 'nres' is used only while closing tbc variables when
|
2021-04-16 21:41:44 +03:00
|
|
|
** returning from a function;
|
2017-11-07 16:25:26 +03:00
|
|
|
*/
|
2022-12-14 22:20:39 +03:00
|
|
|
struct CallInfo {
|
2022-10-29 18:06:37 +03:00
|
|
|
StkIdRel func; /* function index in the stack */
|
|
|
|
StkIdRel top; /* top for this function */
|
2017-11-07 16:25:26 +03:00
|
|
|
struct CallInfo *previous, *next; /* dynamic call link */
|
|
|
|
union {
|
|
|
|
struct { /* only for Lua functions */
|
|
|
|
const Instruction *savedpc;
|
2023-07-25 22:50:44 +03:00
|
|
|
volatile l_signalT trap; /* function is tracing lines/counts */
|
2018-02-09 18:16:06 +03:00
|
|
|
int nextraargs; /* # of extra arguments in vararg functions */
|
2017-11-07 16:25:26 +03:00
|
|
|
} l;
|
|
|
|
struct { /* only for C functions */
|
|
|
|
lua_KFunction k; /* continuation in case of yields */
|
|
|
|
ptrdiff_t old_errfunc;
|
|
|
|
lua_KContext ctx; /* context info. in case of yields */
|
|
|
|
} c;
|
|
|
|
} u;
|
|
|
|
union {
|
|
|
|
int funcidx; /* called-function index */
|
|
|
|
int nyield; /* number of values yielded */
|
2021-02-12 19:36:30 +03:00
|
|
|
int nres; /* number of values returned */
|
2017-11-07 16:25:26 +03:00
|
|
|
} u2;
|
2024-07-21 20:56:59 +03:00
|
|
|
l_uint32 callstatus;
|
2022-12-14 22:20:39 +03:00
|
|
|
};
|
2017-11-07 16:25:26 +03:00
|
|
|
|
2002-07-16 18:26:56 +04:00
|
|
|
|
2008-08-26 17:27:42 +04:00
|
|
|
/*
|
|
|
|
** Bits in CallInfo status
|
|
|
|
*/
|
2024-07-21 20:56:59 +03:00
|
|
|
/* bits 0-7 are the expected number of results from this function + 1 */
|
|
|
|
#define CIST_NRESULTS 0xff
|
|
|
|
/* original value of 'allowhook' */
|
|
|
|
#define CIST_OAH (cast(l_uint32, 1) << 8)
|
|
|
|
/* call is running a C function */
|
|
|
|
#define CIST_C (cast(l_uint32, 1) << 9)
|
|
|
|
/* call is on a fresh "luaV_execute" frame */
|
|
|
|
#define CIST_FRESH (cast(l_uint32, 1) << 10)
|
|
|
|
/* call is running a debug hook */
|
|
|
|
#define CIST_HOOKED (cast(l_uint32, 1) << 11)
|
|
|
|
/* doing a yieldable protected call */
|
|
|
|
#define CIST_YPCALL (cast(l_uint32, 1) << 12)
|
|
|
|
/* call was tail called */
|
|
|
|
#define CIST_TAIL (cast(l_uint32, 1) << 13)
|
|
|
|
/* last hook called yielded */
|
|
|
|
#define CIST_HOOKYIELD (cast(l_uint32, 1) << 14)
|
|
|
|
/* function "called" a finalizer */
|
|
|
|
#define CIST_FIN (cast(l_uint32, 1) << 15)
|
|
|
|
/* function is closing tbc variables */
|
2024-07-30 16:16:19 +03:00
|
|
|
#define CIST_CLSRET (cast(l_uint32, 1) << 16)
|
|
|
|
/* Bits 17-19 are used for CIST_RECST (see below) */
|
|
|
|
#define CIST_RECST 17 /* the offset, not the mask */
|
2018-08-24 16:17:54 +03:00
|
|
|
#if defined(LUA_COMPAT_LT_LE)
|
2024-07-21 20:56:59 +03:00
|
|
|
/* using __lt for __le */
|
2024-07-30 16:16:19 +03:00
|
|
|
#define CIST_LEQ (cast(l_uint32, 1) << 20)
|
2018-08-24 16:17:54 +03:00
|
|
|
#endif
|
2002-07-16 18:26:56 +04:00
|
|
|
|
2021-01-18 17:40:45 +03:00
|
|
|
|
2024-07-21 20:56:59 +03:00
|
|
|
#define get_nresults(cs) (cast_int((cs) & CIST_NRESULTS) - 1)
|
|
|
|
|
2021-01-18 17:40:45 +03:00
|
|
|
/*
|
|
|
|
** Field CIST_RECST stores the "recover status", used to keep the error
|
|
|
|
** status while closing to-be-closed variables in coroutines, so that
|
|
|
|
** Lua can correctly resume after an yield from a __close method called
|
|
|
|
** because of an error. (Three bits are enough for error status.)
|
|
|
|
*/
|
|
|
|
#define getcistrecst(ci) (((ci)->callstatus >> CIST_RECST) & 7)
|
|
|
|
#define setcistrecst(ci,st) \
|
|
|
|
check_exp(((st) & 7) == (st), /* status must fit in three bits */ \
|
2024-07-27 19:32:59 +03:00
|
|
|
((ci)->callstatus = ((ci)->callstatus & ~(7u << CIST_RECST)) \
|
2024-07-21 20:56:59 +03:00
|
|
|
| (cast(l_uint32, st) << CIST_RECST)))
|
2021-01-18 17:40:45 +03:00
|
|
|
|
|
|
|
|
2017-12-19 19:40:17 +03:00
|
|
|
/* active function is a Lua function */
|
|
|
|
#define isLua(ci) (!((ci)->callstatus & CIST_C))
|
|
|
|
|
|
|
|
/* call is running Lua code (not a hook) */
|
|
|
|
#define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
|
2001-12-18 23:52:30 +03:00
|
|
|
|
2024-07-21 20:56:59 +03:00
|
|
|
|
|
|
|
#define setoah(ci,v) \
|
|
|
|
((ci)->callstatus = ((v) ? (ci)->callstatus | CIST_OAH \
|
|
|
|
: (ci)->callstatus & ~CIST_OAH))
|
|
|
|
#define getoah(ci) (((ci)->callstatus & CIST_OAH) ? 1 : 0)
|
2014-06-12 23:07:30 +04:00
|
|
|
|
2001-12-18 23:52:30 +03:00
|
|
|
|
2001-01-19 16:20:30 +03:00
|
|
|
/*
|
2014-10-25 15:50:46 +04:00
|
|
|
** 'global state', shared by all threads of this state
|
2001-01-19 16:20:30 +03:00
|
|
|
*/
|
|
|
|
typedef struct global_State {
|
2005-02-23 20:30:22 +03:00
|
|
|
lua_Alloc frealloc; /* function to reallocate memory */
|
2014-10-25 15:50:46 +04:00
|
|
|
void *ud; /* auxiliary data to 'frealloc' */
|
2024-09-20 01:02:14 +03:00
|
|
|
l_mem GCtotalbytes; /* number of bytes currently allocated + debt */
|
|
|
|
l_mem GCdebt; /* bytes counted but not yet allocated */
|
|
|
|
l_mem GCmarked; /* number of objects marked in a GC cycle */
|
|
|
|
l_mem GCmajorminor; /* auxiliary counter to control major-minor shifts */
|
2010-03-25 22:37:23 +03:00
|
|
|
stringtable strt; /* hash table for strings */
|
|
|
|
TValue l_registry;
|
2018-06-15 22:31:22 +03:00
|
|
|
TValue nilvalue; /* a nil value */
|
2012-02-02 01:57:15 +04:00
|
|
|
unsigned int seed; /* randomized seed for hashes */
|
2023-12-22 20:48:07 +03:00
|
|
|
lu_byte gcparams[LUA_GCPN];
|
2004-08-25 00:12:06 +04:00
|
|
|
lu_byte currentwhite;
|
|
|
|
lu_byte gcstate; /* state of garbage collector */
|
2008-02-11 18:45:30 +03:00
|
|
|
lu_byte gckind; /* kind of GC running */
|
2021-02-26 17:41:02 +03:00
|
|
|
lu_byte gcstopem; /* stops emergency collections */
|
2021-12-13 16:41:17 +03:00
|
|
|
lu_byte gcstp; /* control whether GC is running */
|
2017-04-24 19:59:26 +03:00
|
|
|
lu_byte gcemergency; /* true if this is an emergency collection */
|
2010-03-24 16:07:01 +03:00
|
|
|
GCObject *allgc; /* list of all collectable objects */
|
2013-08-30 23:14:26 +04:00
|
|
|
GCObject **sweepgc; /* current position of sweep in list */
|
2013-09-03 19:37:10 +04:00
|
|
|
GCObject *finobj; /* list of collectable objects with finalizers */
|
2003-11-18 17:55:11 +03:00
|
|
|
GCObject *gray; /* list of gray objects */
|
2003-12-04 21:52:23 +03:00
|
|
|
GCObject *grayagain; /* list of objects to be traversed atomically */
|
2008-02-19 21:55:09 +03:00
|
|
|
GCObject *weak; /* list of tables with weak values */
|
|
|
|
GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
|
2007-10-31 18:41:19 +03:00
|
|
|
GCObject *allweak; /* list of all-weak tables */
|
2008-06-26 23:42:45 +04:00
|
|
|
GCObject *tobefnz; /* list of userdata to be GC */
|
2013-08-22 00:09:51 +04:00
|
|
|
GCObject *fixedgc; /* list of objects not to be collected */
|
2017-02-24 00:07:34 +03:00
|
|
|
/* fields for generational collector */
|
|
|
|
GCObject *survival; /* start of objects that survived one GC cycle */
|
2020-07-29 17:34:08 +03:00
|
|
|
GCObject *old1; /* start of old1 objects */
|
|
|
|
GCObject *reallyold; /* objects more than one cycle old ("really old") */
|
2020-07-29 23:05:47 +03:00
|
|
|
GCObject *firstold1; /* first OLD1 object in the list (if any) */
|
2017-04-05 19:50:51 +03:00
|
|
|
GCObject *finobjsur; /* list of survival objects with finalizers */
|
2020-07-29 17:34:08 +03:00
|
|
|
GCObject *finobjold1; /* list of old1 objects with finalizers */
|
2017-04-05 19:50:51 +03:00
|
|
|
GCObject *finobjrold; /* list of really old objects with finalizers */
|
2014-02-18 17:39:37 +04:00
|
|
|
struct lua_State *twups; /* list of threads with open upvalues */
|
2002-04-16 21:08:28 +04:00
|
|
|
lua_CFunction panic; /* to be called in unprotected errors */
|
2002-10-26 00:05:28 +04:00
|
|
|
struct lua_State *mainthread;
|
2018-02-15 21:06:24 +03:00
|
|
|
TString *memerrmsg; /* message for memory-allocation errors */
|
2010-03-22 21:28:03 +03:00
|
|
|
TString *tmname[TM_N]; /* array with tag-method names */
|
2022-12-14 22:20:39 +03:00
|
|
|
struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */
|
2015-09-22 17:18:24 +03:00
|
|
|
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
2018-12-28 20:42:34 +03:00
|
|
|
lua_WarnFunction warnf; /* warning function */
|
|
|
|
void *ud_warn; /* auxiliary data to 'warnf' */
|
2001-01-19 16:20:30 +03:00
|
|
|
} global_State;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-10-25 15:50:46 +04:00
|
|
|
** 'per thread' state
|
2001-01-19 16:20:30 +03:00
|
|
|
*/
|
|
|
|
struct lua_State {
|
2002-10-26 00:05:28 +04:00
|
|
|
CommonHeader;
|
2006-02-06 21:27:59 +03:00
|
|
|
lu_byte status;
|
2018-12-27 19:32:29 +03:00
|
|
|
lu_byte allowhook;
|
|
|
|
unsigned short nci; /* number of items in 'ci' list */
|
2022-10-29 18:06:37 +03:00
|
|
|
StkIdRel top; /* first free slot in the stack */
|
2005-07-09 17:22:34 +04:00
|
|
|
global_State *l_G;
|
2017-11-07 16:25:26 +03:00
|
|
|
CallInfo *ci; /* call info for current function */
|
2022-10-29 18:06:37 +03:00
|
|
|
StkIdRel stack_last; /* end of stack (last element + 1) */
|
|
|
|
StkIdRel stack; /* stack base */
|
2013-08-27 22:53:35 +04:00
|
|
|
UpVal *openupval; /* list of open upvalues in this stack */
|
2022-10-29 18:06:37 +03:00
|
|
|
StkIdRel tbclist; /* list of to-be-closed variables */
|
2002-11-13 14:32:26 +03:00
|
|
|
GCObject *gclist;
|
2014-02-18 17:39:37 +04:00
|
|
|
struct lua_State *twups; /* list of threads with open upvalues */
|
2002-08-05 21:36:24 +04:00
|
|
|
struct lua_longjmp *errorJmp; /* current error recover point */
|
2017-11-07 16:25:26 +03:00
|
|
|
CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
|
2015-12-16 19:39:38 +03:00
|
|
|
volatile lua_Hook hook;
|
2014-07-23 21:15:43 +04:00
|
|
|
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
2020-09-23 16:18:01 +03:00
|
|
|
l_uint32 nCcalls; /* number of nested (non-yieldable | C) calls */
|
2020-07-17 17:01:05 +03:00
|
|
|
int oldpc; /* last pc traced */
|
2014-07-23 21:15:43 +04:00
|
|
|
int basehookcount;
|
|
|
|
int hookcount;
|
2020-05-22 17:40:34 +03:00
|
|
|
volatile l_signalT hookmask;
|
2024-07-30 16:16:19 +03:00
|
|
|
struct { /* info about transferred values (for call/return hooks) */
|
|
|
|
int ftransfer; /* offset of first value transferred */
|
|
|
|
int ntransfer; /* number of values transferred */
|
|
|
|
} transferinfo;
|
1998-06-03 00:37:04 +04:00
|
|
|
};
|
1997-11-19 20:31:19 +03:00
|
|
|
|
|
|
|
|
2005-07-09 17:22:34 +04:00
|
|
|
#define G(L) (L->l_G)
|
2001-01-19 16:20:30 +03:00
|
|
|
|
2021-02-05 23:51:25 +03:00
|
|
|
/*
|
|
|
|
** 'g->nilvalue' being a nil value flags that the state was completely
|
|
|
|
** build.
|
|
|
|
*/
|
|
|
|
#define completestate(g) ttisnil(&g->nilvalue)
|
|
|
|
|
2001-01-19 16:20:30 +03:00
|
|
|
|
2002-10-26 00:05:28 +04:00
|
|
|
/*
|
2014-07-18 16:17:54 +04:00
|
|
|
** Union of all collectable objects (only for conversions)
|
2020-09-16 20:57:51 +03:00
|
|
|
** ISO C99, 6.5.2.3 p.5:
|
|
|
|
** "if a union contains several structures that share a common initial
|
|
|
|
** sequence [...], and if the union object currently contains one
|
|
|
|
** of these structures, it is permitted to inspect the common initial
|
|
|
|
** part of any of them anywhere that a declaration of the complete type
|
|
|
|
** of the union is visible."
|
2002-10-26 00:05:28 +04:00
|
|
|
*/
|
2014-07-17 21:09:50 +04:00
|
|
|
union GCUnion {
|
|
|
|
GCObject gc; /* common header */
|
2014-07-18 17:36:14 +04:00
|
|
|
struct TString ts;
|
2014-07-18 18:46:47 +04:00
|
|
|
struct Udata u;
|
2002-10-26 00:05:28 +04:00
|
|
|
union Closure cl;
|
|
|
|
struct Table h;
|
|
|
|
struct Proto p;
|
|
|
|
struct lua_State th; /* thread */
|
2017-04-11 21:41:09 +03:00
|
|
|
struct UpVal upv;
|
2002-10-26 00:05:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-09-16 20:57:51 +03:00
|
|
|
/*
|
|
|
|
** ISO C99, 6.7.2.1 p.14:
|
|
|
|
** "A pointer to a union object, suitably converted, points to each of
|
|
|
|
** its members [...], and vice versa."
|
|
|
|
*/
|
2014-07-17 21:09:50 +04:00
|
|
|
#define cast_u(o) cast(union GCUnion *, (o))
|
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
/* macros to convert a GCObject into a specific value */
|
2014-07-18 17:36:14 +04:00
|
|
|
#define gco2ts(o) \
|
2014-07-17 21:27:49 +04:00
|
|
|
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
|
2020-01-31 17:09:53 +03:00
|
|
|
#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))
|
2012-01-21 02:05:50 +04:00
|
|
|
#define gco2cl(o) \
|
2014-07-17 21:27:49 +04:00
|
|
|
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
|
2020-01-31 17:09:53 +03:00
|
|
|
#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))
|
2014-07-17 21:09:50 +04:00
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
|
2018-02-25 15:43:52 +03:00
|
|
|
/*
|
|
|
|
** 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))
|
2014-07-18 16:17:54 +04:00
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
|
2024-09-20 01:02:14 +03:00
|
|
|
/* actual number of total memory allocated */
|
|
|
|
#define gettotalbytes(g) ((g)->GCtotalbytes - (g)->GCdebt)
|
2022-11-23 23:17:20 +03:00
|
|
|
|
2010-12-20 22:40:07 +03:00
|
|
|
|
2024-09-20 01:02:14 +03:00
|
|
|
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
|
2005-04-25 23:24:10 +04:00
|
|
|
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
2024-09-30 20:01:42 +03:00
|
|
|
LUAI_FUNC size_t luaE_statesize (lua_State *L);
|
2017-11-07 16:25:26 +03:00
|
|
|
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
|
|
|
|
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
|
2020-09-23 16:18:01 +03:00
|
|
|
LUAI_FUNC void luaE_checkcstack (lua_State *L);
|
|
|
|
LUAI_FUNC void luaE_incCstack (lua_State *L);
|
2019-03-14 21:30:54 +03:00
|
|
|
LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
|
2019-08-16 15:51:54 +03:00
|
|
|
LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
|
2020-12-28 22:34:07 +03:00
|
|
|
LUAI_FUNC int luaE_resetthread (lua_State *L, int status);
|
2018-12-27 19:32:29 +03:00
|
|
|
|
2009-04-17 18:28:06 +04:00
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
#endif
|
1999-02-04 20:47:59 +03:00
|
|
|
|