Mercurial > vba-clojure
diff src/lua/lstate.h @ 11:27763b933818
raise lua sources up one level
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 11:07:39 -0600 |
parents | src/lua/src/lstate.h@f9f4f1b99eed |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/lua/lstate.h Sat Mar 03 11:07:39 2012 -0600 1.3 @@ -0,0 +1,169 @@ 1.4 +/* 1.5 +** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ 1.6 +** Global State 1.7 +** See Copyright Notice in lua.h 1.8 +*/ 1.9 + 1.10 +#ifndef lstate_h 1.11 +#define lstate_h 1.12 + 1.13 +#include "lua.h" 1.14 + 1.15 +#include "lobject.h" 1.16 +#include "ltm.h" 1.17 +#include "lzio.h" 1.18 + 1.19 + 1.20 + 1.21 +struct lua_longjmp; /* defined in ldo.c */ 1.22 + 1.23 + 1.24 +/* table of globals */ 1.25 +#define gt(L) (&L->l_gt) 1.26 + 1.27 +/* registry */ 1.28 +#define registry(L) (&G(L)->l_registry) 1.29 + 1.30 + 1.31 +/* extra stack space to handle TM calls and some other extras */ 1.32 +#define EXTRA_STACK 5 1.33 + 1.34 + 1.35 +#define BASIC_CI_SIZE 8 1.36 + 1.37 +#define BASIC_STACK_SIZE (2*LUA_MINSTACK) 1.38 + 1.39 + 1.40 + 1.41 +typedef struct stringtable { 1.42 + GCObject **hash; 1.43 + lu_int32 nuse; /* number of elements */ 1.44 + int size; 1.45 +} stringtable; 1.46 + 1.47 + 1.48 +/* 1.49 +** informations about a call 1.50 +*/ 1.51 +typedef struct CallInfo { 1.52 + StkId base; /* base for this function */ 1.53 + StkId func; /* function index in the stack */ 1.54 + StkId top; /* top for this function */ 1.55 + const Instruction *savedpc; 1.56 + int nresults; /* expected number of results from this function */ 1.57 + int tailcalls; /* number of tail calls lost under this entry */ 1.58 +} CallInfo; 1.59 + 1.60 + 1.61 + 1.62 +#define curr_func(L) (clvalue(L->ci->func)) 1.63 +#define ci_func(ci) (clvalue((ci)->func)) 1.64 +#define f_isLua(ci) (!ci_func(ci)->c.isC) 1.65 +#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) 1.66 + 1.67 + 1.68 +/* 1.69 +** `global state', shared by all threads of this state 1.70 +*/ 1.71 +typedef struct global_State { 1.72 + stringtable strt; /* hash table for strings */ 1.73 + lua_Alloc frealloc; /* function to reallocate memory */ 1.74 + void *ud; /* auxiliary data to `frealloc' */ 1.75 + lu_byte currentwhite; 1.76 + lu_byte gcstate; /* state of garbage collector */ 1.77 + int sweepstrgc; /* position of sweep in `strt' */ 1.78 + GCObject *rootgc; /* list of all collectable objects */ 1.79 + GCObject **sweepgc; /* position of sweep in `rootgc' */ 1.80 + GCObject *gray; /* list of gray objects */ 1.81 + GCObject *grayagain; /* list of objects to be traversed atomically */ 1.82 + GCObject *weak; /* list of weak tables (to be cleared) */ 1.83 + GCObject *tmudata; /* last element of list of userdata to be GC */ 1.84 + Mbuffer buff; /* temporary buffer for string concatentation */ 1.85 + lu_mem GCthreshold; 1.86 + lu_mem totalbytes; /* number of bytes currently allocated */ 1.87 + lu_mem estimate; /* an estimate of number of bytes actually in use */ 1.88 + lu_mem gcdept; /* how much GC is `behind schedule' */ 1.89 + int gcpause; /* size of pause between successive GCs */ 1.90 + int gcstepmul; /* GC `granularity' */ 1.91 + lua_CFunction panic; /* to be called in unprotected errors */ 1.92 + TValue l_registry; 1.93 + struct lua_State *mainthread; 1.94 + UpVal uvhead; /* head of double-linked list of all open upvalues */ 1.95 + struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 1.96 + TString *tmname[TM_N]; /* array with tag-method names */ 1.97 +} global_State; 1.98 + 1.99 + 1.100 +/* 1.101 +** `per thread' state 1.102 +*/ 1.103 +struct lua_State { 1.104 + CommonHeader; 1.105 + lu_byte status; 1.106 + StkId top; /* first free slot in the stack */ 1.107 + StkId base; /* base of current function */ 1.108 + global_State *l_G; 1.109 + CallInfo *ci; /* call info for current function */ 1.110 + const Instruction *savedpc; /* `savedpc' of current function */ 1.111 + StkId stack_last; /* last free slot in the stack */ 1.112 + StkId stack; /* stack base */ 1.113 + CallInfo *end_ci; /* points after end of ci array*/ 1.114 + CallInfo *base_ci; /* array of CallInfo's */ 1.115 + int stacksize; 1.116 + int size_ci; /* size of array `base_ci' */ 1.117 + unsigned short nCcalls; /* number of nested C calls */ 1.118 + unsigned short baseCcalls; /* nested C calls when resuming coroutine */ 1.119 + lu_byte hookmask; 1.120 + lu_byte allowhook; 1.121 + int basehookcount; 1.122 + int hookcount; 1.123 + lua_Hook hook; 1.124 + TValue l_gt; /* table of globals */ 1.125 + TValue env; /* temporary place for environments */ 1.126 + GCObject *openupval; /* list of open upvalues in this stack */ 1.127 + GCObject *gclist; 1.128 + struct lua_longjmp *errorJmp; /* current error recover point */ 1.129 + ptrdiff_t errfunc; /* current error handling function (stack index) */ 1.130 +}; 1.131 + 1.132 + 1.133 +#define G(L) (L->l_G) 1.134 + 1.135 + 1.136 +/* 1.137 +** Union of all collectable objects 1.138 +*/ 1.139 +union GCObject { 1.140 + GCheader gch; 1.141 + union TString ts; 1.142 + union Udata u; 1.143 + union Closure cl; 1.144 + struct Table h; 1.145 + struct Proto p; 1.146 + struct UpVal uv; 1.147 + struct lua_State th; /* thread */ 1.148 +}; 1.149 + 1.150 + 1.151 +/* macros to convert a GCObject into a specific value */ 1.152 +#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) 1.153 +#define gco2ts(o) (&rawgco2ts(o)->tsv) 1.154 +#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 1.155 +#define gco2u(o) (&rawgco2u(o)->uv) 1.156 +#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 1.157 +#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 1.158 +#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 1.159 +#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 1.160 +#define ngcotouv(o) \ 1.161 + check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 1.162 +#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) 1.163 + 1.164 +/* macro to convert any Lua object into a GCObject */ 1.165 +#define obj2gco(v) (cast(GCObject *, (v))) 1.166 + 1.167 + 1.168 +LUAI_FUNC lua_State *luaE_newthread (lua_State *L); 1.169 +LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 1.170 + 1.171 +#endif 1.172 +