2009-05-21 19:01:41 +00:00
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** $Id$
|
2009-05-21 19:01:41 +00:00
|
|
|
** Global State
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lstate_h
|
|
|
|
#define lstate_h
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "ltm.h"
|
|
|
|
#include "lzio.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
struct lua_longjmp; /* defined in ldo.c */
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* table of globals */
|
|
|
|
#define gt(L) (&L->l_gt)
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
/* registry */
|
|
|
|
#define registry(L) (&G(L)->l_registry)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* extra stack space to handle TM calls and some other extras */
|
|
|
|
#define EXTRA_STACK 5
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define BASIC_CI_SIZE 8
|
2009-05-21 19:01:41 +00:00
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
2009-05-21 19:01:41 +00:00
|
|
|
|
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change
reduces the number of modifications in the Lua source using some new
defines and because the upstream source is now more flexible.
Unless otherwise stated, l*.[ch] files are taken unmodified from the
upstream lua-5.2.3.
fscanf.c:
file descriptors in rockbox are just ints, they are hidden behind a
void* now so liolib requires less modifications. fscanf is updated to
use void* too.
getc.c: this is a new file required for getc implementation in lauxlib.c
lauxlib.c: LoadF replaced FILE* with int, the rockbox file
descriptor int are cast to FILE* (actually void* due to typedef).
getc uses the PREFIX version. stdin is not used, as per 5.1.4.
lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now
rather than being commented out.
lbitlib.c: use the built-in version from 5.2.3 rather than Reuben
Thomas's external library. Backwards compatible and adds some new bit
operations.
ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have
been removed from rockconf.h
liolib.c: here the implementation has changed to use the LStream from
the original source, and cast the FILE* pointers to int. This has
reduced the number of modifications from the upstream version.
llex.c: the only change from upstream is to remove the locale include.
lmathlib.c: updated from the 5.2.3 version and re-applied the changes
that were made vs 5.1.4 for random numbers and to remove unsupported
float functions.
loadlib.c: upstream version, with the 5.1.4 changes for missing
functions.
lobject.c: upstream version, with ctype.h added and sprintf changed to
snprintf.
loslib.c: upstream version with locale.h removed and 5.1.4 changes for
unsupportable functions.
lstrlib.c: sprintf changed to snprintf.
ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp
in luai_hashnum.
luaconf.h: updated to 5.2.3 version, restored relevant parts from the
original 5.1.4 configuration. The COMPAT defines that are no longer
available are not included.
lundump.c: VERSION macro conflicts with the core Rockbox equivalent.
rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg
equivalent. Moved checkboolean/optboolean functions to this file and out
of core lua files. luaL_getn is no longer available, replaced by
luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs
replacements. rli_init has to be called before setting up the newlib to
avoid overwriting the rb table.
rocklib_aux.pl: use rli_checkboolean from rocklib.c.
rocklua.c: new default bits library used, update the library loading
code with idiomatic 5.2 code.
strcspn.c: no longer needed, but strspn.c is required for strspn in
lbaselib.c
Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651
Reviewed-on: http://gerrit.rockbox.org/774
Tested: Richard Quirk <richard.quirk@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
2014-03-19 18:31:31 +00:00
|
|
|
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
typedef struct stringtable {
|
|
|
|
GCObject **hash;
|
|
|
|
lu_int32 nuse; /* number of elements */
|
|
|
|
int size;
|
|
|
|
} stringtable;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-04-02 18:46:06 +00:00
|
|
|
** informations about a call
|
2009-05-21 19:01:41 +00:00
|
|
|
*/
|
|
|
|
typedef struct CallInfo {
|
2014-04-02 18:46:06 +00:00
|
|
|
StkId base; /* base for this function */
|
2009-05-21 19:01:41 +00:00
|
|
|
StkId func; /* function index in the stack */
|
|
|
|
StkId top; /* top for this function */
|
2014-04-02 18:46:06 +00:00
|
|
|
const Instruction *savedpc;
|
|
|
|
int nresults; /* expected number of results from this function */
|
|
|
|
int tailcalls; /* number of tail calls lost under this entry */
|
2009-05-21 19:01:41 +00:00
|
|
|
} CallInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
#define curr_func(L) (clvalue(L->ci->func))
|
|
|
|
#define ci_func(ci) (clvalue((ci)->func))
|
|
|
|
#define f_isLua(ci) (!ci_func(ci)->c.isC)
|
|
|
|
#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
|
2009-05-21 19:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** `global state', shared by all threads of this state
|
|
|
|
*/
|
|
|
|
typedef struct global_State {
|
2014-04-02 18:46:06 +00:00
|
|
|
stringtable strt; /* hash table for strings */
|
2009-05-21 19:01:41 +00:00
|
|
|
lua_Alloc frealloc; /* function to reallocate memory */
|
|
|
|
void *ud; /* auxiliary data to `frealloc' */
|
|
|
|
lu_byte currentwhite;
|
|
|
|
lu_byte gcstate; /* state of garbage collector */
|
2019-07-12 10:23:52 +00:00
|
|
|
lu_byte gcflags; /* flags for the garbage collector */
|
2009-05-21 19:01:41 +00:00
|
|
|
int sweepstrgc; /* position of sweep in `strt' */
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *rootgc; /* list of all collectable objects */
|
|
|
|
GCObject **sweepgc; /* position of sweep in `rootgc' */
|
2009-05-21 19:01:41 +00:00
|
|
|
GCObject *gray; /* list of gray objects */
|
|
|
|
GCObject *grayagain; /* list of objects to be traversed atomically */
|
2014-04-02 18:46:06 +00:00
|
|
|
GCObject *weak; /* list of weak tables (to be cleared) */
|
|
|
|
GCObject *tmudata; /* last element of list of userdata to be GC */
|
|
|
|
Mbuffer buff; /* temporary buffer for string concatentation */
|
|
|
|
lu_mem GCthreshold;
|
|
|
|
lu_mem totalbytes; /* number of bytes currently allocated */
|
|
|
|
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
|
|
|
lu_mem gcdept; /* how much GC is `behind schedule' */
|
2009-05-21 19:01:41 +00:00
|
|
|
int gcpause; /* size of pause between successive GCs */
|
|
|
|
int gcstepmul; /* GC `granularity' */
|
|
|
|
lua_CFunction panic; /* to be called in unprotected errors */
|
2014-04-02 18:46:06 +00:00
|
|
|
TValue l_registry;
|
2009-05-21 19:01:41 +00:00
|
|
|
struct lua_State *mainthread;
|
2014-04-02 18:46:06 +00:00
|
|
|
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
|
|
|
struct Table *mt[NUM_TAGS]; /* metatables for basic types */
|
2009-05-21 19:01:41 +00:00
|
|
|
TString *tmname[TM_N]; /* array with tag-method names */
|
|
|
|
} global_State;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** `per thread' state
|
|
|
|
*/
|
|
|
|
struct lua_State {
|
|
|
|
CommonHeader;
|
|
|
|
lu_byte status;
|
|
|
|
StkId top; /* first free slot in the stack */
|
2014-04-02 18:46:06 +00:00
|
|
|
StkId base; /* base of current function */
|
2009-05-21 19:01:41 +00:00
|
|
|
global_State *l_G;
|
|
|
|
CallInfo *ci; /* call info for current function */
|
2014-04-02 18:46:06 +00:00
|
|
|
const Instruction *savedpc; /* `savedpc' of current function */
|
2009-05-21 19:01:41 +00:00
|
|
|
StkId stack_last; /* last free slot in the stack */
|
|
|
|
StkId stack; /* stack base */
|
2014-04-02 18:46:06 +00:00
|
|
|
CallInfo *end_ci; /* points after end of ci array*/
|
|
|
|
CallInfo *base_ci; /* array of CallInfo's */
|
2009-05-21 19:01:41 +00:00
|
|
|
int stacksize;
|
2014-04-02 18:46:06 +00:00
|
|
|
int size_ci; /* size of array `base_ci' */
|
2009-05-21 19:01:41 +00:00
|
|
|
unsigned short nCcalls; /* number of nested C calls */
|
2014-04-02 18:46:06 +00:00
|
|
|
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
|
2009-05-21 19:01:41 +00:00
|
|
|
lu_byte hookmask;
|
|
|
|
lu_byte allowhook;
|
|
|
|
int basehookcount;
|
|
|
|
int hookcount;
|
|
|
|
lua_Hook hook;
|
2014-04-02 18:46:06 +00:00
|
|
|
TValue l_gt; /* table of globals */
|
|
|
|
TValue env; /* temporary place for environments */
|
2009-05-21 19:01:41 +00:00
|
|
|
GCObject *openupval; /* list of open upvalues in this stack */
|
|
|
|
GCObject *gclist;
|
|
|
|
struct lua_longjmp *errorJmp; /* current error recover point */
|
|
|
|
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define G(L) (L->l_G)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Union of all collectable objects
|
|
|
|
*/
|
|
|
|
union GCObject {
|
2014-04-02 18:46:06 +00:00
|
|
|
GCheader gch;
|
2009-05-21 19:01:41 +00:00
|
|
|
union TString ts;
|
|
|
|
union Udata u;
|
|
|
|
union Closure cl;
|
|
|
|
struct Table h;
|
|
|
|
struct Proto p;
|
|
|
|
struct UpVal uv;
|
|
|
|
struct lua_State th; /* thread */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* macros to convert a GCObject into a specific value */
|
2014-04-02 18:46:06 +00:00
|
|
|
#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
|
2009-05-21 19:01:41 +00:00
|
|
|
#define gco2ts(o) (&rawgco2ts(o)->tsv)
|
|
|
|
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
|
|
|
|
#define gco2u(o) (&rawgco2u(o)->uv)
|
2014-04-02 18:46:06 +00:00
|
|
|
#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
|
|
|
|
#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
|
2009-05-21 19:01:41 +00:00
|
|
|
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
|
|
|
|
#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
2014-04-02 18:46:06 +00:00
|
|
|
#define ngcotouv(o) \
|
|
|
|
check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
2009-05-21 19:01:41 +00:00
|
|
|
#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
|
|
|
|
|
|
|
|
/* macro to convert any Lua object into a GCObject */
|
|
|
|
#define obj2gco(v) (cast(GCObject *, (v)))
|
|
|
|
|
|
|
|
|
2014-04-02 18:46:06 +00:00
|
|
|
LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
|
2009-05-21 19:01:41 +00:00
|
|
|
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|