diff options
-rw-r--r-- | lapi.c | 50 | ||||
-rw-r--r-- | lcode.c | 16 | ||||
-rw-r--r-- | ldebug.c | 37 | ||||
-rw-r--r-- | ldo.c | 16 | ||||
-rw-r--r-- | lfunc.c | 10 | ||||
-rw-r--r-- | lgc.c | 85 | ||||
-rw-r--r-- | llex.c | 18 | ||||
-rw-r--r-- | lmem.c | 8 | ||||
-rw-r--r-- | lobject.c | 12 | ||||
-rw-r--r-- | lobject.h | 30 | ||||
-rw-r--r-- | lparser.c | 15 | ||||
-rw-r--r-- | lstate.c | 77 | ||||
-rw-r--r-- | lstate.h | 35 | ||||
-rw-r--r-- | lstring.c | 29 | ||||
-rw-r--r-- | ltable.c | 10 | ||||
-rw-r--r-- | ltests.c | 5 | ||||
-rw-r--r-- | ltm.c | 34 | ||||
-rw-r--r-- | ltm.h | 8 | ||||
-rw-r--r-- | lvm.c | 30 |
19 files changed, 268 insertions, 257 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.116 2001/01/10 18:56:11 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.117 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -230,7 +230,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
230 | 230 | ||
231 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | 231 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { |
232 | /* ORDER LUA_T */ | 232 | /* ORDER LUA_T */ |
233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(tag))) | 233 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) |
234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | 234 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); |
235 | setuvalue(L->top, luaS_createudata(L, u, tag)); | 235 | setuvalue(L->top, luaS_createudata(L, u, tag)); |
236 | api_incr_top(L); | 236 | api_incr_top(L); |
@@ -261,14 +261,14 @@ LUA_API void lua_gettable (lua_State *L, int index) { | |||
261 | 261 | ||
262 | LUA_API void lua_rawget (lua_State *L, int index) { | 262 | LUA_API void lua_rawget (lua_State *L, int index) { |
263 | StkId t = Index(L, index); | 263 | StkId t = Index(L, index); |
264 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 264 | lua_assert(ttype(t) == LUA_TTABLE); |
265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); | 265 | setobj(L->top - 1, luaH_get(hvalue(t), L->top - 1)); |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | 269 | LUA_API void lua_rawgeti (lua_State *L, int index, int n) { |
270 | StkId o = Index(L, index); | 270 | StkId o = Index(L, index); |
271 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 271 | lua_assert(ttype(o) == LUA_TTABLE); |
272 | setobj(L->top, luaH_getnum(hvalue(o), n)); | 272 | setobj(L->top, luaH_getnum(hvalue(o), n)); |
273 | api_incr_top(L); | 273 | api_incr_top(L); |
274 | } | 274 | } |
@@ -284,9 +284,9 @@ LUA_API int lua_getref (lua_State *L, int ref) { | |||
284 | if (ref == LUA_REFNIL) { | 284 | if (ref == LUA_REFNIL) { |
285 | setnilvalue(L->top); | 285 | setnilvalue(L->top); |
286 | } | 286 | } |
287 | else if (0 <= ref && ref < L->nref && | 287 | else if (0 <= ref && ref < G(L)->nref && |
288 | (L->refArray[ref].st == LOCK || L->refArray[ref].st == HOLD)) { | 288 | (G(L)->refArray[ref].st == LOCK || G(L)->refArray[ref].st == HOLD)) { |
289 | setobj(L->top, &L->refArray[ref].o); | 289 | setobj(L->top, &G(L)->refArray[ref].o); |
290 | } | 290 | } |
291 | else | 291 | else |
292 | return 0; | 292 | return 0; |
@@ -324,7 +324,7 @@ LUA_API void lua_settable (lua_State *L, int index) { | |||
324 | 324 | ||
325 | LUA_API void lua_rawset (lua_State *L, int index) { | 325 | LUA_API void lua_rawset (lua_State *L, int index) { |
326 | StkId t = Index(L, index); | 326 | StkId t = Index(L, index); |
327 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 327 | lua_assert(ttype(t) == LUA_TTABLE); |
328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); | 328 | setobj(luaH_set(L, hvalue(t), L->top-2), (L->top-1)); |
329 | L->top -= 2; | 329 | L->top -= 2; |
330 | } | 330 | } |
@@ -332,7 +332,7 @@ LUA_API void lua_rawset (lua_State *L, int index) { | |||
332 | 332 | ||
333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { | 333 | LUA_API void lua_rawseti (lua_State *L, int index, int n) { |
334 | StkId o = Index(L, index); | 334 | StkId o = Index(L, index); |
335 | LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); | 335 | lua_assert(ttype(o) == LUA_TTABLE); |
336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); | 336 | setobj(luaH_setnum(L, hvalue(o), n), (L->top-1)); |
337 | L->top--; | 337 | L->top--; |
338 | } | 338 | } |
@@ -340,7 +340,7 @@ LUA_API void lua_rawseti (lua_State *L, int index, int n) { | |||
340 | 340 | ||
341 | LUA_API void lua_setglobals (lua_State *L) { | 341 | LUA_API void lua_setglobals (lua_State *L) { |
342 | StkId newtable = --L->top; | 342 | StkId newtable = --L->top; |
343 | LUA_ASSERT(ttype(newtable) == LUA_TTABLE, "table expected"); | 343 | lua_assert(ttype(newtable) == LUA_TTABLE); |
344 | L->gt = hvalue(newtable); | 344 | L->gt = hvalue(newtable); |
345 | } | 345 | } |
346 | 346 | ||
@@ -350,17 +350,17 @@ LUA_API int lua_ref (lua_State *L, int lock) { | |||
350 | if (ttype(L->top-1) == LUA_TNIL) | 350 | if (ttype(L->top-1) == LUA_TNIL) |
351 | ref = LUA_REFNIL; | 351 | ref = LUA_REFNIL; |
352 | else { | 352 | else { |
353 | if (L->refFree != NONEXT) { /* is there a free place? */ | 353 | if (G(L)->refFree != NONEXT) { /* is there a free place? */ |
354 | ref = L->refFree; | 354 | ref = G(L)->refFree; |
355 | L->refFree = L->refArray[ref].st; | 355 | G(L)->refFree = G(L)->refArray[ref].st; |
356 | } | 356 | } |
357 | else { /* no more free places */ | 357 | else { /* no more free places */ |
358 | luaM_growvector(L, L->refArray, L->nref, L->sizeref, struct Ref, | 358 | luaM_growvector(L, G(L)->refArray, G(L)->nref, G(L)->sizeref, struct Ref, |
359 | MAX_INT, "reference table overflow"); | 359 | MAX_INT, "reference table overflow"); |
360 | ref = L->nref++; | 360 | ref = G(L)->nref++; |
361 | } | 361 | } |
362 | setobj(&L->refArray[ref].o, L->top-1); | 362 | setobj(&G(L)->refArray[ref].o, L->top-1); |
363 | L->refArray[ref].st = lock ? LOCK : HOLD; | 363 | G(L)->refArray[ref].st = lock ? LOCK : HOLD; |
364 | } | 364 | } |
365 | L->top--; | 365 | L->top--; |
366 | return ref; | 366 | return ref; |
@@ -386,18 +386,18 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
386 | #define GCunscale(x) ((mem_int)(x)<<10) | 386 | #define GCunscale(x) ((mem_int)(x)<<10) |
387 | 387 | ||
388 | LUA_API int lua_getgcthreshold (lua_State *L) { | 388 | LUA_API int lua_getgcthreshold (lua_State *L) { |
389 | return GCscale(L->GCthreshold); | 389 | return GCscale(G(L)->GCthreshold); |
390 | } | 390 | } |
391 | 391 | ||
392 | LUA_API int lua_getgccount (lua_State *L) { | 392 | LUA_API int lua_getgccount (lua_State *L) { |
393 | return GCscale(L->nblocks); | 393 | return GCscale(G(L)->nblocks); |
394 | } | 394 | } |
395 | 395 | ||
396 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | 396 | LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { |
397 | if (newthreshold > GCscale(ULONG_MAX)) | 397 | if (newthreshold > GCscale(ULONG_MAX)) |
398 | L->GCthreshold = ULONG_MAX; | 398 | G(L)->GCthreshold = ULONG_MAX; |
399 | else | 399 | else |
400 | L->GCthreshold = GCunscale(newthreshold); | 400 | G(L)->GCthreshold = GCunscale(newthreshold); |
401 | luaC_checkGC(L); | 401 | luaC_checkGC(L); |
402 | } | 402 | } |
403 | 403 | ||
@@ -424,9 +424,9 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
424 | 424 | ||
425 | LUA_API void lua_unref (lua_State *L, int ref) { | 425 | LUA_API void lua_unref (lua_State *L, int ref) { |
426 | if (ref >= 0) { | 426 | if (ref >= 0) { |
427 | LUA_ASSERT(ref < L->nref && L->refArray[ref].st < 0, "invalid ref"); | 427 | lua_assert(ref < G(L)->nref && G(L)->refArray[ref].st < 0); |
428 | L->refArray[ref].st = L->refFree; | 428 | G(L)->refArray[ref].st = G(L)->refFree; |
429 | L->refFree = ref; | 429 | G(L)->refFree = ref; |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
@@ -434,7 +434,7 @@ LUA_API void lua_unref (lua_State *L, int ref) { | |||
434 | LUA_API int lua_next (lua_State *L, int index) { | 434 | LUA_API int lua_next (lua_State *L, int index) { |
435 | StkId t = luaA_index(L, index); | 435 | StkId t = luaA_index(L, index); |
436 | Node *n; | 436 | Node *n; |
437 | LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); | 437 | lua_assert(ttype(t) == LUA_TTABLE); |
438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); | 438 | n = luaH_next(L, hvalue(t), luaA_index(L, -1)); |
439 | if (n) { | 439 | if (n) { |
440 | setobj(L->top-1, key(n)); | 440 | setobj(L->top-1, key(n)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 1.55 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.56 2001/01/15 16:13:24 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -189,7 +189,7 @@ void luaK_storevar (LexState *ls, const expdesc *var) { | |||
189 | luaK_code2(fs, OP_SETTABLE, 3, 3); | 189 | luaK_code2(fs, OP_SETTABLE, 3, 3); |
190 | break; | 190 | break; |
191 | default: | 191 | default: |
192 | LUA_INTERNALERROR("invalid var kind to store"); | 192 | lua_assert(0); /* invalid var kind to store */ |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
@@ -205,7 +205,7 @@ static OpCode invertjump (OpCode op) { | |||
205 | case OP_JMPT: case OP_JMPONT: return OP_JMPF; | 205 | case OP_JMPT: case OP_JMPONT: return OP_JMPF; |
206 | case OP_JMPF: case OP_JMPONF: return OP_JMPT; | 206 | case OP_JMPF: case OP_JMPONF: return OP_JMPT; |
207 | default: | 207 | default: |
208 | LUA_INTERNALERROR("invalid jump instruction"); | 208 | lua_assert(0); /* invalid jump instruction */ |
209 | return OP_JMP; /* to avoid warnings */ | 209 | return OP_JMP; /* to avoid warnings */ |
210 | } | 210 | } |
211 | } | 211 | } |
@@ -280,7 +280,7 @@ static void luaK_testgo (FuncState *fs, expdesc *v, int invert, OpCode jump) { | |||
280 | discharge1(fs, v); | 280 | discharge1(fs, v); |
281 | prevpos = fs->pc-1; | 281 | prevpos = fs->pc-1; |
282 | previous = &fs->f->code[prevpos]; | 282 | previous = &fs->f->code[prevpos]; |
283 | LUA_ASSERT(*previous==previous_instruction(fs), "no jump allowed here"); | 283 | lua_assert(*previous==previous_instruction(fs)); /* no jump allowed here */ |
284 | if (!ISJUMP(GET_OPCODE(*previous))) | 284 | if (!ISJUMP(GET_OPCODE(*previous))) |
285 | prevpos = luaK_code1(fs, jump, NO_JUMP); | 285 | prevpos = luaK_code1(fs, jump, NO_JUMP); |
286 | else { /* last instruction is already a jump */ | 286 | else { /* last instruction is already a jump */ |
@@ -398,14 +398,14 @@ void luaK_posfix (LexState *ls, BinOpr op, expdesc *v1, expdesc *v2) { | |||
398 | FuncState *fs = ls->fs; | 398 | FuncState *fs = ls->fs; |
399 | switch (op) { | 399 | switch (op) { |
400 | case OPR_AND: { | 400 | case OPR_AND: { |
401 | LUA_ASSERT(v1->u.l.t == NO_JUMP, "list must be closed"); | 401 | lua_assert(v1->u.l.t == NO_JUMP); /* list must be closed */ |
402 | discharge1(fs, v2); | 402 | discharge1(fs, v2); |
403 | v1->u.l.t = v2->u.l.t; | 403 | v1->u.l.t = v2->u.l.t; |
404 | luaK_concat(fs, &v1->u.l.f, v2->u.l.f); | 404 | luaK_concat(fs, &v1->u.l.f, v2->u.l.f); |
405 | break; | 405 | break; |
406 | } | 406 | } |
407 | case OPR_OR: { | 407 | case OPR_OR: { |
408 | LUA_ASSERT(v1->u.l.f == NO_JUMP, "list must be closed"); | 408 | lua_assert(v1->u.l.f == NO_JUMP); /* list must be closed */ |
409 | discharge1(fs, v2); | 409 | discharge1(fs, v2); |
410 | v1->u.l.f = v2->u.l.f; | 410 | v1->u.l.f = v2->u.l.f; |
411 | luaK_concat(fs, &v1->u.l.t, v2->u.l.t); | 411 | luaK_concat(fs, &v1->u.l.t, v2->u.l.t); |
@@ -622,11 +622,11 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) { | |||
622 | case OP_GETINDEXED: | 622 | case OP_GETINDEXED: |
623 | case OP_TAILCALL: | 623 | case OP_TAILCALL: |
624 | case OP_ADDI: { | 624 | case OP_ADDI: { |
625 | LUA_INTERNALERROR("instruction used only for optimizations"); | 625 | lua_assert(0); /* instruction used only for optimizations */ |
626 | break; | 626 | break; |
627 | } | 627 | } |
628 | default: { | 628 | default: { |
629 | LUA_ASSERT(delta != VD, "invalid delta"); | 629 | lua_assert(delta != VD); |
630 | break; | 630 | break; |
631 | } | 631 | } |
632 | } | 632 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.52 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.53 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -96,20 +96,20 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
96 | refi = prefi ? *prefi : 0; | 96 | refi = prefi ? *prefi : 0; |
97 | if (lineinfo[refi] < 0) | 97 | if (lineinfo[refi] < 0) |
98 | refline += -lineinfo[refi++]; | 98 | refline += -lineinfo[refi++]; |
99 | LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info"); | 99 | lua_assert(lineinfo[refi] >= 0); |
100 | while (lineinfo[refi] > pc) { | 100 | while (lineinfo[refi] > pc) { |
101 | refline--; | 101 | refline--; |
102 | refi--; | 102 | refi--; |
103 | if (lineinfo[refi] < 0) | 103 | if (lineinfo[refi] < 0) |
104 | refline -= -lineinfo[refi--]; | 104 | refline -= -lineinfo[refi--]; |
105 | LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info"); | 105 | lua_assert(lineinfo[refi] >= 0); |
106 | } | 106 | } |
107 | for (;;) { | 107 | for (;;) { |
108 | int nextline = refline + 1; | 108 | int nextline = refline + 1; |
109 | int nextref = refi + 1; | 109 | int nextref = refi + 1; |
110 | if (lineinfo[nextref] < 0) | 110 | if (lineinfo[nextref] < 0) |
111 | nextline += -lineinfo[nextref++]; | 111 | nextline += -lineinfo[nextref++]; |
112 | LUA_ASSERT(lineinfo[nextref] >= 0, "invalid line info"); | 112 | lua_assert(lineinfo[nextref] >= 0); |
113 | if (lineinfo[nextref] > pc) | 113 | if (lineinfo[nextref] > pc) |
114 | break; | 114 | break; |
115 | refline = nextline; | 115 | refline = nextline; |
@@ -122,7 +122,7 @@ int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) { | |||
122 | 122 | ||
123 | static int currentpc (StkId f) { | 123 | static int currentpc (StkId f) { |
124 | CallInfo *ci = infovalue(f); | 124 | CallInfo *ci = infovalue(f); |
125 | LUA_ASSERT(isLmark(f), "function has no pc"); | 125 | lua_assert(isLmark(f)); |
126 | if (ci->pc) | 126 | if (ci->pc) |
127 | return (*ci->pc - ci->func->f.l->code) - 1; | 127 | return (*ci->pc - ci->func->f.l->code) - 1; |
128 | else | 128 | else |
@@ -204,13 +204,13 @@ static void funcinfo (lua_State *L, lua_Debug *ar, StkId func) { | |||
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | static const char *travtagmethods (lua_State *L, const TObject *o) { | 207 | static const char *travtagmethods (global_State *G, const TObject *o) { |
208 | if (ttype(o) == LUA_TFUNCTION) { | 208 | if (ttype(o) == LUA_TFUNCTION) { |
209 | int e; | 209 | int e; |
210 | for (e=0; e<TM_N; e++) { | 210 | for (e=0; e<TM_N; e++) { |
211 | int t; | 211 | int t; |
212 | for (t=0; t<L->ntag; t++) | 212 | for (t=0; t<G->ntag; t++) |
213 | if (clvalue(o) == luaT_gettm(L, t, e)) | 213 | if (clvalue(o) == luaT_gettm(G, t, e)) |
214 | return luaT_eventname[e]; | 214 | return luaT_eventname[e]; |
215 | } | 215 | } |
216 | } | 216 | } |
@@ -237,7 +237,7 @@ static void getname (lua_State *L, StkId f, lua_Debug *ar) { | |||
237 | if ((ar->name = travglobals(L, &o)) != NULL) | 237 | if ((ar->name = travglobals(L, &o)) != NULL) |
238 | ar->namewhat = "global"; | 238 | ar->namewhat = "global"; |
239 | /* not found: try tag methods */ | 239 | /* not found: try tag methods */ |
240 | else if ((ar->name = travtagmethods(L, &o)) != NULL) | 240 | else if ((ar->name = travtagmethods(G(L), &o)) != NULL) |
241 | ar->namewhat = "tag-method"; | 241 | ar->namewhat = "tag-method"; |
242 | else ar->namewhat = ""; /* not found at all */ | 242 | else ar->namewhat = ""; /* not found at all */ |
243 | } | 243 | } |
@@ -308,22 +308,22 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { | |||
308 | top++; /* `arg' */ | 308 | top++; /* `arg' */ |
309 | while (pc < lastpc) { | 309 | while (pc < lastpc) { |
310 | const Instruction i = code[pc++]; | 310 | const Instruction i = code[pc++]; |
311 | LUA_ASSERT(0 <= top && top <= pt->maxstacksize, "wrong stack"); | 311 | lua_assert(0 <= top && top <= pt->maxstacksize); |
312 | switch (GET_OPCODE(i)) { | 312 | switch (GET_OPCODE(i)) { |
313 | case OP_RETURN: { | 313 | case OP_RETURN: { |
314 | LUA_ASSERT(top >= GETARG_U(i), "wrong stack"); | 314 | lua_assert(top >= GETARG_U(i)); |
315 | top = GETARG_U(i); | 315 | top = GETARG_U(i); |
316 | break; | 316 | break; |
317 | } | 317 | } |
318 | case OP_TAILCALL: { | 318 | case OP_TAILCALL: { |
319 | LUA_ASSERT(top >= GETARG_A(i), "wrong stack"); | 319 | lua_assert(top >= GETARG_A(i)); |
320 | top = GETARG_B(i); | 320 | top = GETARG_B(i); |
321 | break; | 321 | break; |
322 | } | 322 | } |
323 | case OP_CALL: { | 323 | case OP_CALL: { |
324 | int nresults = GETARG_B(i); | 324 | int nresults = GETARG_B(i); |
325 | if (nresults == MULT_RET) nresults = 1; | 325 | if (nresults == MULT_RET) nresults = 1; |
326 | LUA_ASSERT(top >= GETARG_A(i), "wrong stack"); | 326 | lua_assert(top >= GETARG_A(i)); |
327 | top = pushpc(stack, pc, GETARG_A(i), nresults); | 327 | top = pushpc(stack, pc, GETARG_A(i), nresults); |
328 | break; | 328 | break; |
329 | } | 329 | } |
@@ -368,10 +368,9 @@ static Instruction luaG_symbexec (const Proto *pt, int lastpc, int stackpos) { | |||
368 | } | 368 | } |
369 | default: { | 369 | default: { |
370 | OpCode op = GET_OPCODE(i); | 370 | OpCode op = GET_OPCODE(i); |
371 | LUA_ASSERT(luaK_opproperties[op].push != VD, | 371 | lua_assert(luaK_opproperties[op].push != VD); |
372 | "invalid opcode for default"); | ||
373 | top -= (int)luaK_opproperties[op].pop; | 372 | top -= (int)luaK_opproperties[op].pop; |
374 | LUA_ASSERT(top >= 0, "wrong stack"); | 373 | lua_assert(top >= 0); |
375 | top = pushpc(stack, pc, top, luaK_opproperties[op].push); | 374 | top = pushpc(stack, pc, top, luaK_opproperties[op].push); |
376 | } | 375 | } |
377 | } | 376 | } |
@@ -389,7 +388,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
389 | int pc = currentpc(func); | 388 | int pc = currentpc(func); |
390 | int stackpos = obj - (func+1); /* func+1 == function base */ | 389 | int stackpos = obj - (func+1); /* func+1 == function base */ |
391 | Instruction i = luaG_symbexec(p, pc, stackpos); | 390 | Instruction i = luaG_symbexec(p, pc, stackpos); |
392 | LUA_ASSERT(pc != -1, "function must be active"); | 391 | lua_assert(pc != -1); |
393 | switch (GET_OPCODE(i)) { | 392 | switch (GET_OPCODE(i)) { |
394 | case OP_GETGLOBAL: { | 393 | case OP_GETGLOBAL: { |
395 | *name = p->kstr[GETARG_U(i)]->str; | 394 | *name = p->kstr[GETARG_U(i)]->str; |
@@ -397,7 +396,7 @@ static const char *getobjname (lua_State *L, StkId obj, const char **name) { | |||
397 | } | 396 | } |
398 | case OP_GETLOCAL: { | 397 | case OP_GETLOCAL: { |
399 | *name = luaF_getlocalname(p, GETARG_U(i)+1, pc); | 398 | *name = luaF_getlocalname(p, GETARG_U(i)+1, pc); |
400 | LUA_ASSERT(*name, "local must exist"); | 399 | lua_assert(*name); |
401 | return "local"; | 400 | return "local"; |
402 | } | 401 | } |
403 | case OP_PUSHSELF: | 402 | case OP_PUSHSELF: |
@@ -449,7 +448,7 @@ void luaG_typeerror (lua_State *L, StkId o, const char *op) { | |||
449 | 448 | ||
450 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { | 449 | void luaG_binerror (lua_State *L, StkId p1, int t, const char *op) { |
451 | if (ttype(p1) == t) p1++; | 450 | if (ttype(p1) == t) p1++; |
452 | LUA_ASSERT(ttype(p1) != t, "must be an error"); | 451 | lua_assert(ttype(p1) != t); |
453 | luaG_typeerror(L, p1, op); | 452 | luaG_typeerror(L, p1, op); |
454 | } | 453 | } |
455 | 454 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.113 2001/01/10 18:56:11 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.114 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -55,7 +55,7 @@ void luaD_checkstack (lua_State *L, int n) { | |||
55 | } | 55 | } |
56 | else { | 56 | else { |
57 | L->stack_last += EXTRA_STACK; /* to be used by error message */ | 57 | L->stack_last += EXTRA_STACK; /* to be used by error message */ |
58 | LUA_ASSERT(L->stack_last == L->stack+L->stacksize-1, "wrong stack limit"); | 58 | lua_assert(L->stack_last == L->stack+L->stacksize-1); |
59 | lua_error(L, "stack overflow"); | 59 | lua_error(L, "stack overflow"); |
60 | } | 60 | } |
61 | } | 61 | } |
@@ -95,7 +95,7 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | |||
95 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ | 95 | luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ |
96 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 96 | L->allowhooks = 0; /* cannot call hooks inside a hook */ |
97 | (*hook)(L, ar); | 97 | (*hook)(L, ar); |
98 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); | 98 | lua_assert(L->allowhooks == 0); |
99 | L->allowhooks = 1; | 99 | L->allowhooks = 1; |
100 | L->top = old_top; | 100 | L->top = old_top; |
101 | L->Cbase = old_Cbase; | 101 | L->Cbase = old_Cbase; |
@@ -161,7 +161,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
161 | Closure *cl; | 161 | Closure *cl; |
162 | if (ttype(func) != LUA_TFUNCTION) { | 162 | if (ttype(func) != LUA_TFUNCTION) { |
163 | /* `func' is not a function; check the `function' tag method */ | 163 | /* `func' is not a function; check the `function' tag method */ |
164 | Closure *tm = luaT_gettmbyObj(L, func, TM_FUNCTION); | 164 | Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); |
165 | if (tm == NULL) | 165 | if (tm == NULL) |
166 | luaG_typeerror(L, func, "call"); | 166 | luaG_typeerror(L, func, "call"); |
167 | luaD_openstack(L, func); | 167 | luaD_openstack(L, func); |
@@ -177,7 +177,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
177 | luaV_execute(L, cl, func+1)); | 177 | luaV_execute(L, cl, func+1)); |
178 | if (callhook) /* same hook that was active at entry */ | 178 | if (callhook) /* same hook that was active at entry */ |
179 | luaD_callHook(L, func, callhook, "return"); | 179 | luaD_callHook(L, func, callhook, "return"); |
180 | LUA_ASSERT(ttype(func) == LUA_TMARK, "invalid tag"); | 180 | lua_assert(ttype(func) == LUA_TMARK); |
181 | /* move results to `func' (to erase parameters and function) */ | 181 | /* move results to `func' (to erase parameters and function) */ |
182 | if (nResults == LUA_MULTRET) { | 182 | if (nResults == LUA_MULTRET) { |
183 | while (firstResult < L->top) /* copy all results */ | 183 | while (firstResult < L->top) /* copy all results */ |
@@ -244,12 +244,12 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
244 | int status; | 244 | int status; |
245 | p.z = z; p.bin = bin; | 245 | p.z = z; p.bin = bin; |
246 | luaC_checkGC(L); | 246 | luaC_checkGC(L); |
247 | old_blocks = L->nblocks; | 247 | old_blocks = G(L)->nblocks; |
248 | status = luaD_runprotected(L, f_parser, &p); | 248 | status = luaD_runprotected(L, f_parser, &p); |
249 | if (status == 0) { | 249 | if (status == 0) { |
250 | /* add new memory to threshold (as it probably will stay) */ | 250 | /* add new memory to threshold (as it probably will stay) */ |
251 | LUA_ASSERT(L->nblocks >= old_blocks, "cannot reduce memory usage here"); | 251 | lua_assert(G(L)->nblocks >= old_blocks); |
252 | L->GCthreshold += (L->nblocks - old_blocks); | 252 | G(L)->GCthreshold += (G(L)->nblocks - old_blocks); |
253 | } | 253 | } |
254 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | 254 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ |
255 | status = LUA_ERRSYNTAX; | 255 | status = LUA_ERRSYNTAX; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 1.35 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.36 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Auxiliary functions to manipulate prototypes and closures | 3 | ** Auxiliary functions to manipulate prototypes and closures |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,8 +19,8 @@ | |||
19 | 19 | ||
20 | Closure *luaF_newclosure (lua_State *L, int nelems) { | 20 | Closure *luaF_newclosure (lua_State *L, int nelems) { |
21 | Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); | 21 | Closure *c = (Closure *)luaM_malloc(L, sizeclosure(nelems)); |
22 | c->next = L->rootcl; | 22 | c->next = G(L)->rootcl; |
23 | L->rootcl = c; | 23 | G(L)->rootcl = c; |
24 | c->mark = c; | 24 | c->mark = c; |
25 | c->nupvalues = nelems; | 25 | c->nupvalues = nelems; |
26 | return c; | 26 | return c; |
@@ -47,8 +47,8 @@ Proto *luaF_newproto (lua_State *L) { | |||
47 | f->locvars = NULL; | 47 | f->locvars = NULL; |
48 | f->lineDefined = 0; | 48 | f->lineDefined = 0; |
49 | f->source = NULL; | 49 | f->source = NULL; |
50 | f->next = L->rootproto; /* chain in list of protos */ | 50 | f->next = G(L)->rootproto; /* chain in list of protos */ |
51 | L->rootproto = f; | 51 | G(L)->rootproto = f; |
52 | return f; | 52 | return f; |
53 | } | 53 | } |
54 | 54 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.75 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.76 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -54,11 +54,11 @@ static void markstack (lua_State *L, GCState *st) { | |||
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | static void marklock (lua_State *L, GCState *st) { | 57 | static void marklock (global_State *G, GCState *st) { |
58 | int i; | 58 | int i; |
59 | for (i=0; i<L->nref; i++) { | 59 | for (i=0; i<G->nref; i++) { |
60 | if (L->refArray[i].st == LOCK) | 60 | if (G->refArray[i].st == LOCK) |
61 | markobject(st, &L->refArray[i].o); | 61 | markobject(st, &G->refArray[i].o); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
@@ -73,12 +73,12 @@ static void markclosure (GCState *st, Closure *cl) { | |||
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | static void marktagmethods (lua_State *L, GCState *st) { | 76 | static void marktagmethods (global_State *G, GCState *st) { |
77 | int e; | 77 | int e; |
78 | for (e=0; e<TM_N; e++) { | 78 | for (e=0; e<TM_N; e++) { |
79 | int t; | 79 | int t; |
80 | for (t=0; t<L->ntag; t++) { | 80 | for (t=0; t<G->ntag; t++) { |
81 | Closure *cl = luaT_gettm(L, t, e); | 81 | Closure *cl = luaT_gettm(G, t, e); |
82 | if (cl) markclosure(st, cl); | 82 | if (cl) markclosure(st, cl); |
83 | } | 83 | } |
84 | } | 84 | } |
@@ -113,9 +113,9 @@ static void markall (lua_State *L) { | |||
113 | st.cmark = NULL; | 113 | st.cmark = NULL; |
114 | st.tmark = L->gt; /* put table of globals in mark list */ | 114 | st.tmark = L->gt; /* put table of globals in mark list */ |
115 | L->gt->mark = NULL; | 115 | L->gt->mark = NULL; |
116 | marktagmethods(L, &st); /* mark tag methods */ | 116 | marktagmethods(G(L), &st); /* mark tag methods */ |
117 | markstack(L, &st); /* mark stack objects */ | 117 | markstack(L, &st); /* mark stack objects */ |
118 | marklock(L, &st); /* mark locked objects */ | 118 | marklock(G(L), &st); /* mark locked objects */ |
119 | for (;;) { /* mark tables and closures */ | 119 | for (;;) { /* mark tables and closures */ |
120 | if (st.cmark) { | 120 | if (st.cmark) { |
121 | int i; | 121 | int i; |
@@ -161,27 +161,26 @@ static int hasmark (const TObject *o) { | |||
161 | /* macro for internal debugging; check if a link of free refs is valid */ | 161 | /* macro for internal debugging; check if a link of free refs is valid */ |
162 | #define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) | 162 | #define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) |
163 | 163 | ||
164 | static void invalidaterefs (lua_State *L) { | 164 | static void invalidaterefs (global_State *G) { |
165 | int n = L->nref; | 165 | int n = G->nref; |
166 | int i; | 166 | int i; |
167 | for (i=0; i<n; i++) { | 167 | for (i=0; i<n; i++) { |
168 | struct Ref *r = &L->refArray[i]; | 168 | struct Ref *r = &G->refArray[i]; |
169 | if (r->st == HOLD && !hasmark(&r->o)) | 169 | if (r->st == HOLD && !hasmark(&r->o)) |
170 | r->st = COLLECTED; | 170 | r->st = COLLECTED; |
171 | LUA_ASSERT((r->st == LOCK && hasmark(&r->o)) || | 171 | lua_assert((r->st == LOCK && hasmark(&r->o)) || |
172 | (r->st == HOLD && hasmark(&r->o)) || | 172 | (r->st == HOLD && hasmark(&r->o)) || |
173 | r->st == COLLECTED || | 173 | r->st == COLLECTED || |
174 | r->st == NONEXT || | 174 | r->st == NONEXT || |
175 | (r->st < n && VALIDLINK(L, L->refArray[r->st].st, n)), | 175 | (r->st < n && VALIDLINK(L, G->refArray[r->st].st, n))); |
176 | "inconsistent ref table"); | ||
177 | } | 176 | } |
178 | LUA_ASSERT(VALIDLINK(L, L->refFree, n), "inconsistent ref table"); | 177 | lua_assert(VALIDLINK(L, G->refFree, n)); |
179 | } | 178 | } |
180 | 179 | ||
181 | 180 | ||
182 | 181 | ||
183 | static void collectproto (lua_State *L) { | 182 | static void collectproto (lua_State *L) { |
184 | Proto **p = &L->rootproto; | 183 | Proto **p = &G(L)->rootproto; |
185 | Proto *next; | 184 | Proto *next; |
186 | while ((next = *p) != NULL) { | 185 | while ((next = *p) != NULL) { |
187 | if (next->marked) { | 186 | if (next->marked) { |
@@ -197,7 +196,7 @@ static void collectproto (lua_State *L) { | |||
197 | 196 | ||
198 | 197 | ||
199 | static void collectclosure (lua_State *L) { | 198 | static void collectclosure (lua_State *L) { |
200 | Closure **p = &L->rootcl; | 199 | Closure **p = &G(L)->rootcl; |
201 | Closure *next; | 200 | Closure *next; |
202 | while ((next = *p) != NULL) { | 201 | while ((next = *p) != NULL) { |
203 | if (ismarked(next)) { | 202 | if (ismarked(next)) { |
@@ -213,7 +212,7 @@ static void collectclosure (lua_State *L) { | |||
213 | 212 | ||
214 | 213 | ||
215 | static void collecttable (lua_State *L) { | 214 | static void collecttable (lua_State *L) { |
216 | Hash **p = &L->roottable; | 215 | Hash **p = &G(L)->roottable; |
217 | Hash *next; | 216 | Hash *next; |
218 | while ((next = *p) != NULL) { | 217 | while ((next = *p) != NULL) { |
219 | if (ismarked(next)) { | 218 | if (ismarked(next)) { |
@@ -236,8 +235,8 @@ static void checktab (lua_State *L, stringtable *tb) { | |||
236 | 235 | ||
237 | static void collectstrings (lua_State *L, int all) { | 236 | static void collectstrings (lua_State *L, int all) { |
238 | int i; | 237 | int i; |
239 | for (i=0; i<L->strt.size; i++) { /* for each list */ | 238 | for (i=0; i<G(L)->strt.size; i++) { /* for each list */ |
240 | TString **p = &L->strt.hash[i]; | 239 | TString **p = &G(L)->strt.hash[i]; |
241 | TString *next; | 240 | TString *next; |
242 | while ((next = *p) != NULL) { | 241 | while ((next = *p) != NULL) { |
243 | if (next->marked && !all) { /* preserve? */ | 242 | if (next->marked && !all) { /* preserve? */ |
@@ -247,22 +246,22 @@ static void collectstrings (lua_State *L, int all) { | |||
247 | } | 246 | } |
248 | else { /* collect */ | 247 | else { /* collect */ |
249 | *p = next->nexthash; | 248 | *p = next->nexthash; |
250 | L->strt.nuse--; | 249 | G(L)->strt.nuse--; |
251 | luaM_free(L, next, sizestring(next->len)); | 250 | luaM_free(L, next, sizestring(next->len)); |
252 | } | 251 | } |
253 | } | 252 | } |
254 | } | 253 | } |
255 | checktab(L, &L->strt); | 254 | checktab(L, &G(L)->strt); |
256 | } | 255 | } |
257 | 256 | ||
258 | 257 | ||
259 | static void collectudata (lua_State *L, int all) { | 258 | static void collectudata (lua_State *L, int all) { |
260 | int i; | 259 | int i; |
261 | for (i=0; i<L->udt.size; i++) { /* for each list */ | 260 | for (i=0; i<G(L)->udt.size; i++) { /* for each list */ |
262 | TString **p = &L->udt.hash[i]; | 261 | TString **p = &G(L)->udt.hash[i]; |
263 | TString *next; | 262 | TString *next; |
264 | while ((next = *p) != NULL) { | 263 | while ((next = *p) != NULL) { |
265 | LUA_ASSERT(next->marked <= 1, "udata cannot be fixed"); | 264 | lua_assert(next->marked <= 1); |
266 | if (next->marked && !all) { /* preserve? */ | 265 | if (next->marked && !all) { /* preserve? */ |
267 | next->marked = 0; | 266 | next->marked = 0; |
268 | p = &next->nexthash; | 267 | p = &next->nexthash; |
@@ -270,28 +269,28 @@ static void collectudata (lua_State *L, int all) { | |||
270 | else { /* collect */ | 269 | else { /* collect */ |
271 | int tag = next->u.d.tag; | 270 | int tag = next->u.d.tag; |
272 | *p = next->nexthash; | 271 | *p = next->nexthash; |
273 | next->nexthash = L->TMtable[tag].collected; /* chain udata */ | 272 | next->nexthash = G(L)->TMtable[tag].collected; /* chain udata */ |
274 | L->TMtable[tag].collected = next; | 273 | G(L)->TMtable[tag].collected = next; |
275 | L->udt.nuse--; | 274 | G(L)->udt.nuse--; |
276 | } | 275 | } |
277 | } | 276 | } |
278 | } | 277 | } |
279 | checktab(L, &L->udt); | 278 | checktab(L, &G(L)->udt); |
280 | } | 279 | } |
281 | 280 | ||
282 | 281 | ||
283 | #define MINBUFFER 256 | 282 | #define MINBUFFER 256 |
284 | static void checkMbuffer (lua_State *L) { | 283 | static void checkMbuffer (lua_State *L) { |
285 | if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ | 284 | if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ |
286 | size_t newsize = L->Mbuffsize/2; /* still larger than MINBUFFER */ | 285 | size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ |
287 | luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, newsize, char); | 286 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, char); |
288 | L->Mbuffsize = newsize; | 287 | G(L)->Mbuffsize = newsize; |
289 | } | 288 | } |
290 | } | 289 | } |
291 | 290 | ||
292 | 291 | ||
293 | static void callgcTM (lua_State *L, const TObject *obj) { | 292 | static void callgcTM (lua_State *L, const TObject *obj) { |
294 | Closure *tm = luaT_gettmbyObj(L, obj, TM_GC); | 293 | Closure *tm = luaT_gettmbyObj(G(L), obj, TM_GC); |
295 | if (tm != NULL) { | 294 | if (tm != NULL) { |
296 | int oldah = L->allowhooks; | 295 | int oldah = L->allowhooks; |
297 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ | 296 | L->allowhooks = 0; /* stop debug hooks during GC tag methods */ |
@@ -307,12 +306,12 @@ static void callgcTM (lua_State *L, const TObject *obj) { | |||
307 | 306 | ||
308 | static void callgcTMudata (lua_State *L) { | 307 | static void callgcTMudata (lua_State *L) { |
309 | int tag; | 308 | int tag; |
310 | L->GCthreshold = 2*L->nblocks; /* avoid GC during tag methods */ | 309 | G(L)->GCthreshold = 2*G(L)->nblocks; /* avoid GC during tag methods */ |
311 | for (tag=L->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ | 310 | for (tag=G(L)->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ |
312 | TString *udata; | 311 | TString *udata; |
313 | while ((udata = L->TMtable[tag].collected) != NULL) { | 312 | while ((udata = G(L)->TMtable[tag].collected) != NULL) { |
314 | TObject obj; | 313 | TObject obj; |
315 | L->TMtable[tag].collected = udata->nexthash; /* remove it from list */ | 314 | G(L)->TMtable[tag].collected = udata->nexthash; /* remove it from list */ |
316 | setuvalue(&obj, udata); | 315 | setuvalue(&obj, udata); |
317 | callgcTM(L, &obj); | 316 | callgcTM(L, &obj); |
318 | luaM_free(L, udata, sizeudata(udata->len)); | 317 | luaM_free(L, udata, sizeudata(udata->len)); |
@@ -333,16 +332,16 @@ void luaC_collect (lua_State *L, int all) { | |||
333 | 332 | ||
334 | static void luaC_collectgarbage (lua_State *L) { | 333 | static void luaC_collectgarbage (lua_State *L) { |
335 | markall(L); | 334 | markall(L); |
336 | invalidaterefs(L); /* check unlocked references */ | 335 | invalidaterefs(G(L)); /* check unlocked references */ |
337 | luaC_collect(L, 0); | 336 | luaC_collect(L, 0); |
338 | checkMbuffer(L); | 337 | checkMbuffer(L); |
339 | L->GCthreshold = 2*L->nblocks; /* set new threshold */ | 338 | G(L)->GCthreshold = 2*G(L)->nblocks; /* set new threshold */ |
340 | callgcTM(L, &luaO_nilobject); | 339 | callgcTM(L, &luaO_nilobject); |
341 | } | 340 | } |
342 | 341 | ||
343 | 342 | ||
344 | void luaC_checkGC (lua_State *L) { | 343 | void luaC_checkGC (lua_State *L) { |
345 | if (L->nblocks >= L->GCthreshold) | 344 | if (G(L)->nblocks >= G(L)->GCthreshold) |
346 | luaC_collectgarbage(L); | 345 | luaC_collectgarbage(L); |
347 | } | 346 | } |
348 | 347 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.74 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.75 2001/01/15 18:07:56 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -35,7 +35,7 @@ void luaX_init (lua_State *L) { | |||
35 | int i; | 35 | int i; |
36 | for (i=0; i<NUM_RESERVED; i++) { | 36 | for (i=0; i<NUM_RESERVED; i++) { |
37 | TString *ts = luaS_new(L, token2string[i]); | 37 | TString *ts = luaS_new(L, token2string[i]); |
38 | LUA_ASSERT(strlen(token2string[i])+1 <= TOKEN_LEN, "incorrect token_len"); | 38 | lua_assert(strlen(token2string[i])+1 <= TOKEN_LEN); |
39 | ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ | 39 | ts->marked = (unsigned char)(RESERVEDMARK+i); /* reserved word */ |
40 | } | 40 | } |
41 | } | 41 | } |
@@ -65,7 +65,7 @@ void luaX_error (LexState *ls, const char *s, int token) { | |||
65 | char buff[TOKEN_LEN]; | 65 | char buff[TOKEN_LEN]; |
66 | luaX_token2str(token, buff); | 66 | luaX_token2str(token, buff); |
67 | if (buff[0] == '\0') | 67 | if (buff[0] == '\0') |
68 | luaX_syntaxerror(ls, s, ls->L->Mbuffer); | 68 | luaX_syntaxerror(ls, s, G(ls->L)->Mbuffer); |
69 | else | 69 | else |
70 | luaX_syntaxerror(ls, s, buff); | 70 | luaX_syntaxerror(ls, s, buff); |
71 | } | 71 | } |
@@ -123,10 +123,10 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) { | |||
123 | /* use Mbuffer to store names, literal strings and numbers */ | 123 | /* use Mbuffer to store names, literal strings and numbers */ |
124 | 124 | ||
125 | #define EXTRABUFF 128 | 125 | #define EXTRABUFF 128 |
126 | #define checkbuffer(L, n, len) if ((len)+(n) > L->Mbuffsize) \ | 126 | #define checkbuffer(L, n, len) if ((len)+(n) > G(L)->Mbuffsize) \ |
127 | luaO_openspace(L, (len)+(n)+EXTRABUFF) | 127 | luaO_openspace(L, (len)+(n)+EXTRABUFF) |
128 | 128 | ||
129 | #define save(L, c, l) (L->Mbuffer[l++] = (char)c) | 129 | #define save(L, c, l) (G(L)->Mbuffer[l++] = (char)c) |
130 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) | 130 | #define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) |
131 | 131 | ||
132 | 132 | ||
@@ -176,7 +176,7 @@ static void read_number (LexState *LS, int comma, SemInfo *seminfo) { | |||
176 | } | 176 | } |
177 | } | 177 | } |
178 | save(L, '\0', l); | 178 | save(L, '\0', l); |
179 | if (!luaO_str2d(L->Mbuffer, &seminfo->r)) | 179 | if (!luaO_str2d(G(L)->Mbuffer, &seminfo->r)) |
180 | luaX_error(LS, "malformed number", TK_NUMBER); | 180 | luaX_error(LS, "malformed number", TK_NUMBER); |
181 | } | 181 | } |
182 | 182 | ||
@@ -220,7 +220,7 @@ static void read_long_string (LexState *LS, SemInfo *seminfo) { | |||
220 | } endloop: | 220 | } endloop: |
221 | save_and_next(L, LS, l); /* skip the second ']' */ | 221 | save_and_next(L, LS, l); /* skip the second ']' */ |
222 | save(L, '\0', l); | 222 | save(L, '\0', l); |
223 | seminfo->ts = luaS_newlstr(L, L->Mbuffer+2, l-5); | 223 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+2, l-5); |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
@@ -272,7 +272,7 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) { | |||
272 | } | 272 | } |
273 | save_and_next(L, LS, l); /* skip delimiter */ | 273 | save_and_next(L, LS, l); /* skip delimiter */ |
274 | save(L, '\0', l); | 274 | save(L, '\0', l); |
275 | seminfo->ts = luaS_newlstr(L, L->Mbuffer+1, l-3); | 275 | seminfo->ts = luaS_newlstr(L, G(L)->Mbuffer+1, l-3); |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
@@ -367,7 +367,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) { | |||
367 | } | 367 | } |
368 | tname: { /* identifier or reserved word */ | 368 | tname: { /* identifier or reserved word */ |
369 | size_t l = readname(LS); | 369 | size_t l = readname(LS); |
370 | TString *ts = luaS_newlstr(LS->L, LS->L->Mbuffer, l); | 370 | TString *ts = luaS_newlstr(LS->L, G(LS->L)->Mbuffer, l); |
371 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ | 371 | if (ts->marked >= RESERVEDMARK) /* reserved word? */ |
372 | return ts->marked-RESERVEDMARK+FIRST_RESERVED; | 372 | return ts->marked-RESERVEDMARK+FIRST_RESERVED; |
373 | seminfo->ts = ts; | 373 | seminfo->ts = ts; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.41 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.42 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -161,9 +161,9 @@ void *luaM_realloc (lua_State *L, void *block, luint32 oldsize, luint32 size) { | |||
161 | else return NULL; /* error before creating state! */ | 161 | else return NULL; /* error before creating state! */ |
162 | } | 162 | } |
163 | } | 163 | } |
164 | if (L) { | 164 | if (L && G(L)) { |
165 | L->nblocks -= oldsize; | 165 | G(L)->nblocks -= oldsize; |
166 | L->nblocks += size; | 166 | G(L)->nblocks += size; |
167 | } | 167 | } |
168 | return block; | 168 | return block; |
169 | } | 169 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.57 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.58 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -49,18 +49,18 @@ int luaO_equalObj (const TObject *t1, const TObject *t2) { | |||
49 | case LUA_TFUNCTION: | 49 | case LUA_TFUNCTION: |
50 | return clvalue(t1) == clvalue(t2); | 50 | return clvalue(t1) == clvalue(t2); |
51 | default: | 51 | default: |
52 | LUA_ASSERT(ttype(t1) == LUA_TNIL, "invalid type"); | 52 | lua_assert(ttype(t1) == LUA_TNIL); |
53 | return 1; /* LUA_TNIL */ | 53 | return 1; /* LUA_TNIL */ |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | char *luaO_openspace (lua_State *L, size_t n) { | 58 | char *luaO_openspace (lua_State *L, size_t n) { |
59 | if (n > L->Mbuffsize) { | 59 | if (n > G(L)->Mbuffsize) { |
60 | luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, n, char); | 60 | luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, char); |
61 | L->Mbuffsize = n; | 61 | G(L)->Mbuffsize = n; |
62 | } | 62 | } |
63 | return L->Mbuffer; | 63 | return G(L)->Mbuffer; |
64 | } | 64 | } |
65 | 65 | ||
66 | 66 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.85 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.86 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -15,11 +15,9 @@ | |||
15 | #ifdef LUA_DEBUG | 15 | #ifdef LUA_DEBUG |
16 | #undef NDEBUG | 16 | #undef NDEBUG |
17 | #include <assert.h> | 17 | #include <assert.h> |
18 | #define LUA_INTERNALERROR(s) assert(((void)s,0)) | 18 | #define lua_assert(c) assert(c) |
19 | #define LUA_ASSERT(c,s) assert(((void)s,(c))) | ||
20 | #else | 19 | #else |
21 | #define LUA_INTERNALERROR(s) /* empty */ | 20 | #define lua_assert(c) /* empty */ |
22 | #define LUA_ASSERT(c,s) /* empty */ | ||
23 | #endif | 21 | #endif |
24 | 22 | ||
25 | 23 | ||
@@ -67,27 +65,27 @@ typedef struct lua_TObject { | |||
67 | 65 | ||
68 | /* Macros to set values */ | 66 | /* Macros to set values */ |
69 | #define setnvalue(obj,x) \ | 67 | #define setnvalue(obj,x) \ |
70 | { TObject *o=(obj); o->tt=LUA_TNUMBER; o->value.n=(x); } | 68 | { TObject *_o=(obj); _o->tt=LUA_TNUMBER; _o->value.n=(x); } |
71 | 69 | ||
72 | #define setsvalue(obj,x) \ | 70 | #define setsvalue(obj,x) \ |
73 | { TObject *o=(obj); struct TString *v=(x); \ | 71 | { TObject *_o=(obj); struct TString *_v=(x); \ |
74 | o->tt=LUA_TSTRING; o->value.v=v; } | 72 | _o->tt=LUA_TSTRING; _o->value.v=_v; } |
75 | 73 | ||
76 | #define setuvalue(obj,x) \ | 74 | #define setuvalue(obj,x) \ |
77 | { TObject *o=(obj); struct TString *v=(x); \ | 75 | { TObject *_o=(obj); struct TString *_v=(x); \ |
78 | o->tt=LUA_TUSERDATA; o->value.v=v; } | 76 | _o->tt=LUA_TUSERDATA; _o->value.v=_v; } |
79 | 77 | ||
80 | #define setclvalue(obj,x) \ | 78 | #define setclvalue(obj,x) \ |
81 | { TObject *o=(obj); struct Closure *v=(x); \ | 79 | { TObject *_o=(obj); struct Closure *_v=(x); \ |
82 | o->tt=LUA_TFUNCTION; o->value.v=v; } | 80 | _o->tt=LUA_TFUNCTION; _o->value.v=_v; } |
83 | 81 | ||
84 | #define sethvalue(obj,x) \ | 82 | #define sethvalue(obj,x) \ |
85 | { TObject *o=(obj); struct Hash *v=(x); \ | 83 | { TObject *_o=(obj); struct Hash *_v=(x); \ |
86 | o->tt=LUA_TTABLE; o->value.v=v; } | 84 | _o->tt=LUA_TTABLE; _o->value.v=_v; } |
87 | 85 | ||
88 | #define setivalue(obj,x) \ | 86 | #define setivalue(obj,x) \ |
89 | { TObject *o=(obj); struct CallInfo *v=(x); \ | 87 | { TObject *_o=(obj); struct CallInfo *_v=(x); \ |
90 | o->tt=LUA_TMARK; o->value.v=v; } | 88 | _o->tt=LUA_TMARK; _o->value.v=_v; } |
91 | 89 | ||
92 | #define setnilvalue(obj) { (obj)->tt=LUA_TNIL; } | 90 | #define setnilvalue(obj) { (obj)->tt=LUA_TNIL; } |
93 | 91 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.123 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.124 2001/01/15 16:13:24 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -65,7 +65,7 @@ static void next (LexState *ls) { | |||
65 | 65 | ||
66 | 66 | ||
67 | static void lookahead (LexState *ls) { | 67 | static void lookahead (LexState *ls) { |
68 | LUA_ASSERT(ls->lookahead.token == TK_EOS, "two look-aheads"); | 68 | lua_assert(ls->lookahead.token == TK_EOS); |
69 | ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo); | 69 | ls->lookahead.token = luaX_lex(ls, &ls->lookahead.seminfo); |
70 | } | 70 | } |
71 | 71 | ||
@@ -285,7 +285,7 @@ static void enterbreak (FuncState *fs, Breaklabel *bl) { | |||
285 | 285 | ||
286 | static void leavebreak (FuncState *fs, Breaklabel *bl) { | 286 | static void leavebreak (FuncState *fs, Breaklabel *bl) { |
287 | fs->bl = bl->previous; | 287 | fs->bl = bl->previous; |
288 | LUA_ASSERT(bl->stacklevel == fs->stacklevel, "wrong levels"); | 288 | lua_assert(bl->stacklevel == fs->stacklevel); |
289 | luaK_patchlist(fs, bl->breaklist, luaK_getlabel(fs)); | 289 | luaK_patchlist(fs, bl->breaklist, luaK_getlabel(fs)); |
290 | } | 290 | } |
291 | 291 | ||
@@ -352,7 +352,7 @@ static void close_func (LexState *ls) { | |||
352 | f->lineinfo[fs->nlineinfo++] = MAX_INT; /* end flag */ | 352 | f->lineinfo[fs->nlineinfo++] = MAX_INT; /* end flag */ |
353 | f->sizelineinfo = fs->nlineinfo; | 353 | f->sizelineinfo = fs->nlineinfo; |
354 | ls->fs = fs->prev; | 354 | ls->fs = fs->prev; |
355 | LUA_ASSERT(fs->bl == NULL, "wrong list end"); | 355 | lua_assert(fs->bl == NULL); |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
@@ -365,8 +365,8 @@ Proto *luaY_parser (lua_State *L, ZIO *z) { | |||
365 | chunk(&lexstate); | 365 | chunk(&lexstate); |
366 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); | 366 | check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); |
367 | close_func(&lexstate); | 367 | close_func(&lexstate); |
368 | LUA_ASSERT(funcstate.prev == NULL, "wrong list end"); | 368 | lua_assert(funcstate.prev == NULL); |
369 | LUA_ASSERT(funcstate.nupvalues == 0, "no upvalues in main"); | 369 | lua_assert(funcstate.nupvalues == 0); |
370 | return funcstate.f; | 370 | return funcstate.f; |
371 | } | 371 | } |
372 | 372 | ||
@@ -1130,8 +1130,7 @@ static void chunk (LexState *ls) { | |||
1130 | while (!islast && !block_follow(ls->t.token)) { | 1130 | while (!islast && !block_follow(ls->t.token)) { |
1131 | islast = stat(ls); | 1131 | islast = stat(ls); |
1132 | optional(ls, ';'); | 1132 | optional(ls, ';'); |
1133 | LUA_ASSERT(ls->fs->stacklevel == ls->fs->nactloc, | 1133 | lua_assert(ls->fs->stacklevel == ls->fs->nactloc); |
1134 | "stack size != # local vars"); | ||
1135 | } | 1134 | } |
1136 | } | 1135 | } |
1137 | 1136 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.49 2000/12/26 18:46:09 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.50 2000/12/28 12:55:41 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -47,6 +47,24 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
47 | stacksize = DEFAULT_STACK_SIZE; | 47 | stacksize = DEFAULT_STACK_SIZE; |
48 | else | 48 | else |
49 | stacksize += LUA_MINSTACK; | 49 | stacksize += LUA_MINSTACK; |
50 | L->G = luaM_new(L, global_State); | ||
51 | G(L)->strt.size = G(L)->udt.size = 0; | ||
52 | G(L)->strt.nuse = G(L)->udt.nuse = 0; | ||
53 | G(L)->strt.hash = G(L)->udt.hash = NULL; | ||
54 | G(L)->Mbuffer = NULL; | ||
55 | G(L)->Mbuffsize = 0; | ||
56 | G(L)->rootproto = NULL; | ||
57 | G(L)->rootcl = NULL; | ||
58 | G(L)->roottable = NULL; | ||
59 | G(L)->TMtable = NULL; | ||
60 | G(L)->sizeTM = 0; | ||
61 | G(L)->ntag = 0; | ||
62 | G(L)->refArray = NULL; | ||
63 | G(L)->nref = 0; | ||
64 | G(L)->sizeref = 0; | ||
65 | G(L)->refFree = NONEXT; | ||
66 | G(L)->nblocks = sizeof(lua_State) + sizeof(global_State); | ||
67 | G(L)->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ | ||
50 | L->gt = luaH_new(L, 10); /* table of globals */ | 68 | L->gt = luaH_new(L, 10); /* table of globals */ |
51 | luaD_init(L, stacksize); | 69 | luaD_init(L, stacksize); |
52 | luaS_init(L); | 70 | luaS_init(L); |
@@ -58,61 +76,48 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
58 | #ifdef LUA_DEBUG | 76 | #ifdef LUA_DEBUG |
59 | luaB_opentests(L); | 77 | luaB_opentests(L); |
60 | if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ | 78 | if (lua_state == NULL) lua_state = L; /* keep first state to be opened */ |
61 | LUA_ASSERT(lua_gettop(L) == 0, "wrong API stack"); | 79 | lua_assert(lua_gettop(L) == 0); |
62 | #endif | 80 | #endif |
63 | } | 81 | } |
64 | 82 | ||
65 | 83 | ||
66 | LUA_API lua_State *lua_open (int stacksize) { | 84 | LUA_API lua_State *lua_open (int stacksize) { |
67 | lua_State *L = luaM_new(NULL, lua_State); | 85 | lua_State *L; |
86 | L = luaM_new(NULL, lua_State); | ||
68 | if (L == NULL) return NULL; /* memory allocation error */ | 87 | if (L == NULL) return NULL; /* memory allocation error */ |
88 | L->G = NULL; | ||
69 | L->stack = NULL; | 89 | L->stack = NULL; |
70 | L->stacksize = 0; | 90 | L->stacksize = 0; |
71 | L->strt.size = L->udt.size = 0; | 91 | L->errorJmp = NULL; |
72 | L->strt.nuse = L->udt.nuse = 0; | ||
73 | L->strt.hash = L->udt.hash = NULL; | ||
74 | L->Mbuffer = NULL; | ||
75 | L->Mbuffsize = 0; | ||
76 | L->rootproto = NULL; | ||
77 | L->rootcl = NULL; | ||
78 | L->roottable = NULL; | ||
79 | L->TMtable = NULL; | ||
80 | L->sizeTM = 0; | ||
81 | L->ntag = 0; | ||
82 | L->refArray = NULL; | ||
83 | L->nref = 0; | ||
84 | L->sizeref = 0; | ||
85 | L->refFree = NONEXT; | ||
86 | L->nblocks = sizeof(lua_State); | ||
87 | L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ | ||
88 | L->callhook = NULL; | 92 | L->callhook = NULL; |
89 | L->linehook = NULL; | 93 | L->linehook = NULL; |
90 | L->allowhooks = 1; | 94 | L->allowhooks = 1; |
91 | L->errorJmp = NULL; | ||
92 | if (luaD_runprotected(L, f_luaopen, &stacksize) != 0) { | 95 | if (luaD_runprotected(L, f_luaopen, &stacksize) != 0) { |
93 | /* memory allocation error: free partial state */ | 96 | /* memory allocation error: free partial state */ |
94 | lua_close(L); | 97 | lua_close(L); |
95 | return NULL; | 98 | return NULL; |
96 | } | 99 | } |
97 | L->GCthreshold = 2*L->nblocks; | 100 | G(L)->GCthreshold = 2*G(L)->nblocks; |
98 | return L; | 101 | return L; |
99 | } | 102 | } |
100 | 103 | ||
101 | 104 | ||
102 | LUA_API void lua_close (lua_State *L) { | 105 | LUA_API void lua_close (lua_State *L) { |
103 | LUA_ASSERT(L != lua_state || lua_gettop(L) == 0, "garbage in C stack"); | 106 | lua_assert(L != lua_state || lua_gettop(L) == 0); |
104 | luaC_collect(L, 1); /* collect all elements */ | 107 | if (G(L)) { /* close global state */ |
105 | LUA_ASSERT(L->rootproto == NULL, "list should be empty"); | 108 | luaC_collect(L, 1); /* collect all elements */ |
106 | LUA_ASSERT(L->rootcl == NULL, "list should be empty"); | 109 | lua_assert(G(L)->rootproto == NULL); |
107 | LUA_ASSERT(L->roottable == NULL, "list should be empty"); | 110 | lua_assert(G(L)->rootcl == NULL); |
108 | luaS_freeall(L); | 111 | lua_assert(G(L)->roottable == NULL); |
109 | luaM_freearray(L, L->stack, L->stacksize, TObject); | 112 | luaS_freeall(L); |
110 | luaM_freearray(L, L->TMtable, L->sizeTM, struct TM); | 113 | luaM_freearray(L, G(L)->TMtable, G(L)->sizeTM, struct TM); |
111 | luaM_freearray(L, L->refArray, L->sizeref, struct Ref); | 114 | luaM_freearray(L, G(L)->refArray, G(L)->sizeref, struct Ref); |
112 | luaM_freearray(L, L->Mbuffer, L->Mbuffsize, char); | 115 | luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); |
113 | LUA_ASSERT(L->nblocks == sizeof(lua_State), "wrong count for nblocks"); | 116 | luaM_freelem(NULL, L->G, global_State); |
114 | luaM_freelem(L, L, lua_State); | 117 | } |
115 | LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); | 118 | luaM_freearray(NULL, L->stack, L->stacksize, TObject); |
116 | LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); | 119 | luaM_freelem(NULL, L, lua_State); |
120 | lua_assert(L != lua_state || memdebug_numblocks == 0); | ||
121 | lua_assert(L != lua_state || memdebug_total == 0); | ||
117 | } | 122 | } |
118 | 123 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.42 2000/11/24 17:39:56 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.43 2000/12/26 18:46:09 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,24 +42,17 @@ typedef struct stringtable { | |||
42 | } stringtable; | 42 | } stringtable; |
43 | 43 | ||
44 | 44 | ||
45 | 45 | /* | |
46 | struct lua_State { | 46 | ** "global state", shared by all threads of this state |
47 | /* thread-specific state */ | 47 | */ |
48 | StkId top; /* first free slot in the stack */ | 48 | typedef struct global_State { |
49 | StkId stack; /* stack base */ | ||
50 | StkId stack_last; /* last free slot in the stack */ | ||
51 | int stacksize; | ||
52 | StkId Cbase; /* base for current C function */ | ||
53 | struct lua_longjmp *errorJmp; /* current error recover point */ | ||
54 | char *Mbuffer; /* global buffer */ | 49 | char *Mbuffer; /* global buffer */ |
55 | size_t Mbuffsize; /* size of Mbuffer */ | 50 | size_t Mbuffsize; /* size of Mbuffer */ |
56 | /* global state */ | ||
57 | Proto *rootproto; /* list of all prototypes */ | 51 | Proto *rootproto; /* list of all prototypes */ |
58 | Closure *rootcl; /* list of all closures */ | 52 | Closure *rootcl; /* list of all closures */ |
59 | Hash *roottable; /* list of all tables */ | 53 | Hash *roottable; /* list of all tables */ |
60 | stringtable strt; /* hash table for strings */ | 54 | stringtable strt; /* hash table for strings */ |
61 | stringtable udt; /* hash table for udata */ | 55 | stringtable udt; /* hash table for udata */ |
62 | Hash *gt; /* table for globals */ | ||
63 | struct TM *TMtable; /* table for tag methods */ | 56 | struct TM *TMtable; /* table for tag methods */ |
64 | int sizeTM; /* size of TMtable */ | 57 | int sizeTM; /* size of TMtable */ |
65 | int ntag; /* number of tags in TMtable */ | 58 | int ntag; /* number of tags in TMtable */ |
@@ -69,11 +62,29 @@ struct lua_State { | |||
69 | int refFree; /* list of free positions in refArray */ | 62 | int refFree; /* list of free positions in refArray */ |
70 | mem_int GCthreshold; | 63 | mem_int GCthreshold; |
71 | mem_int nblocks; /* number of `bytes' currently allocated */ | 64 | mem_int nblocks; /* number of `bytes' currently allocated */ |
65 | } global_State; | ||
66 | |||
67 | |||
68 | /* | ||
69 | ** "per thread" state | ||
70 | */ | ||
71 | struct lua_State { | ||
72 | StkId top; /* first free slot in the stack */ | ||
73 | StkId stack; /* stack base */ | ||
74 | StkId stack_last; /* last free slot in the stack */ | ||
75 | int stacksize; | ||
76 | StkId Cbase; /* base for current C function */ | ||
77 | struct lua_longjmp *errorJmp; /* current error recover point */ | ||
78 | Hash *gt; /* table for globals */ | ||
72 | lua_Hook callhook; | 79 | lua_Hook callhook; |
73 | lua_Hook linehook; | 80 | lua_Hook linehook; |
74 | int allowhooks; | 81 | int allowhooks; |
82 | global_State *G; | ||
75 | }; | 83 | }; |
76 | 84 | ||
77 | 85 | ||
86 | #define G(L) (L->G) | ||
87 | |||
88 | |||
78 | #endif | 89 | #endif |
79 | 90 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.49 2001/01/10 17:41:50 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.50 2001/01/11 18:59:20 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,16 +19,16 @@ | |||
19 | 19 | ||
20 | 20 | ||
21 | void luaS_init (lua_State *L) { | 21 | void luaS_init (lua_State *L) { |
22 | luaS_resize(L, &L->strt, MINPOWER2); | 22 | luaS_resize(L, &G(L)->strt, MINPOWER2); |
23 | luaS_resize(L, &L->udt, MINPOWER2); | 23 | luaS_resize(L, &G(L)->udt, MINPOWER2); |
24 | } | 24 | } |
25 | 25 | ||
26 | 26 | ||
27 | void luaS_freeall (lua_State *L) { | 27 | void luaS_freeall (lua_State *L) { |
28 | LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); | 28 | lua_assert(G(L)->strt.nuse==0); |
29 | luaM_freearray(L, L->strt.hash, L->strt.size, TString *); | 29 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *); |
30 | LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); | 30 | lua_assert(G(L)->udt.nuse==0); |
31 | luaM_freearray(L, L->udt.hash, L->udt.size, TString *); | 31 | luaM_freearray(L, G(L)->udt.hash, G(L)->udt.size, TString *); |
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
@@ -41,10 +41,9 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
41 | TString *p = tb->hash[i]; | 41 | TString *p = tb->hash[i]; |
42 | while (p) { /* for each node in the list */ | 42 | while (p) { /* for each node in the list */ |
43 | TString *next = p->nexthash; /* save next */ | 43 | TString *next = p->nexthash; /* save next */ |
44 | luint32 h = (tb == &L->strt) ? p->u.s.hash : IntPoint(p->u.d.value); | 44 | luint32 h = (tb == &G(L)->strt) ? p->u.s.hash : IntPoint(p->u.d.value); |
45 | int h1 = lmod(h, newsize); /* new position */ | 45 | int h1 = lmod(h, newsize); /* new position */ |
46 | LUA_ASSERT((int)(h%newsize) == lmod(h, newsize), | 46 | lua_assert((int)(h%newsize) == lmod(h, newsize)); |
47 | "a&(x-1) == a%x, for x power of 2"); | ||
48 | p->nexthash = newhash[h1]; /* chain it in new position */ | 47 | p->nexthash = newhash[h1]; /* chain it in new position */ |
49 | newhash[h1] = p; | 48 | newhash[h1] = p; |
50 | p = next; | 49 | p = next; |
@@ -73,7 +72,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
73 | size_t l1; | 72 | size_t l1; |
74 | for (l1=l; l1>=step; l1-=step) /* compute hash */ | 73 | for (l1=l; l1>=step; l1-=step) /* compute hash */ |
75 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]); | 74 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]); |
76 | for (ts = L->strt.hash[lmod(h, L->strt.size)]; ts; ts = ts->nexthash) { | 75 | for (ts = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; ts; ts = ts->nexthash) { |
77 | if (ts->len == l && (memcmp(str, ts->str, l) == 0)) | 76 | if (ts->len == l && (memcmp(str, ts->str, l) == 0)) |
78 | return ts; | 77 | return ts; |
79 | } | 78 | } |
@@ -86,7 +85,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
86 | ts->u.s.constindex = 0; | 85 | ts->u.s.constindex = 0; |
87 | memcpy(ts->str, str, l); | 86 | memcpy(ts->str, str, l); |
88 | ts->str[l] = 0; /* ending 0 */ | 87 | ts->str[l] = 0; /* ending 0 */ |
89 | newentry(L, &L->strt, ts, lmod(h, L->strt.size)); /* insert it on table */ | 88 | newentry(L, &G(L)->strt, ts, lmod(h, G(L)->strt.size)); /* insert it */ |
90 | return ts; | 89 | return ts; |
91 | } | 90 | } |
92 | 91 | ||
@@ -100,15 +99,15 @@ TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | |||
100 | ts->u.d.tag = 0; | 99 | ts->u.d.tag = 0; |
101 | ts->u.d.value = (udata == NULL) ? uts+1 : udata; | 100 | ts->u.d.value = (udata == NULL) ? uts+1 : udata; |
102 | /* insert it on table */ | 101 | /* insert it on table */ |
103 | newentry(L, &L->udt, ts, lmod(IntPoint(ts->u.d.value), L->udt.size)); | 102 | newentry(L, &G(L)->udt, ts, lmod(IntPoint(ts->u.d.value), G(L)->udt.size)); |
104 | return ts; | 103 | return ts; |
105 | } | 104 | } |
106 | 105 | ||
107 | 106 | ||
108 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { | 107 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { |
109 | int h1 = lmod(IntPoint(udata), L->udt.size); | 108 | int h1 = lmod(IntPoint(udata), G(L)->udt.size); |
110 | TString *ts; | 109 | TString *ts; |
111 | for (ts = L->udt.hash[h1]; ts; ts = ts->nexthash) { | 110 | for (ts = G(L)->udt.hash[h1]; ts; ts = ts->nexthash) { |
112 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) | 111 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) |
113 | return ts; | 112 | return ts; |
114 | } | 113 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.63 2001/01/10 18:56:11 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.64 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -144,7 +144,7 @@ void luaH_remove (Hash *t, TObject *key) { | |||
144 | n += t->size; | 144 | n += t->size; |
145 | } | 145 | } |
146 | setnvalue(key, n); | 146 | setnvalue(key, n); |
147 | LUA_ASSERT(luaH_mainposition(t, key) == mp, "cannot change hash"); | 147 | lua_assert(luaH_mainposition(t, key) == mp); |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
@@ -167,8 +167,8 @@ static void setnodevector (lua_State *L, Hash *t, luint32 size) { | |||
167 | Hash *luaH_new (lua_State *L, int size) { | 167 | Hash *luaH_new (lua_State *L, int size) { |
168 | Hash *t = luaM_new(L, Hash); | 168 | Hash *t = luaM_new(L, Hash); |
169 | t->htag = TagDefault; | 169 | t->htag = TagDefault; |
170 | t->next = L->roottable; | 170 | t->next = G(L)->roottable; |
171 | L->roottable = t; | 171 | G(L)->roottable = t; |
172 | t->mark = t; | 172 | t->mark = t; |
173 | t->size = 0; | 173 | t->size = 0; |
174 | t->node = NULL; | 174 | t->node = NULL; |
@@ -201,7 +201,7 @@ static void rehash (lua_State *L, Hash *t) { | |||
201 | Node *nold = t->node; | 201 | Node *nold = t->node; |
202 | int nelems = numuse(t); | 202 | int nelems = numuse(t); |
203 | int i; | 203 | int i; |
204 | LUA_ASSERT(nelems<=oldsize, "wrong count"); | 204 | lua_assert(nelems<=oldsize); |
205 | if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ | 205 | if (nelems >= oldsize-oldsize/4) /* using more than 3/4? */ |
206 | setnodevector(L, t, (luint32)oldsize*2); | 206 | setnodevector(L, t, (luint32)oldsize*2); |
207 | else if (nelems <= oldsize/4 && /* less than 1/4? */ | 207 | else if (nelems <= oldsize/4 && /* less than 1/4? */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.56 2001/01/15 16:13:24 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.57 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -215,7 +215,8 @@ static int table_query (lua_State *L) { | |||
215 | 215 | ||
216 | 216 | ||
217 | static int string_query (lua_State *L) { | 217 | static int string_query (lua_State *L) { |
218 | stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &L->strt : &L->udt; | 218 | stringtable *tb = (*luaL_check_string(L, 1) == 's') ? &G(L)->strt : |
219 | &G(L)->udt; | ||
219 | int s = luaL_opt_int(L, 2, 0) - 1; | 220 | int s = luaL_opt_int(L, 2, 0) - 1; |
220 | if (s==-1) { | 221 | if (s==-1) { |
221 | lua_pushnumber(L ,tb->nuse); | 222 | lua_pushnumber(L ,tb->nuse); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.59 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.60 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -68,36 +68,36 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | |||
68 | static void init_entry (lua_State *L, int tag) { | 68 | static void init_entry (lua_State *L, int tag) { |
69 | int i; | 69 | int i; |
70 | for (i=0; i<TM_N; i++) | 70 | for (i=0; i<TM_N; i++) |
71 | luaT_gettm(L, tag, i) = NULL; | 71 | luaT_gettm(G(L), tag, i) = NULL; |
72 | L->TMtable[tag].collected = NULL; | 72 | G(L)->TMtable[tag].collected = NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void luaT_init (lua_State *L) { | 76 | void luaT_init (lua_State *L) { |
77 | int t; | 77 | int t; |
78 | L->TMtable = luaM_newvector(L, NUM_TAGS+2, struct TM); | 78 | G(L)->TMtable = luaM_newvector(L, NUM_TAGS+2, struct TM); |
79 | L->sizeTM = NUM_TAGS+2; | 79 | G(L)->sizeTM = NUM_TAGS+2; |
80 | L->ntag = NUM_TAGS; | 80 | G(L)->ntag = NUM_TAGS; |
81 | for (t=0; t<L->ntag; t++) | 81 | for (t=0; t<G(L)->ntag; t++) |
82 | init_entry(L, t); | 82 | init_entry(L, t); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | LUA_API int lua_newtag (lua_State *L) { | 86 | LUA_API int lua_newtag (lua_State *L) { |
87 | luaM_growvector(L, L->TMtable, L->ntag, L->sizeTM, struct TM, | 87 | luaM_growvector(L, G(L)->TMtable, G(L)->ntag, G(L)->sizeTM, struct TM, |
88 | MAX_INT, "tag table overflow"); | 88 | MAX_INT, "tag table overflow"); |
89 | init_entry(L, L->ntag); | 89 | init_entry(L, G(L)->ntag); |
90 | return L->ntag++; | 90 | return G(L)->ntag++; |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | static void checktag (lua_State *L, int tag) { | 94 | static void checktag (lua_State *L, int tag) { |
95 | if (!(0 <= tag && tag < L->ntag)) | 95 | if (!(0 <= tag && tag < G(L)->ntag)) |
96 | luaO_verror(L, "%d is not a valid tag", tag); | 96 | luaO_verror(L, "%d is not a valid tag", tag); |
97 | } | 97 | } |
98 | 98 | ||
99 | void luaT_realtag (lua_State *L, int tag) { | 99 | void luaT_realtag (lua_State *L, int tag) { |
100 | if (!validtag(tag)) | 100 | if (!validtag(G(L), tag)) |
101 | luaO_verror(L, "tag %d was not created by `newtag'", tag); | 101 | luaO_verror(L, "tag %d was not created by `newtag'", tag); |
102 | } | 102 | } |
103 | 103 | ||
@@ -108,7 +108,7 @@ LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) { | |||
108 | checktag(L, tagfrom); | 108 | checktag(L, tagfrom); |
109 | for (e=0; e<TM_N; e++) { | 109 | for (e=0; e<TM_N; e++) { |
110 | if (luaT_validevent(tagto, e)) | 110 | if (luaT_validevent(tagto, e)) |
111 | luaT_gettm(L, tagto, e) = luaT_gettm(L, tagfrom, e); | 111 | luaT_gettm(G(L), tagto, e) = luaT_gettm(G(L), tagfrom, e); |
112 | } | 112 | } |
113 | return tagto; | 113 | return tagto; |
114 | } | 114 | } |
@@ -128,8 +128,8 @@ LUA_API void lua_gettagmethod (lua_State *L, int t, const char *event) { | |||
128 | int e; | 128 | int e; |
129 | e = luaI_checkevent(L, event, t); | 129 | e = luaI_checkevent(L, event, t); |
130 | checktag(L, t); | 130 | checktag(L, t); |
131 | if (luaT_validevent(t, e) && luaT_gettm(L, t, e)) { | 131 | if (luaT_validevent(t, e) && luaT_gettm(G(L), t, e)) { |
132 | setclvalue(L->top, luaT_gettm(L, t, e)); | 132 | setclvalue(L->top, luaT_gettm(G(L), t, e)); |
133 | } | 133 | } |
134 | else | 134 | else |
135 | setnilvalue(L->top); | 135 | setnilvalue(L->top); |
@@ -147,10 +147,10 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const char *event) { | |||
147 | " with default tag" : ""); | 147 | " with default tag" : ""); |
148 | switch (ttype(L->top - 1)) { | 148 | switch (ttype(L->top - 1)) { |
149 | case LUA_TNIL: | 149 | case LUA_TNIL: |
150 | luaT_gettm(L, t, e) = NULL; | 150 | luaT_gettm(G(L), t, e) = NULL; |
151 | break; | 151 | break; |
152 | case LUA_TFUNCTION: | 152 | case LUA_TFUNCTION: |
153 | luaT_gettm(L, t, e) = clvalue(L->top - 1); | 153 | luaT_gettm(G(L), t, e) = clvalue(L->top - 1); |
154 | break; | 154 | break; |
155 | default: | 155 | default: |
156 | lua_error(L, "tag method must be a function (or nil)"); | 156 | lua_error(L, "tag method must be a function (or nil)"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 1.18 2000/10/05 13:00:17 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.19 2000/12/26 18:46:09 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,11 +41,11 @@ struct TM { | |||
41 | }; | 41 | }; |
42 | 42 | ||
43 | 43 | ||
44 | #define luaT_gettm(L,tag,event) (L->TMtable[tag].method[event]) | 44 | #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event]) |
45 | #define luaT_gettmbyObj(L,o,e) (luaT_gettm((L),luaT_tag(o),(e))) | 45 | #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e))) |
46 | 46 | ||
47 | 47 | ||
48 | #define validtag(t) (NUM_TAGS <= (t) && (t) < L->ntag) | 48 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) |
49 | 49 | ||
50 | extern const char *const luaT_eventname[]; | 50 | extern const char *const luaT_eventname[]; |
51 | 51 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.153 2001/01/15 16:13:24 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.154 2001/01/18 15:59:09 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -118,16 +118,16 @@ const TObject *luaV_gettable (lua_State *L, StkId t) { | |||
118 | int tg; | 118 | int tg; |
119 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ | 119 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ |
120 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ | 120 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ |
121 | luaT_gettm(L, tg, TM_GETTABLE) == NULL)) { /* or no TM? */ | 121 | luaT_gettm(G(L), tg, TM_GETTABLE) == NULL)) { /* or no TM? */ |
122 | /* do a primitive get */ | 122 | /* do a primitive get */ |
123 | const TObject *h = luaH_get(hvalue(t), L->top-1); | 123 | const TObject *h = luaH_get(hvalue(t), L->top-1); |
124 | /* result is no nil or there is no `index' tag method? */ | 124 | /* result is no nil or there is no `index' tag method? */ |
125 | if (ttype(h) != LUA_TNIL || ((tm=luaT_gettm(L, tg, TM_INDEX)) == NULL)) | 125 | if (ttype(h) != LUA_TNIL || ((tm=luaT_gettm(G(L), tg, TM_INDEX)) == NULL)) |
126 | return h; /* return result */ | 126 | return h; /* return result */ |
127 | /* else call `index' tag method */ | 127 | /* else call `index' tag method */ |
128 | } | 128 | } |
129 | else { /* try a `gettable' tag method */ | 129 | else { /* try a `gettable' tag method */ |
130 | tm = luaT_gettmbyObj(L, t, TM_GETTABLE); | 130 | tm = luaT_gettmbyObj(G(L), t, TM_GETTABLE); |
131 | } | 131 | } |
132 | if (tm != NULL) { /* is there a tag method? */ | 132 | if (tm != NULL) { /* is there a tag method? */ |
133 | luaD_checkstack(L, 2); | 133 | luaD_checkstack(L, 2); |
@@ -152,11 +152,11 @@ void luaV_settable (lua_State *L, StkId t, StkId key) { | |||
152 | int tg; | 152 | int tg; |
153 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ | 153 | if (ttype(t) == LUA_TTABLE && /* `t' is a table? */ |
154 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ | 154 | ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ |
155 | luaT_gettm(L, tg, TM_SETTABLE) == NULL)) { /* or no TM? */ | 155 | luaT_gettm(G(L), tg, TM_SETTABLE) == NULL)) { /* or no TM? */ |
156 | setobj(luaH_set(L, hvalue(t), key), L->top-1); /* do a primitive set */ | 156 | setobj(luaH_set(L, hvalue(t), key), L->top-1); /* do a primitive set */ |
157 | } | 157 | } |
158 | else { /* try a `settable' tag method */ | 158 | else { /* try a `settable' tag method */ |
159 | Closure *tm = luaT_gettmbyObj(L, t, TM_SETTABLE); | 159 | Closure *tm = luaT_gettmbyObj(G(L), t, TM_SETTABLE); |
160 | if (tm != NULL) { | 160 | if (tm != NULL) { |
161 | luaD_checkstack(L, 3); | 161 | luaD_checkstack(L, 3); |
162 | setobj(L->top+2, L->top-1); | 162 | setobj(L->top+2, L->top-1); |
@@ -174,7 +174,7 @@ void luaV_settable (lua_State *L, StkId t, StkId key) { | |||
174 | 174 | ||
175 | const TObject *luaV_getglobal (lua_State *L, TString *s) { | 175 | const TObject *luaV_getglobal (lua_State *L, TString *s) { |
176 | const TObject *value = luaH_getstr(L->gt, s); | 176 | const TObject *value = luaH_getstr(L->gt, s); |
177 | Closure *tm = luaT_gettmbyObj(L, value, TM_GETGLOBAL); | 177 | Closure *tm = luaT_gettmbyObj(G(L), value, TM_GETGLOBAL); |
178 | if (tm == NULL) /* is there a tag method? */ | 178 | if (tm == NULL) /* is there a tag method? */ |
179 | return value; /* default behavior */ | 179 | return value; /* default behavior */ |
180 | else { /* tag method */ | 180 | else { /* tag method */ |
@@ -191,7 +191,7 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) { | |||
191 | 191 | ||
192 | void luaV_setglobal (lua_State *L, TString *s) { | 192 | void luaV_setglobal (lua_State *L, TString *s) { |
193 | TObject *oldvalue = luaH_setstr(L, L->gt, s); | 193 | TObject *oldvalue = luaH_setstr(L, L->gt, s); |
194 | Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL); | 194 | Closure *tm = luaT_gettmbyObj(G(L), oldvalue, TM_SETGLOBAL); |
195 | if (tm == NULL) { /* no tag methods? */ | 195 | if (tm == NULL) { /* no tag methods? */ |
196 | setobj(oldvalue, L->top - 1); /* raw set */ | 196 | setobj(oldvalue, L->top - 1); /* raw set */ |
197 | } | 197 | } |
@@ -209,12 +209,12 @@ void luaV_setglobal (lua_State *L, TString *s) { | |||
209 | 209 | ||
210 | static int call_binTM (lua_State *L, StkId top, TMS event) { | 210 | static int call_binTM (lua_State *L, StkId top, TMS event) { |
211 | /* try first operand */ | 211 | /* try first operand */ |
212 | Closure *tm = luaT_gettmbyObj(L, top-2, event); | 212 | Closure *tm = luaT_gettmbyObj(G(L), top-2, event); |
213 | L->top = top; | 213 | L->top = top; |
214 | if (tm == NULL) { | 214 | if (tm == NULL) { |
215 | tm = luaT_gettmbyObj(L, top-1, event); /* try second operand */ | 215 | tm = luaT_gettmbyObj(G(L), top-1, event); /* try second operand */ |
216 | if (tm == NULL) { | 216 | if (tm == NULL) { |
217 | tm = luaT_gettm(L, 0, event); /* try a `global' method */ | 217 | tm = luaT_gettm(G(L), 0, event); /* try a `global' method */ |
218 | if (tm == NULL) | 218 | if (tm == NULL) |
219 | return 0; /* error */ | 219 | return 0; /* error */ |
220 | } | 220 | } |
@@ -369,7 +369,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
369 | } | 369 | } |
370 | case OP_PUSHNIL: { | 370 | case OP_PUSHNIL: { |
371 | int n = GETARG_U(i); | 371 | int n = GETARG_U(i); |
372 | LUA_ASSERT(n>0, "invalid argument"); | 372 | lua_assert(n>0); |
373 | do { | 373 | do { |
374 | setnilvalue(top++); | 374 | setnilvalue(top++); |
375 | } while (--n > 0); | 375 | } while (--n > 0); |
@@ -620,8 +620,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
620 | break; | 620 | break; |
621 | } | 621 | } |
622 | case OP_FORLOOP: { | 622 | case OP_FORLOOP: { |
623 | LUA_ASSERT(ttype(top-1) == LUA_TNUMBER, "invalid step"); | 623 | lua_assert(ttype(top-1) == LUA_TNUMBER); |
624 | LUA_ASSERT(ttype(top-2) == LUA_TNUMBER, "invalid limit"); | 624 | lua_assert(ttype(top-2) == LUA_TNUMBER); |
625 | if (ttype(top-3) != LUA_TNUMBER) | 625 | if (ttype(top-3) != LUA_TNUMBER) |
626 | lua_error(L, "`for' index must be a number"); | 626 | lua_error(L, "`for' index must be a number"); |
627 | nvalue(top-3) += nvalue(top-1); /* increment index */ | 627 | nvalue(top-3) += nvalue(top-1); /* increment index */ |
@@ -651,7 +651,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) { | |||
651 | } | 651 | } |
652 | case OP_LFORLOOP: { | 652 | case OP_LFORLOOP: { |
653 | Node *node; | 653 | Node *node; |
654 | LUA_ASSERT(ttype(top-3) == LUA_TTABLE, "invalid table"); | 654 | lua_assert(ttype(top-3) == LUA_TTABLE); |
655 | node = luaH_next(L, hvalue(top-3), top-2); | 655 | node = luaH_next(L, hvalue(top-3), top-2); |
656 | if (node == NULL) /* end loop? */ | 656 | if (node == NULL) /* end loop? */ |
657 | top -= 3; /* remove table, key, and value */ | 657 | top -= 3; /* remove table, key, and value */ |