diff options
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 55 |
1 files changed, 30 insertions, 25 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.119 2000/12/04 18:33:40 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.120 2000/12/26 18:46:09 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 | */ |
| @@ -120,10 +120,10 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
| 120 | static int string_constant (FuncState *fs, TString *s) { | 120 | static int string_constant (FuncState *fs, TString *s) { |
| 121 | Proto *f = fs->f; | 121 | Proto *f = fs->f; |
| 122 | int c = s->u.s.constindex; | 122 | int c = s->u.s.constindex; |
| 123 | if (c >= f->nkstr || f->kstr[c] != s) { | 123 | if (c >= fs->nkstr || f->kstr[c] != s) { |
| 124 | luaM_growvector(fs->L, f->kstr, f->nkstr, fs->sizekstr, TString *, | 124 | luaM_growvector(fs->L, f->kstr, fs->nkstr, f->sizekstr, TString *, |
| 125 | MAXARG_U, "constant table overflow"); | 125 | MAXARG_U, "constant table overflow"); |
| 126 | c = f->nkstr++; | 126 | c = fs->nkstr++; |
| 127 | f->kstr[c] = s; | 127 | f->kstr[c] = s; |
| 128 | s->u.s.constindex = c; /* hint for next time */ | 128 | s->u.s.constindex = c; /* hint for next time */ |
| 129 | } | 129 | } |
| @@ -151,11 +151,12 @@ static int checkname (LexState *ls) { | |||
| 151 | 151 | ||
| 152 | 152 | ||
| 153 | static int luaI_registerlocalvar (LexState *ls, TString *varname) { | 153 | static int luaI_registerlocalvar (LexState *ls, TString *varname) { |
| 154 | Proto *f = ls->fs->f; | 154 | FuncState *fs = ls->fs; |
| 155 | luaM_growvector(ls->L, f->locvars, f->nlocvars, ls->fs->sizelocvars, | 155 | Proto *f = fs->f; |
| 156 | luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars, | ||
| 156 | LocVar, MAX_INT, ""); | 157 | LocVar, MAX_INT, ""); |
| 157 | f->locvars[f->nlocvars].varname = varname; | 158 | f->locvars[fs->nlocvars].varname = varname; |
| 158 | return f->nlocvars++; | 159 | return fs->nlocvars++; |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | 162 | ||
| @@ -295,10 +296,10 @@ static void pushclosure (LexState *ls, FuncState *func) { | |||
| 295 | int i; | 296 | int i; |
| 296 | for (i=0; i<func->nupvalues; i++) | 297 | for (i=0; i<func->nupvalues; i++) |
| 297 | luaK_tostack(ls, &func->upvalues[i], 1); | 298 | luaK_tostack(ls, &func->upvalues[i], 1); |
| 298 | luaM_growvector(ls->L, f->kproto, f->nkproto, fs->sizekproto, Proto *, | 299 | luaM_growvector(ls->L, f->kproto, fs->nkproto, f->sizekproto, Proto *, |
| 299 | MAXARG_A, "constant table overflow"); | 300 | MAXARG_A, "constant table overflow"); |
| 300 | f->kproto[f->nkproto++] = func->f; | 301 | f->kproto[fs->nkproto++] = func->f; |
| 301 | luaK_code2(fs, OP_CLOSURE, f->nkproto-1, func->nupvalues); | 302 | luaK_code2(fs, OP_CLOSURE, fs->nkproto-1, func->nupvalues); |
| 302 | } | 303 | } |
| 303 | 304 | ||
| 304 | 305 | ||
| @@ -313,12 +314,11 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
| 313 | fs->lasttarget = 0; | 314 | fs->lasttarget = 0; |
| 314 | fs->jlt = NO_JUMP; | 315 | fs->jlt = NO_JUMP; |
| 315 | fs->stacklevel = 0; | 316 | fs->stacklevel = 0; |
| 316 | fs->sizekstr = 0; | 317 | fs->nkstr = 0; |
| 317 | fs->sizekproto = 0; | 318 | fs->nkproto = 0; |
| 318 | fs->sizeknum = 0; | 319 | fs->nknum = 0; |
| 319 | fs->sizelineinfo = 0; | 320 | fs->nlineinfo = 0; |
| 320 | fs->sizecode = 0; | 321 | fs->nlocvars = 0; |
| 321 | fs->sizelocvars = 0; | ||
| 322 | fs->nactloc = 0; | 322 | fs->nactloc = 0; |
| 323 | fs->nupvalues = 0; | 323 | fs->nupvalues = 0; |
| 324 | fs->lastline = 0; | 324 | fs->lastline = 0; |
| @@ -337,15 +337,20 @@ static void close_func (LexState *ls) { | |||
| 337 | Proto *f = fs->f; | 337 | Proto *f = fs->f; |
| 338 | luaK_code0(fs, OP_END); | 338 | luaK_code0(fs, OP_END); |
| 339 | luaK_getlabel(fs); /* close eventual list of pending jumps */ | 339 | luaK_getlabel(fs); /* close eventual list of pending jumps */ |
| 340 | luaM_reallocvector(L, f->code, fs->pc, Instruction); | ||
| 341 | luaM_reallocvector(L, f->kstr, f->nkstr, TString *); | ||
| 342 | luaM_reallocvector(L, f->knum, f->nknum, lua_Number); | ||
| 343 | luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); | ||
| 344 | removelocalvars(ls, fs->nactloc); | 340 | removelocalvars(ls, fs->nactloc); |
| 345 | luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar); | 341 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); |
| 346 | luaM_reallocvector(L, f->lineinfo, f->nlineinfo+1, int); | 342 | f->sizecode = fs->pc; |
| 347 | f->lineinfo[f->nlineinfo++] = MAX_INT; /* end flag */ | 343 | luaM_reallocvector(L, f->kstr, f->sizekstr, fs->nkstr, TString *); |
| 348 | luaF_protook(L, f, fs->pc); /* proto is ok now */ | 344 | f->sizekstr = fs->nkstr; |
| 345 | luaM_reallocvector(L, f->knum, f->sizeknum, fs->nknum, lua_Number); | ||
| 346 | f->sizeknum = fs->nknum; | ||
| 347 | luaM_reallocvector(L, f->kproto, f->sizekproto, fs->nkproto, Proto *); | ||
| 348 | f->sizekproto = fs->nkproto; | ||
| 349 | luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); | ||
| 350 | f->sizelocvars = fs->nlocvars; | ||
| 351 | luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->nlineinfo+1, int); | ||
| 352 | f->lineinfo[fs->nlineinfo++] = MAX_INT; /* end flag */ | ||
| 353 | f->sizelineinfo = fs->nlineinfo; | ||
| 349 | ls->fs = fs->prev; | 354 | ls->fs = fs->prev; |
| 350 | LUA_ASSERT(fs->bl == NULL, "wrong list end"); | 355 | LUA_ASSERT(fs->bl == NULL, "wrong list end"); |
| 351 | } | 356 | } |
