diff options
-rw-r--r-- | lapi.c | 3 | ||||
-rw-r--r-- | lcode.c | 9 | ||||
-rw-r--r-- | ldo.c | 11 | ||||
-rw-r--r-- | lfunc.c | 36 | ||||
-rw-r--r-- | lfunc.h | 3 | ||||
-rw-r--r-- | lgc.c | 8 | ||||
-rw-r--r-- | llimits.h | 11 | ||||
-rw-r--r-- | lobject.c | 9 | ||||
-rw-r--r-- | lobject.h | 14 | ||||
-rw-r--r-- | lparser.c | 8 | ||||
-rw-r--r-- | lparser.h | 3 | ||||
-rw-r--r-- | lstate.c | 11 | ||||
-rw-r--r-- | lstate.h | 4 | ||||
-rw-r--r-- | lstring.c | 9 | ||||
-rw-r--r-- | lstring.h | 6 | ||||
-rw-r--r-- | ltable.c | 4 | ||||
-rw-r--r-- | ltests.c | 5 | ||||
-rw-r--r-- | ltm.c | 4 |
18 files changed, 95 insertions, 63 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.99 2000/09/18 19:39:26 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.100 2000/09/27 12:51:39 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 | */ |
@@ -355,6 +355,7 @@ int lua_ref (lua_State *L, int lock) { | |||
355 | else { /* no more free places */ | 355 | else { /* no more free places */ |
356 | luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref, | 356 | luaM_growvector(L, L->refArray, L->refSize, 1, struct Ref, |
357 | "reference table overflow", MAX_INT); | 357 | "reference table overflow", MAX_INT); |
358 | L->nblocks += sizeof(struct Ref); | ||
358 | ref = L->refSize++; | 359 | ref = L->refSize++; |
359 | } | 360 | } |
360 | L->refArray[ref].o = *(L->top-1); | 361 | L->refArray[ref].o = *(L->top-1); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 1.49 2000/08/15 13:18:28 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.50 2000/08/31 14:08:27 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 | */ |
@@ -420,13 +420,14 @@ void luaK_posfix (LexState *ls, BinOpr op, expdesc *v1, expdesc *v2) { | |||
420 | 420 | ||
421 | 421 | ||
422 | static void codelineinfo (FuncState *fs) { | 422 | static void codelineinfo (FuncState *fs) { |
423 | Proto *f = fs->f; | ||
423 | LexState *ls = fs->ls; | 424 | LexState *ls = fs->ls; |
424 | if (ls->lastline > fs->lastline) { | 425 | if (ls->lastline > fs->lastline) { |
425 | luaM_growvector(fs->L, fs->f->lineinfo, fs->nlineinfo, 2, int, | 426 | luaM_growvector(fs->L, f->lineinfo, f->nlineinfo, 2, int, |
426 | "line info overflow", MAX_INT); | 427 | "line info overflow", MAX_INT); |
427 | if (ls->lastline > fs->lastline+1) | 428 | if (ls->lastline > fs->lastline+1) |
428 | fs->f->lineinfo[fs->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); | 429 | f->lineinfo[f->nlineinfo++] = -(ls->lastline - (fs->lastline+1)); |
429 | fs->f->lineinfo[fs->nlineinfo++] = fs->pc; | 430 | f->lineinfo[f->nlineinfo++] = fs->pc; |
430 | fs->lastline = ls->lastline; | 431 | fs->lastline = ls->lastline; |
431 | } | 432 | } |
432 | } | 433 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.96 2000/09/12 13:47:39 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.97 2000/09/25 16:22:42 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 | */ |
@@ -33,6 +33,7 @@ | |||
33 | 33 | ||
34 | void luaD_init (lua_State *L, int stacksize) { | 34 | void luaD_init (lua_State *L, int stacksize) { |
35 | L->stack = luaM_newvector(L, stacksize+EXTRA_STACK, TObject); | 35 | L->stack = luaM_newvector(L, stacksize+EXTRA_STACK, TObject); |
36 | L->nblocks += stacksize*sizeof(TObject); | ||
36 | L->stack_last = L->stack+(stacksize-1); | 37 | L->stack_last = L->stack+(stacksize-1); |
37 | L->stacksize = stacksize; | 38 | L->stacksize = stacksize; |
38 | L->Cbase = L->top = L->stack; | 39 | L->Cbase = L->top = L->stack; |
@@ -248,10 +249,12 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
248 | luaC_checkGC(L); | 249 | luaC_checkGC(L); |
249 | old_blocks = L->nblocks; | 250 | old_blocks = L->nblocks; |
250 | status = luaD_runprotected(L, f_parser, &p); | 251 | status = luaD_runprotected(L, f_parser, &p); |
251 | if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | 252 | if (status == 0) { |
253 | /* add new memory to threshould (as it probably will stay) */ | ||
254 | L->GCthreshold += (L->nblocks - old_blocks); | ||
255 | } | ||
256 | else if (status == LUA_ERRRUN) /* an error occurred: correct error code */ | ||
252 | status = LUA_ERRSYNTAX; | 257 | status = LUA_ERRSYNTAX; |
253 | /* add new memory to threshould (as it probably will stay) */ | ||
254 | L->GCthreshold += (L->nblocks - old_blocks); | ||
255 | return status; | 258 | return status; |
256 | } | 259 | } |
257 | 260 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 1.29 2000/08/09 19:16:57 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.30 2000/08/22 17:44:17 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 | */ |
@@ -13,19 +13,18 @@ | |||
13 | #include "lmem.h" | 13 | #include "lmem.h" |
14 | #include "lstate.h" | 14 | #include "lstate.h" |
15 | 15 | ||
16 | #define gcsizeproto(L, p) numblocks(L, 0, sizeof(Proto)) | ||
17 | #define gcsizeclosure(L, c) numblocks(L, c->nupvalues, sizeof(Closure)) | ||
18 | 16 | ||
17 | #define sizeclosure(n) (sizeof(Closure) + (lint32)sizeof(TObject)*((n)-1)) | ||
19 | 18 | ||
20 | 19 | ||
21 | Closure *luaF_newclosure (lua_State *L, int nelems) { | 20 | Closure *luaF_newclosure (lua_State *L, int nelems) { |
22 | Closure *c = (Closure *)luaM_malloc(L, sizeof(Closure) + | 21 | lint32 size = sizeclosure(nelems); |
23 | (lint32)sizeof(TObject)*(nelems-1)); | 22 | Closure *c = (Closure *)luaM_malloc(L, size); |
24 | c->next = L->rootcl; | 23 | c->next = L->rootcl; |
25 | L->rootcl = c; | 24 | L->rootcl = c; |
26 | c->mark = c; | 25 | c->mark = c; |
27 | c->nupvalues = nelems; | 26 | c->nupvalues = nelems; |
28 | L->nblocks += gcsizeclosure(L, c); | 27 | L->nblocks += size; |
29 | return c; | 28 | return c; |
30 | } | 29 | } |
31 | 30 | ||
@@ -33,7 +32,9 @@ Closure *luaF_newclosure (lua_State *L, int nelems) { | |||
33 | Proto *luaF_newproto (lua_State *L) { | 32 | Proto *luaF_newproto (lua_State *L) { |
34 | Proto *f = luaM_new(L, Proto); | 33 | Proto *f = luaM_new(L, Proto); |
35 | f->code = NULL; | 34 | f->code = NULL; |
35 | f->ncode = 0; | ||
36 | f->lineinfo = NULL; | 36 | f->lineinfo = NULL; |
37 | f->nlineinfo = 0; | ||
37 | f->lineDefined = 0; | 38 | f->lineDefined = 0; |
38 | f->source = NULL; | 39 | f->source = NULL; |
39 | f->kstr = NULL; | 40 | f->kstr = NULL; |
@@ -47,13 +48,30 @@ Proto *luaF_newproto (lua_State *L) { | |||
47 | f->next = L->rootproto; | 48 | f->next = L->rootproto; |
48 | L->rootproto = f; | 49 | L->rootproto = f; |
49 | f->marked = 0; | 50 | f->marked = 0; |
50 | L->nblocks += gcsizeproto(L, f); | ||
51 | return f; | 51 | return f; |
52 | } | 52 | } |
53 | 53 | ||
54 | 54 | ||
55 | static size_t protosize (Proto *f) { | ||
56 | return sizeof(Proto) | ||
57 | + f->nknum*sizeof(Number) | ||
58 | + f->nkstr*sizeof(TString *) | ||
59 | + f->nkproto*sizeof(Proto *) | ||
60 | + f->ncode*sizeof(Instruction) | ||
61 | + f->nlocvars*sizeof(struct LocVar) | ||
62 | + f->nlineinfo*sizeof(int); | ||
63 | } | ||
64 | |||
65 | |||
66 | void luaF_protook (lua_State *L, Proto *f, int pc) { | ||
67 | f->ncode = pc; /* signal that proto was properly created */ | ||
68 | L->nblocks += protosize(f); | ||
69 | } | ||
70 | |||
71 | |||
55 | void luaF_freeproto (lua_State *L, Proto *f) { | 72 | void luaF_freeproto (lua_State *L, Proto *f) { |
56 | L->nblocks -= gcsizeproto(L, f); | 73 | if (f->ncode > 0) /* function was properly created? */ |
74 | L->nblocks -= protosize(f); | ||
57 | luaM_free(L, f->code); | 75 | luaM_free(L, f->code); |
58 | luaM_free(L, f->locvars); | 76 | luaM_free(L, f->locvars); |
59 | luaM_free(L, f->kstr); | 77 | luaM_free(L, f->kstr); |
@@ -65,7 +83,7 @@ void luaF_freeproto (lua_State *L, Proto *f) { | |||
65 | 83 | ||
66 | 84 | ||
67 | void luaF_freeclosure (lua_State *L, Closure *c) { | 85 | void luaF_freeclosure (lua_State *L, Closure *c) { |
68 | L->nblocks -= gcsizeclosure(L, c); | 86 | L->nblocks -= sizeclosure(c->nupvalues); |
69 | luaM_free(L, c); | 87 | luaM_free(L, c); |
70 | } | 88 | } |
71 | 89 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.h,v 1.11 2000/03/10 18:37:44 roberto Exp roberto $ | 2 | ** $Id: lfunc.h,v 1.12 2000/06/26 19:28:31 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 | */ |
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | 14 | ||
15 | Proto *luaF_newproto (lua_State *L); | 15 | Proto *luaF_newproto (lua_State *L); |
16 | void luaF_protook (lua_State *L, Proto *f, int pc); | ||
16 | Closure *luaF_newclosure (lua_State *L, int nelems); | 17 | Closure *luaF_newclosure (lua_State *L, int nelems); |
17 | void luaF_freeproto (lua_State *L, Proto *f); | 18 | void luaF_freeproto (lua_State *L, Proto *f); |
18 | void luaF_freeclosure (lua_State *L, Closure *c); | 19 | void luaF_freeclosure (lua_State *L, Closure *c); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.66 2000/09/19 08:42:35 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.67 2000/09/25 14:52:10 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 | */ |
@@ -254,7 +254,7 @@ static void collectstringtab (lua_State *L, int limit) { | |||
254 | else { /* collect */ | 254 | else { /* collect */ |
255 | *p = next->nexthash; | 255 | *p = next->nexthash; |
256 | L->strt.nuse--; | 256 | L->strt.nuse--; |
257 | L->nblocks -= gcsizestring(L, next->u.s.len); | 257 | L->nblocks -= sizestring(next->u.s.len); |
258 | luaM_free(L, next); | 258 | luaM_free(L, next); |
259 | } | 259 | } |
260 | } | 260 | } |
@@ -343,7 +343,9 @@ long lua_collectgarbage (lua_State *L, long limit) { | |||
343 | recovered = recovered - L->nblocks; | 343 | recovered = recovered - L->nblocks; |
344 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; | 344 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; |
345 | if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ | 345 | if (L->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ |
346 | L->Mbuffsize /= 2; /* still larger than MINBUFFER */ | 346 | size_t diff = L->Mbuffsize/2; |
347 | L->Mbuffsize -= diff; /* still larger than MINBUFFER */ | ||
348 | L->nblocks -= diff*sizeof(char); | ||
347 | luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char); | 349 | luaM_reallocvector(L, L->Mbuffer, L->Mbuffsize, char); |
348 | } | 350 | } |
349 | callgcTM(L, &luaO_nilobject); | 351 | callgcTM(L, &luaO_nilobject); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.13 2000/08/28 17:57:04 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.14 2000/08/29 14:48:16 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other "installation-dependent" definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -57,13 +57,6 @@ typedef unsigned long lint32; /* unsigned int with at least 32 bits */ | |||
57 | #define IntPoint(p) (((unsigned long)(p)) >> 3) | 57 | #define IntPoint(p) (((unsigned long)(p)) >> 3) |
58 | 58 | ||
59 | 59 | ||
60 | /* | ||
61 | ** number of `blocks' for garbage collection: each reference to other | ||
62 | ** objects count 1, and each 32 bytes of `raw' memory count 1; we add | ||
63 | ** 2 to the total as a minimum (and also to count the overhead of malloc) | ||
64 | */ | ||
65 | #define numblocks(L, o,b) ((o)+((b)>>5)+2) | ||
66 | |||
67 | 60 | ||
68 | #define MINPOWER2 4 /* minimum size for "growing" vectors */ | 61 | #define MINPOWER2 4 /* minimum size for "growing" vectors */ |
69 | 62 | ||
@@ -77,7 +70,7 @@ typedef unsigned long lint32; /* unsigned int with at least 32 bits */ | |||
77 | 70 | ||
78 | /* | 71 | /* |
79 | ** type for virtual-machine instructions | 72 | ** type for virtual-machine instructions |
80 | ** must be an unsigned with 4 bytes (see details in lopcodes.h) | 73 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) |
81 | ** For a very small machine, you may change that to 2 bytes (and adjust | 74 | ** For a very small machine, you may change that to 2 bytes (and adjust |
82 | ** the following limits accordingly) | 75 | ** the following limits accordingly) |
83 | */ | 76 | */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.c,v 1.47 2000/09/11 20:29:27 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.48 2000/09/12 13:47:39 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 | */ |
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | /* | 20 | /* |
21 | ** you can use the fact that the 3rd letter or each name is always different | 21 | ** you can use the fact that the 3rd letter of each name is always different |
22 | ** (e-m-r-b-n-l) to compare and switch these strings | 22 | ** (e-m-r-b-n-l) to compare and switch these strings |
23 | */ | 23 | */ |
24 | const char *const luaO_typenames[] = { /* ORDER LUA_T */ | 24 | const char *const luaO_typenames[] = { /* ORDER LUA_T */ |
@@ -61,6 +61,7 @@ int luaO_equalObj (const TObject *t1, const TObject *t2) { | |||
61 | char *luaO_openspace (lua_State *L, size_t n) { | 61 | char *luaO_openspace (lua_State *L, size_t n) { |
62 | if (n > L->Mbuffsize) { | 62 | if (n > L->Mbuffsize) { |
63 | luaM_reallocvector(L, L->Mbuffer, n, char); | 63 | luaM_reallocvector(L, L->Mbuffer, n, char); |
64 | L->nblocks += (n - L->Mbuffsize)*sizeof(char); | ||
64 | L->Mbuffsize = n; | 65 | L->Mbuffsize = n; |
65 | } | 66 | } |
66 | return L->Mbuffer; | 67 | return L->Mbuffer; |
@@ -127,10 +128,10 @@ int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */ | |||
127 | } | 128 | } |
128 | 129 | ||
129 | 130 | ||
130 | /* this function needs to handle only '%d' and '%.XXXs' formats */ | 131 | /* this function needs to handle only '%d' and '%.XXs' formats */ |
131 | void luaO_verror (lua_State *L, const char *fmt, ...) { | 132 | void luaO_verror (lua_State *L, const char *fmt, ...) { |
132 | char buff[500]; | ||
133 | va_list argp; | 133 | va_list argp; |
134 | char buff[600]; /* to hold formated message */ | ||
134 | va_start(argp, fmt); | 135 | va_start(argp, fmt); |
135 | vsprintf(buff, fmt, argp); | 136 | vsprintf(buff, fmt, argp); |
136 | va_end(argp); | 137 | va_end(argp); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.75 2000/09/11 17:38:42 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.76 2000/09/11 20:29:27 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 | */ |
@@ -116,14 +116,16 @@ typedef struct Proto { | |||
116 | int nkstr; /* size of `kstr' */ | 116 | int nkstr; /* size of `kstr' */ |
117 | struct Proto **kproto; /* functions defined inside the function */ | 117 | struct Proto **kproto; /* functions defined inside the function */ |
118 | int nkproto; /* size of `kproto' */ | 118 | int nkproto; /* size of `kproto' */ |
119 | Instruction *code; /* ends with opcode ENDCODE */ | 119 | Instruction *code; |
120 | int numparams; | 120 | int ncode; /* size of `code'; when 0 means an incomplete `Proto' */ |
121 | int is_vararg; | 121 | short numparams; |
122 | int maxstacksize; | 122 | short is_vararg; |
123 | short maxstacksize; | ||
124 | short marked; | ||
123 | struct Proto *next; | 125 | struct Proto *next; |
124 | int marked; | ||
125 | /* debug information */ | 126 | /* debug information */ |
126 | int *lineinfo; /* map from opcodes to source lines */ | 127 | int *lineinfo; /* map from opcodes to source lines */ |
128 | int nlineinfo; /* size of `lineinfo' */ | ||
127 | int nlocvars; | 129 | int nlocvars; |
128 | struct LocVar *locvars; /* information about local variables */ | 130 | struct LocVar *locvars; /* information about local variables */ |
129 | int lineDefined; | 131 | int lineDefined; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.112 2000/09/20 17:57:08 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.113 2000/09/27 17:41:58 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 | */ |
@@ -315,7 +315,6 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
315 | f->source = ls->source; | 315 | f->source = ls->source; |
316 | fs->pc = 0; | 316 | fs->pc = 0; |
317 | fs->lasttarget = 0; | 317 | fs->lasttarget = 0; |
318 | fs->nlineinfo = 0; | ||
319 | fs->lastline = 0; | 318 | fs->lastline = 0; |
320 | fs->jlt = NO_JUMP; | 319 | fs->jlt = NO_JUMP; |
321 | f->code = NULL; | 320 | f->code = NULL; |
@@ -337,8 +336,9 @@ static void close_func (LexState *ls) { | |||
337 | luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); | 336 | luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); |
338 | removelocalvars(ls, fs->nactloc); | 337 | removelocalvars(ls, fs->nactloc); |
339 | luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar); | 338 | luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar); |
340 | luaM_reallocvector(L, f->lineinfo, fs->nlineinfo+1, int); | 339 | luaM_reallocvector(L, f->lineinfo, f->nlineinfo+1, int); |
341 | f->lineinfo[fs->nlineinfo] = MAX_INT; /* end flag */ | 340 | f->lineinfo[f->nlineinfo] = MAX_INT; /* end flag */ |
341 | luaF_protook(L, f, fs->pc); /* proto is ok now */ | ||
342 | ls->fs = fs->prev; | 342 | ls->fs = fs->prev; |
343 | LUA_ASSERT(fs->bl == NULL, "wrong list end"); | 343 | LUA_ASSERT(fs->bl == NULL, "wrong list end"); |
344 | } | 344 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.h,v 1.23 2000/08/22 17:44:17 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.24 2000/08/30 18:50:18 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 | */ |
@@ -48,7 +48,6 @@ typedef struct FuncState { | |||
48 | int nactloc; /* number of active local variables */ | 48 | int nactloc; /* number of active local variables */ |
49 | int nupvalues; /* number of upvalues */ | 49 | int nupvalues; /* number of upvalues */ |
50 | int lastline; /* line where last `lineinfo' was generated */ | 50 | int lastline; /* line where last `lineinfo' was generated */ |
51 | int nlineinfo; /* index of next `lineinfo' to be generated */ | ||
52 | struct Breaklabel *bl; /* chain of breakable blocks */ | 51 | struct Breaklabel *bl; /* chain of breakable blocks */ |
53 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ | 52 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ |
54 | int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */ | 53 | int actloc[MAXLOCALS]; /* local-variable stack (indices to locvars) */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.40 2000/09/21 14:41:25 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.41 2000/09/25 16:22:42 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 | */ |
@@ -78,7 +78,7 @@ lua_State *lua_open (int stacksize) { | |||
78 | L->refArray = NULL; | 78 | L->refArray = NULL; |
79 | L->refSize = 0; | 79 | L->refSize = 0; |
80 | L->refFree = NONEXT; | 80 | L->refFree = NONEXT; |
81 | L->nblocks = 0; | 81 | L->nblocks = sizeof(lua_State); |
82 | L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ | 82 | L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */ |
83 | L->callhook = NULL; | 83 | L->callhook = NULL; |
84 | L->linehook = NULL; | 84 | L->linehook = NULL; |
@@ -100,11 +100,16 @@ void lua_close (lua_State *L) { | |||
100 | LUA_ASSERT(L->rootcl == NULL, "list should be empty"); | 100 | LUA_ASSERT(L->rootcl == NULL, "list should be empty"); |
101 | LUA_ASSERT(L->roottable == NULL, "list should be empty"); | 101 | LUA_ASSERT(L->roottable == NULL, "list should be empty"); |
102 | luaS_freeall(L); | 102 | luaS_freeall(L); |
103 | if (L->stack) | ||
104 | L->nblocks -= (L->stack_last - L->stack + 1)*sizeof(TObject); | ||
103 | luaM_free(L, L->stack); | 105 | luaM_free(L, L->stack); |
106 | L->nblocks -= (L->last_tag+1)*sizeof(struct IM); | ||
104 | luaM_free(L, L->IMtable); | 107 | luaM_free(L, L->IMtable); |
108 | L->nblocks -= (L->refSize)*sizeof(struct Ref); | ||
105 | luaM_free(L, L->refArray); | 109 | luaM_free(L, L->refArray); |
110 | L->nblocks -= (L->Mbuffsize)*sizeof(char); | ||
106 | luaM_free(L, L->Mbuffer); | 111 | luaM_free(L, L->Mbuffer); |
107 | LUA_ASSERT(L->nblocks == 0, "wrong count for nblocks"); | 112 | LUA_ASSERT(L->nblocks == sizeof(lua_State), "wrong count for nblocks"); |
108 | luaM_free(L, L); | 113 | luaM_free(L, L); |
109 | LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); | 114 | LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); |
110 | LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); | 115 | LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 1.38 2000/09/11 17:38:42 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 1.39 2000/09/25 16:22:42 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 | */ |
@@ -65,7 +65,7 @@ struct lua_State { | |||
65 | int refSize; /* size of refArray */ | 65 | int refSize; /* size of refArray */ |
66 | int refFree; /* list of free positions in refArray */ | 66 | int refFree; /* list of free positions in refArray */ |
67 | unsigned long GCthreshold; | 67 | unsigned long GCthreshold; |
68 | unsigned long nblocks; /* number of `blocks' currently allocated */ | 68 | unsigned long nblocks; /* number of `bytes' currently allocated */ |
69 | lua_Hook callhook; | 69 | lua_Hook callhook; |
70 | lua_Hook linehook; | 70 | lua_Hook linehook; |
71 | int allowhooks; | 71 | int allowhooks; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.41 2000/08/04 19:38:35 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.42 2000/08/09 19:16:57 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,6 +19,7 @@ | |||
19 | void luaS_init (lua_State *L) { | 19 | void luaS_init (lua_State *L) { |
20 | L->strt.hash = luaM_newvector(L, 1, TString *); | 20 | L->strt.hash = luaM_newvector(L, 1, TString *); |
21 | L->udt.hash = luaM_newvector(L, 1, TString *); | 21 | L->udt.hash = luaM_newvector(L, 1, TString *); |
22 | L->nblocks += 2*sizeof(TString *); | ||
22 | L->strt.size = L->udt.size = 1; | 23 | L->strt.size = L->udt.size = 1; |
23 | L->strt.nuse = L->udt.nuse = 0; | 24 | L->strt.nuse = L->udt.nuse = 0; |
24 | L->strt.hash[0] = L->udt.hash[0] = NULL; | 25 | L->strt.hash[0] = L->udt.hash[0] = NULL; |
@@ -27,6 +28,7 @@ void luaS_init (lua_State *L) { | |||
27 | 28 | ||
28 | void luaS_freeall (lua_State *L) { | 29 | void luaS_freeall (lua_State *L) { |
29 | LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); | 30 | LUA_ASSERT(L->strt.nuse==0, "non-empty string table"); |
31 | L->nblocks -= (L->strt.size + L->udt.size)*sizeof(TString *); | ||
30 | luaM_free(L, L->strt.hash); | 32 | luaM_free(L, L->strt.hash); |
31 | LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); | 33 | LUA_ASSERT(L->udt.nuse==0, "non-empty udata table"); |
32 | luaM_free(L, L->udt.hash); | 34 | luaM_free(L, L->udt.hash); |
@@ -61,6 +63,7 @@ void luaS_resize (lua_State *L, stringtable *tb, int newsize) { | |||
61 | } | 63 | } |
62 | } | 64 | } |
63 | luaM_free(L, tb->hash); | 65 | luaM_free(L, tb->hash); |
66 | L->nblocks += (newsize - tb->size)*sizeof(TString *); | ||
64 | tb->size = newsize; | 67 | tb->size = newsize; |
65 | tb->hash = newhash; | 68 | tb->hash = newhash; |
66 | } | 69 | } |
@@ -85,7 +88,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
85 | return ts; | 88 | return ts; |
86 | } | 89 | } |
87 | /* not found */ | 90 | /* not found */ |
88 | ts = (TString *)luaM_malloc(L, sizeof(TString)+(lint32)l*sizeof(char)); | 91 | ts = (TString *)luaM_malloc(L, sizestring(l)); |
89 | ts->marked = 0; | 92 | ts->marked = 0; |
90 | ts->nexthash = NULL; | 93 | ts->nexthash = NULL; |
91 | ts->u.s.len = l; | 94 | ts->u.s.len = l; |
@@ -93,7 +96,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
93 | ts->u.s.constindex = 0; | 96 | ts->u.s.constindex = 0; |
94 | memcpy(ts->str, str, l); | 97 | memcpy(ts->str, str, l); |
95 | ts->str[l] = 0; /* ending 0 */ | 98 | ts->str[l] = 0; /* ending 0 */ |
96 | L->nblocks += gcsizestring(L, l); | 99 | L->nblocks += sizestring(l); |
97 | newentry(L, &L->strt, ts, h1); /* insert it on table */ | 100 | newentry(L, &L->strt, ts, h1); /* insert it on table */ |
98 | return ts; | 101 | return ts; |
99 | } | 102 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.20 2000/05/10 16:33:20 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.21 2000/05/24 13:54:49 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -20,8 +20,8 @@ | |||
20 | #define RESERVEDMARK 3 | 20 | #define RESERVEDMARK 3 |
21 | 21 | ||
22 | 22 | ||
23 | #define gcsizestring(L, l) numblocks(L, 0, sizeof(TString)+l) | 23 | #define sizestring(l) (sizeof(TString)+(lint32)(l)*sizeof(char)) |
24 | #define gcsizeudata gcsizestring(L, 0) | 24 | #define gcsizeudata (sizeof(TString)) |
25 | 25 | ||
26 | 26 | ||
27 | void luaS_init (lua_State *L); | 27 | void luaS_init (lua_State *L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.54 2000/08/31 14:08:27 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.55 2000/09/11 20:29:27 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 | */ |
@@ -27,7 +27,7 @@ | |||
27 | #include "ltable.h" | 27 | #include "ltable.h" |
28 | 28 | ||
29 | 29 | ||
30 | #define gcsize(L, n) numblocks(L, n*2, sizeof(Hash)) | 30 | #define gcsize(L, n) (sizeof(Hash)+(n)*sizeof(Node)) |
31 | 31 | ||
32 | 32 | ||
33 | 33 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.43 2000/09/25 14:48:42 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.44 2000/09/25 16:22:42 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 | */ |
@@ -166,7 +166,8 @@ static int mem_query (lua_State *L) { | |||
166 | lua_pushnumber(L, memdebug_total); | 166 | lua_pushnumber(L, memdebug_total); |
167 | lua_pushnumber(L, memdebug_numblocks); | 167 | lua_pushnumber(L, memdebug_numblocks); |
168 | lua_pushnumber(L, memdebug_maxmem); | 168 | lua_pushnumber(L, memdebug_maxmem); |
169 | return 3; | 169 | lua_pushnumber(L, L->nblocks); |
170 | return 4; | ||
170 | } | 171 | } |
171 | else { | 172 | else { |
172 | memdebug_memlimit = luaL_check_int(L, 1); | 173 | memdebug_memlimit = luaL_check_int(L, 1); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 1.48 2000/09/11 19:45:27 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.49 2000/09/11 20:29:27 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 | */ |
@@ -77,6 +77,7 @@ static void init_entry (lua_State *L, int tag) { | |||
77 | void luaT_init (lua_State *L) { | 77 | void luaT_init (lua_State *L) { |
78 | int t; | 78 | int t; |
79 | luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, "", MAX_INT); | 79 | luaM_growvector(L, L->IMtable, 0, NUM_TAGS, struct IM, "", MAX_INT); |
80 | L->nblocks += NUM_TAGS*sizeof(struct IM); | ||
80 | L->last_tag = NUM_TAGS-1; | 81 | L->last_tag = NUM_TAGS-1; |
81 | for (t=0; t<=L->last_tag; t++) | 82 | for (t=0; t<=L->last_tag; t++) |
82 | init_entry(L, t); | 83 | init_entry(L, t); |
@@ -86,6 +87,7 @@ void luaT_init (lua_State *L) { | |||
86 | int lua_newtag (lua_State *L) { | 87 | int lua_newtag (lua_State *L) { |
87 | luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM, | 88 | luaM_growvector(L, L->IMtable, L->last_tag, 1, struct IM, |
88 | "tag table overflow", MAX_INT); | 89 | "tag table overflow", MAX_INT); |
90 | L->nblocks += sizeof(struct IM); | ||
89 | L->last_tag++; | 91 | L->last_tag++; |
90 | init_entry(L, L->last_tag); | 92 | init_entry(L, L->last_tag); |
91 | return L->last_tag; | 93 | return L->last_tag; |