diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-25 12:16:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-02-25 12:16:26 -0300 |
commit | 26d1e21c89a481c2368ba934da8e192a164d8f99 (patch) | |
tree | ea2eaaade79264b71d0e18fef75bca70fc1f4766 /lparser.c | |
parent | 24a2c08145ecc9b5c528a46ba83bdd7b95dbdc02 (diff) | |
download | lua-26d1e21c89a481c2368ba934da8e192a164d8f99.tar.gz lua-26d1e21c89a481c2368ba934da8e192a164d8f99.tar.bz2 lua-26d1e21c89a481c2368ba934da8e192a164d8f99.zip |
new way to handle "growing" vectors
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 31 |
1 files changed, 9 insertions, 22 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.21 1999/02/24 15:37:19 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.22 1999/02/24 17:55:51 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 | */ |
@@ -89,10 +89,7 @@ typedef struct FuncState { | |||
89 | int maxstacksize; /* maximum number of values on activation register */ | 89 | int maxstacksize; /* maximum number of values on activation register */ |
90 | int nlocalvar; /* number of active local variables */ | 90 | int nlocalvar; /* number of active local variables */ |
91 | int nupvalues; /* number of upvalues */ | 91 | int nupvalues; /* number of upvalues */ |
92 | int nvars; /* number of entries in f->locvars */ | 92 | int nvars; /* number of entries in f->locvars (-1 if no debug information) */ |
93 | int maxcode; /* size of f->code */ | ||
94 | int maxvars; /* size of f->locvars (-1 if no debug information) */ | ||
95 | int maxconsts; /* size of f->consts */ | ||
96 | int lastsetline; /* line where last SETLINE was issued */ | 93 | int lastsetline; /* line where last SETLINE was issued */ |
97 | vardesc upvalues[MAXUPVALUES]; /* upvalues */ | 94 | vardesc upvalues[MAXUPVALUES]; /* upvalues */ |
98 | TaggedString *localvar[MAXLOCALS]; /* store local variable names */ | 95 | TaggedString *localvar[MAXLOCALS]; /* store local variable names */ |
@@ -134,9 +131,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v); | |||
134 | 131 | ||
135 | 132 | ||
136 | static void check_pc (FuncState *fs, int n) { | 133 | static void check_pc (FuncState *fs, int n) { |
137 | if (fs->pc+n > fs->maxcode) | 134 | fs->f->code = luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT); |
138 | fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode+n, | ||
139 | Byte, codeEM, MAX_INT); | ||
140 | } | 135 | } |
141 | 136 | ||
142 | 137 | ||
@@ -221,9 +216,8 @@ static void code_constant (LexState *ls, int c) { | |||
221 | 216 | ||
222 | static int next_constant (FuncState *fs) { | 217 | static int next_constant (FuncState *fs) { |
223 | TProtoFunc *f = fs->f; | 218 | TProtoFunc *f = fs->f; |
224 | if (f->nconsts >= fs->maxconsts) | 219 | f->consts = luaM_growvector(f->consts, f->nconsts, 1, TObject, |
225 | fs->maxconsts = luaM_growvector(&f->consts, fs->maxconsts, TObject, | 220 | constantEM, MAX_ARG); |
226 | constantEM, MAX_ARG); | ||
227 | return f->nconsts++; | 221 | return f->nconsts++; |
228 | } | 222 | } |
229 | 223 | ||
@@ -293,11 +287,9 @@ static void flush_list (LexState *ls, int m, int n) { | |||
293 | 287 | ||
294 | static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, | 288 | static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, |
295 | int line) { | 289 | int line) { |
296 | if (fs->maxvars != -1) { /* debug information? */ | 290 | if (fs->nvars != -1) { /* debug information? */ |
297 | TProtoFunc *f = fs->f; | 291 | TProtoFunc *f = fs->f; |
298 | if (fs->nvars >= fs->maxvars) | 292 | f->locvars = luaM_growvector(f->locvars, fs->nvars, 1, LocVar, "", MAX_INT); |
299 | fs->maxvars = luaM_growvector(&f->locvars, fs->maxvars, | ||
300 | LocVar, "", MAX_INT); | ||
301 | f->locvars[fs->nvars].varname = varname; | 293 | f->locvars[fs->nvars].varname = varname; |
302 | f->locvars[fs->nvars].line = line; | 294 | f->locvars[fs->nvars].line = line; |
303 | fs->nvars++; | 295 | fs->nvars++; |
@@ -555,13 +547,8 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) { | |||
555 | fs->f = f; | 547 | fs->f = f; |
556 | f->fileName = filename; | 548 | f->fileName = filename; |
557 | fs->pc = 0; | 549 | fs->pc = 0; |
558 | fs->maxcode = 0; | ||
559 | f->code = NULL; | 550 | f->code = NULL; |
560 | fs->maxconsts = 0; | 551 | fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */ |
561 | if (L->debug) | ||
562 | fs->nvars = fs->maxvars = 0; | ||
563 | else | ||
564 | fs->maxvars = -1; /* flag no debug information */ | ||
565 | code_byte(fs, 0); /* to be filled with maxstacksize */ | 552 | code_byte(fs, 0); /* to be filled with maxstacksize */ |
566 | code_byte(fs, 0); /* to be filled with arg information */ | 553 | code_byte(fs, 0); /* to be filled with arg information */ |
567 | /* push function (to avoid GC) */ | 554 | /* push function (to avoid GC) */ |
@@ -577,7 +564,7 @@ static void close_func (LexState *ls) { | |||
577 | f->code[0] = (Byte)fs->maxstacksize; | 564 | f->code[0] = (Byte)fs->maxstacksize; |
578 | f->code = luaM_reallocvector(f->code, fs->pc, Byte); | 565 | f->code = luaM_reallocvector(f->code, fs->pc, Byte); |
579 | f->consts = luaM_reallocvector(f->consts, f->nconsts, TObject); | 566 | f->consts = luaM_reallocvector(f->consts, f->nconsts, TObject); |
580 | if (fs->maxvars != -1) { /* debug information? */ | 567 | if (fs->nvars != -1) { /* debug information? */ |
581 | luaI_registerlocalvar(fs, NULL, -1); /* flag end of vector */ | 568 | luaI_registerlocalvar(fs, NULL, -1); /* flag end of vector */ |
582 | f->locvars = luaM_reallocvector(f->locvars, fs->nvars, LocVar); | 569 | f->locvars = luaM_reallocvector(f->locvars, fs->nvars, LocVar); |
583 | } | 570 | } |