diff options
Diffstat (limited to '')
| -rw-r--r-- | lparser.c | 28 | ||||
| -rw-r--r-- | lparser.h | 4 |
2 files changed, 14 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.89 2000/05/24 13:54:49 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.90 2000/05/24 18:04:17 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 | */ |
| @@ -183,10 +183,11 @@ static TString *optionalname (LexState *ls) { | |||
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | 185 | ||
| 186 | static void luaI_registerlocalvar (LexState *ls, TString *varname, | 186 | static void luaI_registerlocalvar (LexState *ls, TString *varname, int line) { |
| 187 | int line) { | ||
| 188 | FuncState *fs = ls->fs; | 187 | FuncState *fs = ls->fs; |
| 189 | if (fs->nvars != -1) { /* debug information? */ | 188 | /* start debug only when there are no active local variables, |
| 189 | but keep going after starting */ | ||
| 190 | if ((ls->L->debug && fs->nlocalvar == 0) || fs->nvars != 0) { | ||
| 190 | Proto *f = fs->f; | 191 | Proto *f = fs->f; |
| 191 | luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT); | 192 | luaM_growvector(ls->L, f->locvars, fs->nvars, 1, LocVar, "", MAX_INT); |
| 192 | f->locvars[fs->nvars].varname = varname; | 193 | f->locvars[fs->nvars].varname = varname; |
| @@ -196,11 +197,6 @@ static void luaI_registerlocalvar (LexState *ls, TString *varname, | |||
| 196 | } | 197 | } |
| 197 | 198 | ||
| 198 | 199 | ||
| 199 | static void luaI_unregisterlocalvar (LexState *ls, int line) { | ||
| 200 | luaI_registerlocalvar(ls, NULL, line); | ||
| 201 | } | ||
| 202 | |||
| 203 | |||
| 204 | static void store_localvar (LexState *ls, TString *name, int n) { | 200 | static void store_localvar (LexState *ls, TString *name, int n) { |
| 205 | FuncState *fs = ls->fs; | 201 | FuncState *fs = ls->fs; |
| 206 | luaX_checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); | 202 | luaX_checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); |
| @@ -212,17 +208,18 @@ static void adjustlocalvars (LexState *ls, int nvars) { | |||
| 212 | int line = ls->fs->lastsetline; | 208 | int line = ls->fs->lastsetline; |
| 213 | FuncState *fs = ls->fs; | 209 | FuncState *fs = ls->fs; |
| 214 | int i; | 210 | int i; |
| 215 | fs->nlocalvar += nvars; | 211 | for (i=fs->nlocalvar; i<fs->nlocalvar+nvars; i++) |
| 216 | for (i=fs->nlocalvar-nvars; i<fs->nlocalvar; i++) | ||
| 217 | luaI_registerlocalvar(ls, fs->localvar[i], line); | 212 | luaI_registerlocalvar(ls, fs->localvar[i], line); |
| 213 | fs->nlocalvar += nvars; | ||
| 218 | } | 214 | } |
| 219 | 215 | ||
| 220 | 216 | ||
| 221 | static void removelocalvars (LexState *ls, int nvars) { | 217 | static void removelocalvars (LexState *ls, int nvars) { |
| 222 | int line = ls->fs->lastsetline; | 218 | int line = ls->fs->lastsetline; |
| 219 | int i; | ||
| 220 | for (i=0;i<nvars;i++) | ||
| 221 | luaI_registerlocalvar(ls, NULL, line); | ||
| 223 | ls->fs->nlocalvar -= nvars; | 222 | ls->fs->nlocalvar -= nvars; |
| 224 | while (nvars--) | ||
| 225 | luaI_unregisterlocalvar(ls, line); | ||
| 226 | } | 223 | } |
| 227 | 224 | ||
| 228 | 225 | ||
| @@ -367,7 +364,6 @@ static void func_onstack (LexState *ls, FuncState *func) { | |||
| 367 | 364 | ||
| 368 | 365 | ||
| 369 | static void init_state (LexState *ls, FuncState *fs, TString *source) { | 366 | static void init_state (LexState *ls, FuncState *fs, TString *source) { |
| 370 | lua_State *L = ls->L; | ||
| 371 | Proto *f = luaF_newproto(ls->L); | 367 | Proto *f = luaF_newproto(ls->L); |
| 372 | fs->prev = ls->fs; /* linked list of funcstates */ | 368 | fs->prev = ls->fs; /* linked list of funcstates */ |
| 373 | fs->ls = ls; | 369 | fs->ls = ls; |
| @@ -387,7 +383,7 @@ static void init_state (LexState *ls, FuncState *fs, TString *source) { | |||
| 387 | f->maxstacksize = 0; | 383 | f->maxstacksize = 0; |
| 388 | f->numparams = 0; /* default for main chunk */ | 384 | f->numparams = 0; /* default for main chunk */ |
| 389 | f->is_vararg = 0; /* default for main chunk */ | 385 | f->is_vararg = 0; /* default for main chunk */ |
| 390 | fs->nvars = (L->debug) ? 0 : -1; /* flag no debug information? */ | 386 | fs->nvars = 0; |
| 391 | } | 387 | } |
| 392 | 388 | ||
| 393 | 389 | ||
| @@ -401,7 +397,7 @@ static void close_func (LexState *ls) { | |||
| 401 | luaM_reallocvector(L, f->kstr, f->nkstr, TString *); | 397 | luaM_reallocvector(L, f->kstr, f->nkstr, TString *); |
| 402 | luaM_reallocvector(L, f->knum, f->nknum, Number); | 398 | luaM_reallocvector(L, f->knum, f->nknum, Number); |
| 403 | luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); | 399 | luaM_reallocvector(L, f->kproto, f->nkproto, Proto *); |
| 404 | if (fs->nvars != -1) { /* debug information? */ | 400 | if (f->locvars) { /* debug information? */ |
| 405 | luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ | 401 | luaI_registerlocalvar(ls, NULL, -1); /* flag end of vector */ |
| 406 | luaM_reallocvector(L, f->locvars, fs->nvars, LocVar); | 402 | luaM_reallocvector(L, f->locvars, fs->nvars, LocVar); |
| 407 | } | 403 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.h,v 1.15 2000/04/05 17:51:58 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.16 2000/04/06 17:36:52 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 | */ |
| @@ -47,7 +47,7 @@ typedef struct FuncState { | |||
| 47 | int stacklevel; /* number of values on activation register */ | 47 | int stacklevel; /* number of values on activation register */ |
| 48 | int nlocalvar; /* number of active local variables */ | 48 | int nlocalvar; /* number of active local variables */ |
| 49 | int nupvalues; /* number of upvalues */ | 49 | int nupvalues; /* number of upvalues */ |
| 50 | int nvars; /* number of entries in f->locvars (-1 if no debug information) */ | 50 | int nvars; /* number of entries in f->locvars */ |
| 51 | int lastsetline; /* line where last SETLINE was issued */ | 51 | int lastsetline; /* line where last SETLINE was issued */ |
| 52 | struct Breaklabel *bl; /* chain of breakable blocks */ | 52 | struct Breaklabel *bl; /* chain of breakable blocks */ |
| 53 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ | 53 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ |
