diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
commit | bfd0179042b0b02fb88748d54e56e7e208bb117f (patch) | |
tree | 42d5fd51574054caaf673420fca1ec962d62d2f2 /apps/plugins/lua/lstate.h | |
parent | 36378988ad4059982742f05f5eb50580b456840a (diff) | |
download | rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.gz rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.zip |
Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and
application builds. I checked only a few random native builds
unfortunately. Sorry for inconvenience.
Diffstat (limited to 'apps/plugins/lua/lstate.h')
-rw-r--r-- | apps/plugins/lua/lstate.h | 149 |
1 files changed, 45 insertions, 104 deletions
diff --git a/apps/plugins/lua/lstate.h b/apps/plugins/lua/lstate.h index daffd9aacf..94a6249461 100644 --- a/apps/plugins/lua/lstate.h +++ b/apps/plugins/lua/lstate.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.82.1.1 2013/04/12 18:48:47 roberto Exp $ | 2 | ** $Id$ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -14,46 +14,25 @@ | |||
14 | #include "lzio.h" | 14 | #include "lzio.h" |
15 | 15 | ||
16 | 16 | ||
17 | /* | ||
18 | |||
19 | ** Some notes about garbage-collected objects: All objects in Lua must | ||
20 | ** be kept somehow accessible until being freed. | ||
21 | ** | ||
22 | ** Lua keeps most objects linked in list g->allgc. The link uses field | ||
23 | ** 'next' of the CommonHeader. | ||
24 | ** | ||
25 | ** Strings are kept in several lists headed by the array g->strt.hash. | ||
26 | ** | ||
27 | ** Open upvalues are not subject to independent garbage collection. They | ||
28 | ** are collected together with their respective threads. Lua keeps a | ||
29 | ** double-linked list with all open upvalues (g->uvhead) so that it can | ||
30 | ** mark objects referred by them. (They are always gray, so they must | ||
31 | ** be remarked in the atomic step. Usually their contents would be marked | ||
32 | ** when traversing the respective threads, but the thread may already be | ||
33 | ** dead, while the upvalue is still accessible through closures.) | ||
34 | ** | ||
35 | ** Objects with finalizers are kept in the list g->finobj. | ||
36 | ** | ||
37 | ** The list g->tobefnz links all objects being finalized. | ||
38 | 17 | ||
39 | */ | 18 | struct lua_longjmp; /* defined in ldo.c */ |
40 | 19 | ||
41 | 20 | ||
42 | struct lua_longjmp; /* defined in ldo.c */ | 21 | /* table of globals */ |
22 | #define gt(L) (&L->l_gt) | ||
43 | 23 | ||
24 | /* registry */ | ||
25 | #define registry(L) (&G(L)->l_registry) | ||
44 | 26 | ||
45 | 27 | ||
46 | /* extra stack space to handle TM calls and some other extras */ | 28 | /* extra stack space to handle TM calls and some other extras */ |
47 | #define EXTRA_STACK 5 | 29 | #define EXTRA_STACK 5 |
48 | 30 | ||
49 | 31 | ||
50 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) | 32 | #define BASIC_CI_SIZE 8 |
51 | 33 | ||
34 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) | ||
52 | 35 | ||
53 | /* kinds of Garbage Collection */ | ||
54 | #define KGC_NORMAL 0 | ||
55 | #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */ | ||
56 | #define KGC_GEN 2 /* generational collection */ | ||
57 | 36 | ||
58 | 37 | ||
59 | typedef struct stringtable { | 38 | typedef struct stringtable { |
@@ -64,87 +43,54 @@ typedef struct stringtable { | |||
64 | 43 | ||
65 | 44 | ||
66 | /* | 45 | /* |
67 | ** information about a call | 46 | ** informations about a call |
68 | */ | 47 | */ |
69 | typedef struct CallInfo { | 48 | typedef struct CallInfo { |
49 | StkId base; /* base for this function */ | ||
70 | StkId func; /* function index in the stack */ | 50 | StkId func; /* function index in the stack */ |
71 | StkId top; /* top for this function */ | 51 | StkId top; /* top for this function */ |
72 | struct CallInfo *previous, *next; /* dynamic call link */ | 52 | const Instruction *savedpc; |
73 | short nresults; /* expected number of results from this function */ | 53 | int nresults; /* expected number of results from this function */ |
74 | lu_byte callstatus; | 54 | int tailcalls; /* number of tail calls lost under this entry */ |
75 | ptrdiff_t extra; | ||
76 | union { | ||
77 | struct { /* only for Lua functions */ | ||
78 | StkId base; /* base for this function */ | ||
79 | const Instruction *savedpc; | ||
80 | } l; | ||
81 | struct { /* only for C functions */ | ||
82 | int ctx; /* context info. in case of yields */ | ||
83 | lua_CFunction k; /* continuation in case of yields */ | ||
84 | ptrdiff_t old_errfunc; | ||
85 | lu_byte old_allowhook; | ||
86 | lu_byte status; | ||
87 | } c; | ||
88 | } u; | ||
89 | } CallInfo; | 55 | } CallInfo; |
90 | 56 | ||
91 | 57 | ||
92 | /* | ||
93 | ** Bits in CallInfo status | ||
94 | */ | ||
95 | #define CIST_LUA (1<<0) /* call is running a Lua function */ | ||
96 | #define CIST_HOOKED (1<<1) /* call is running a debug hook */ | ||
97 | #define CIST_REENTRY (1<<2) /* call is running on same invocation of | ||
98 | luaV_execute of previous call */ | ||
99 | #define CIST_YIELDED (1<<3) /* call reentered after suspension */ | ||
100 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ | ||
101 | #define CIST_STAT (1<<5) /* call has an error status (pcall) */ | ||
102 | #define CIST_TAIL (1<<6) /* call was tail called */ | ||
103 | #define CIST_HOOKYIELD (1<<7) /* last hook called yielded */ | ||
104 | |||
105 | 58 | ||
106 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) | 59 | #define curr_func(L) (clvalue(L->ci->func)) |
60 | #define ci_func(ci) (clvalue((ci)->func)) | ||
61 | #define f_isLua(ci) (!ci_func(ci)->c.isC) | ||
62 | #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) | ||
107 | 63 | ||
108 | 64 | ||
109 | /* | 65 | /* |
110 | ** `global state', shared by all threads of this state | 66 | ** `global state', shared by all threads of this state |
111 | */ | 67 | */ |
112 | typedef struct global_State { | 68 | typedef struct global_State { |
69 | stringtable strt; /* hash table for strings */ | ||
113 | lua_Alloc frealloc; /* function to reallocate memory */ | 70 | lua_Alloc frealloc; /* function to reallocate memory */ |
114 | void *ud; /* auxiliary data to `frealloc' */ | 71 | void *ud; /* auxiliary data to `frealloc' */ |
115 | lu_mem totalbytes; /* number of bytes currently allocated - GCdebt */ | ||
116 | l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ | ||
117 | lu_mem GCmemtrav; /* memory traversed by the GC */ | ||
118 | lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ | ||
119 | stringtable strt; /* hash table for strings */ | ||
120 | TValue l_registry; | ||
121 | unsigned int seed; /* randomized seed for hashes */ | ||
122 | lu_byte currentwhite; | 72 | lu_byte currentwhite; |
123 | lu_byte gcstate; /* state of garbage collector */ | 73 | lu_byte gcstate; /* state of garbage collector */ |
124 | lu_byte gckind; /* kind of GC running */ | ||
125 | lu_byte gcrunning; /* true if GC is running */ | ||
126 | int sweepstrgc; /* position of sweep in `strt' */ | 74 | int sweepstrgc; /* position of sweep in `strt' */ |
127 | GCObject *allgc; /* list of all collectable objects */ | 75 | GCObject *rootgc; /* list of all collectable objects */ |
128 | GCObject *finobj; /* list of collectable objects with finalizers */ | 76 | GCObject **sweepgc; /* position of sweep in `rootgc' */ |
129 | GCObject **sweepgc; /* current position of sweep in list 'allgc' */ | ||
130 | GCObject **sweepfin; /* current position of sweep in list 'finobj' */ | ||
131 | GCObject *gray; /* list of gray objects */ | 77 | GCObject *gray; /* list of gray objects */ |
132 | GCObject *grayagain; /* list of objects to be traversed atomically */ | 78 | GCObject *grayagain; /* list of objects to be traversed atomically */ |
133 | GCObject *weak; /* list of tables with weak values */ | 79 | GCObject *weak; /* list of weak tables (to be cleared) */ |
134 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ | 80 | GCObject *tmudata; /* last element of list of userdata to be GC */ |
135 | GCObject *allweak; /* list of all-weak tables */ | 81 | Mbuffer buff; /* temporary buffer for string concatentation */ |
136 | GCObject *tobefnz; /* list of userdata to be GC */ | 82 | lu_mem GCthreshold; |
137 | UpVal uvhead; /* head of double-linked list of all open upvalues */ | 83 | lu_mem totalbytes; /* number of bytes currently allocated */ |
138 | Mbuffer buff; /* temporary buffer for string concatenation */ | 84 | lu_mem estimate; /* an estimate of number of bytes actually in use */ |
85 | lu_mem gcdept; /* how much GC is `behind schedule' */ | ||
139 | int gcpause; /* size of pause between successive GCs */ | 86 | int gcpause; /* size of pause between successive GCs */ |
140 | int gcmajorinc; /* pause between major collections (only in gen. mode) */ | ||
141 | int gcstepmul; /* GC `granularity' */ | 87 | int gcstepmul; /* GC `granularity' */ |
142 | lua_CFunction panic; /* to be called in unprotected errors */ | 88 | lua_CFunction panic; /* to be called in unprotected errors */ |
89 | TValue l_registry; | ||
143 | struct lua_State *mainthread; | 90 | struct lua_State *mainthread; |
144 | const lua_Number *version; /* pointer to version number */ | 91 | UpVal uvhead; /* head of double-linked list of all open upvalues */ |
145 | TString *memerrmsg; /* memory-error message */ | 92 | struct Table *mt[NUM_TAGS]; /* metatables for basic types */ |
146 | TString *tmname[TM_N]; /* array with tag-method names */ | 93 | TString *tmname[TM_N]; /* array with tag-method names */ |
147 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ | ||
148 | } global_State; | 94 | } global_State; |
149 | 95 | ||
150 | 96 | ||
@@ -155,24 +101,29 @@ struct lua_State { | |||
155 | CommonHeader; | 101 | CommonHeader; |
156 | lu_byte status; | 102 | lu_byte status; |
157 | StkId top; /* first free slot in the stack */ | 103 | StkId top; /* first free slot in the stack */ |
104 | StkId base; /* base of current function */ | ||
158 | global_State *l_G; | 105 | global_State *l_G; |
159 | CallInfo *ci; /* call info for current function */ | 106 | CallInfo *ci; /* call info for current function */ |
160 | const Instruction *oldpc; /* last pc traced */ | 107 | const Instruction *savedpc; /* `savedpc' of current function */ |
161 | StkId stack_last; /* last free slot in the stack */ | 108 | StkId stack_last; /* last free slot in the stack */ |
162 | StkId stack; /* stack base */ | 109 | StkId stack; /* stack base */ |
110 | CallInfo *end_ci; /* points after end of ci array*/ | ||
111 | CallInfo *base_ci; /* array of CallInfo's */ | ||
163 | int stacksize; | 112 | int stacksize; |
164 | unsigned short nny; /* number of non-yieldable calls in stack */ | 113 | int size_ci; /* size of array `base_ci' */ |
165 | unsigned short nCcalls; /* number of nested C calls */ | 114 | unsigned short nCcalls; /* number of nested C calls */ |
115 | unsigned short baseCcalls; /* nested C calls when resuming coroutine */ | ||
166 | lu_byte hookmask; | 116 | lu_byte hookmask; |
167 | lu_byte allowhook; | 117 | lu_byte allowhook; |
168 | int basehookcount; | 118 | int basehookcount; |
169 | int hookcount; | 119 | int hookcount; |
170 | lua_Hook hook; | 120 | lua_Hook hook; |
121 | TValue l_gt; /* table of globals */ | ||
122 | TValue env; /* temporary place for environments */ | ||
171 | GCObject *openupval; /* list of open upvalues in this stack */ | 123 | GCObject *openupval; /* list of open upvalues in this stack */ |
172 | GCObject *gclist; | 124 | GCObject *gclist; |
173 | struct lua_longjmp *errorJmp; /* current error recover point */ | 125 | struct lua_longjmp *errorJmp; /* current error recover point */ |
174 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | 126 | ptrdiff_t errfunc; /* current error handling function (stack index) */ |
175 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ | ||
176 | }; | 127 | }; |
177 | 128 | ||
178 | 129 | ||
@@ -183,7 +134,7 @@ struct lua_State { | |||
183 | ** Union of all collectable objects | 134 | ** Union of all collectable objects |
184 | */ | 135 | */ |
185 | union GCObject { | 136 | union GCObject { |
186 | GCheader gch; /* common header */ | 137 | GCheader gch; |
187 | union TString ts; | 138 | union TString ts; |
188 | union Udata u; | 139 | union Udata u; |
189 | union Closure cl; | 140 | union Closure cl; |
@@ -194,35 +145,25 @@ union GCObject { | |||
194 | }; | 145 | }; |
195 | 146 | ||
196 | 147 | ||
197 | #define gch(o) (&(o)->gch) | ||
198 | |||
199 | /* macros to convert a GCObject into a specific value */ | 148 | /* macros to convert a GCObject into a specific value */ |
200 | #define rawgco2ts(o) \ | 149 | #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) |
201 | check_exp(novariant((o)->gch.tt) == LUA_TSTRING, &((o)->ts)) | ||
202 | #define gco2ts(o) (&rawgco2ts(o)->tsv) | 150 | #define gco2ts(o) (&rawgco2ts(o)->tsv) |
203 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) | 151 | #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) |
204 | #define gco2u(o) (&rawgco2u(o)->uv) | 152 | #define gco2u(o) (&rawgco2u(o)->uv) |
205 | #define gco2lcl(o) check_exp((o)->gch.tt == LUA_TLCL, &((o)->cl.l)) | 153 | #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) |
206 | #define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c)) | 154 | #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) |
207 | #define gco2cl(o) \ | ||
208 | check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl)) | ||
209 | #define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) | ||
210 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) | 155 | #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) |
211 | #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) | 156 | #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) |
157 | #define ngcotouv(o) \ | ||
158 | check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) | ||
212 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) | 159 | #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) |
213 | 160 | ||
214 | /* macro to convert any Lua object into a GCObject */ | 161 | /* macro to convert any Lua object into a GCObject */ |
215 | #define obj2gco(v) (cast(GCObject *, (v))) | 162 | #define obj2gco(v) (cast(GCObject *, (v))) |
216 | 163 | ||
217 | 164 | ||
218 | /* actual number of total bytes allocated */ | 165 | LUAI_FUNC lua_State *luaE_newthread (lua_State *L); |
219 | #define gettotalbytes(g) ((g)->totalbytes + (g)->GCdebt) | ||
220 | |||
221 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); | ||
222 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); | 166 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); |
223 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); | ||
224 | LUAI_FUNC void luaE_freeCI (lua_State *L); | ||
225 | |||
226 | 167 | ||
227 | #endif | 168 | #endif |
228 | 169 | ||