annotate src/lua/lstate.h @ 68:86093f2ce7d1

got the speedrun to play
author Robert McIntyre <rlm@mit.edu>
date Thu, 08 Mar 2012 02:10:03 -0600
parents 27763b933818
children
rev   line source
rlm@1 1 /*
rlm@1 2 ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
rlm@1 3 ** Global State
rlm@1 4 ** See Copyright Notice in lua.h
rlm@1 5 */
rlm@1 6
rlm@1 7 #ifndef lstate_h
rlm@1 8 #define lstate_h
rlm@1 9
rlm@1 10 #include "lua.h"
rlm@1 11
rlm@1 12 #include "lobject.h"
rlm@1 13 #include "ltm.h"
rlm@1 14 #include "lzio.h"
rlm@1 15
rlm@1 16
rlm@1 17
rlm@1 18 struct lua_longjmp; /* defined in ldo.c */
rlm@1 19
rlm@1 20
rlm@1 21 /* table of globals */
rlm@1 22 #define gt(L) (&L->l_gt)
rlm@1 23
rlm@1 24 /* registry */
rlm@1 25 #define registry(L) (&G(L)->l_registry)
rlm@1 26
rlm@1 27
rlm@1 28 /* extra stack space to handle TM calls and some other extras */
rlm@1 29 #define EXTRA_STACK 5
rlm@1 30
rlm@1 31
rlm@1 32 #define BASIC_CI_SIZE 8
rlm@1 33
rlm@1 34 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
rlm@1 35
rlm@1 36
rlm@1 37
rlm@1 38 typedef struct stringtable {
rlm@1 39 GCObject **hash;
rlm@1 40 lu_int32 nuse; /* number of elements */
rlm@1 41 int size;
rlm@1 42 } stringtable;
rlm@1 43
rlm@1 44
rlm@1 45 /*
rlm@1 46 ** informations about a call
rlm@1 47 */
rlm@1 48 typedef struct CallInfo {
rlm@1 49 StkId base; /* base for this function */
rlm@1 50 StkId func; /* function index in the stack */
rlm@1 51 StkId top; /* top for this function */
rlm@1 52 const Instruction *savedpc;
rlm@1 53 int nresults; /* expected number of results from this function */
rlm@1 54 int tailcalls; /* number of tail calls lost under this entry */
rlm@1 55 } CallInfo;
rlm@1 56
rlm@1 57
rlm@1 58
rlm@1 59 #define curr_func(L) (clvalue(L->ci->func))
rlm@1 60 #define ci_func(ci) (clvalue((ci)->func))
rlm@1 61 #define f_isLua(ci) (!ci_func(ci)->c.isC)
rlm@1 62 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
rlm@1 63
rlm@1 64
rlm@1 65 /*
rlm@1 66 ** `global state', shared by all threads of this state
rlm@1 67 */
rlm@1 68 typedef struct global_State {
rlm@1 69 stringtable strt; /* hash table for strings */
rlm@1 70 lua_Alloc frealloc; /* function to reallocate memory */
rlm@1 71 void *ud; /* auxiliary data to `frealloc' */
rlm@1 72 lu_byte currentwhite;
rlm@1 73 lu_byte gcstate; /* state of garbage collector */
rlm@1 74 int sweepstrgc; /* position of sweep in `strt' */
rlm@1 75 GCObject *rootgc; /* list of all collectable objects */
rlm@1 76 GCObject **sweepgc; /* position of sweep in `rootgc' */
rlm@1 77 GCObject *gray; /* list of gray objects */
rlm@1 78 GCObject *grayagain; /* list of objects to be traversed atomically */
rlm@1 79 GCObject *weak; /* list of weak tables (to be cleared) */
rlm@1 80 GCObject *tmudata; /* last element of list of userdata to be GC */
rlm@1 81 Mbuffer buff; /* temporary buffer for string concatentation */
rlm@1 82 lu_mem GCthreshold;
rlm@1 83 lu_mem totalbytes; /* number of bytes currently allocated */
rlm@1 84 lu_mem estimate; /* an estimate of number of bytes actually in use */
rlm@1 85 lu_mem gcdept; /* how much GC is `behind schedule' */
rlm@1 86 int gcpause; /* size of pause between successive GCs */
rlm@1 87 int gcstepmul; /* GC `granularity' */
rlm@1 88 lua_CFunction panic; /* to be called in unprotected errors */
rlm@1 89 TValue l_registry;
rlm@1 90 struct lua_State *mainthread;
rlm@1 91 UpVal uvhead; /* head of double-linked list of all open upvalues */
rlm@1 92 struct Table *mt[NUM_TAGS]; /* metatables for basic types */
rlm@1 93 TString *tmname[TM_N]; /* array with tag-method names */
rlm@1 94 } global_State;
rlm@1 95
rlm@1 96
rlm@1 97 /*
rlm@1 98 ** `per thread' state
rlm@1 99 */
rlm@1 100 struct lua_State {
rlm@1 101 CommonHeader;
rlm@1 102 lu_byte status;
rlm@1 103 StkId top; /* first free slot in the stack */
rlm@1 104 StkId base; /* base of current function */
rlm@1 105 global_State *l_G;
rlm@1 106 CallInfo *ci; /* call info for current function */
rlm@1 107 const Instruction *savedpc; /* `savedpc' of current function */
rlm@1 108 StkId stack_last; /* last free slot in the stack */
rlm@1 109 StkId stack; /* stack base */
rlm@1 110 CallInfo *end_ci; /* points after end of ci array*/
rlm@1 111 CallInfo *base_ci; /* array of CallInfo's */
rlm@1 112 int stacksize;
rlm@1 113 int size_ci; /* size of array `base_ci' */
rlm@1 114 unsigned short nCcalls; /* number of nested C calls */
rlm@1 115 unsigned short baseCcalls; /* nested C calls when resuming coroutine */
rlm@1 116 lu_byte hookmask;
rlm@1 117 lu_byte allowhook;
rlm@1 118 int basehookcount;
rlm@1 119 int hookcount;
rlm@1 120 lua_Hook hook;
rlm@1 121 TValue l_gt; /* table of globals */
rlm@1 122 TValue env; /* temporary place for environments */
rlm@1 123 GCObject *openupval; /* list of open upvalues in this stack */
rlm@1 124 GCObject *gclist;
rlm@1 125 struct lua_longjmp *errorJmp; /* current error recover point */
rlm@1 126 ptrdiff_t errfunc; /* current error handling function (stack index) */
rlm@1 127 };
rlm@1 128
rlm@1 129
rlm@1 130 #define G(L) (L->l_G)
rlm@1 131
rlm@1 132
rlm@1 133 /*
rlm@1 134 ** Union of all collectable objects
rlm@1 135 */
rlm@1 136 union GCObject {
rlm@1 137 GCheader gch;
rlm@1 138 union TString ts;
rlm@1 139 union Udata u;
rlm@1 140 union Closure cl;
rlm@1 141 struct Table h;
rlm@1 142 struct Proto p;
rlm@1 143 struct UpVal uv;
rlm@1 144 struct lua_State th; /* thread */
rlm@1 145 };
rlm@1 146
rlm@1 147
rlm@1 148 /* macros to convert a GCObject into a specific value */
rlm@1 149 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
rlm@1 150 #define gco2ts(o) (&rawgco2ts(o)->tsv)
rlm@1 151 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
rlm@1 152 #define gco2u(o) (&rawgco2u(o)->uv)
rlm@1 153 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
rlm@1 154 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
rlm@1 155 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
rlm@1 156 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
rlm@1 157 #define ngcotouv(o) \
rlm@1 158 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
rlm@1 159 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
rlm@1 160
rlm@1 161 /* macro to convert any Lua object into a GCObject */
rlm@1 162 #define obj2gco(v) (cast(GCObject *, (v)))
rlm@1 163
rlm@1 164
rlm@1 165 LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
rlm@1 166 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
rlm@1 167
rlm@1 168 #endif
rlm@1 169