diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-25 14:47:14 -0300 |
commit | 801aaf37b14a1fad5bb49c9a4200d25680152471 (patch) | |
tree | e3cc5cdebac6d503091f4ba16444f8ecfa8dfdb2 /lparser.c | |
parent | 00af2faae71e6388ee61ef18b2c5902a42e9bc27 (diff) | |
download | lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.gz lua-801aaf37b14a1fad5bb49c9a4200d25680152471.tar.bz2 lua-801aaf37b14a1fad5bb49c9a4200d25680152471.zip |
simpler implementation for line information
Diffstat (limited to 'lparser.c')
-rw-r--r-- | lparser.c | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.171 2002/03/18 14:49:46 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.172 2002/03/21 20:32:22 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -376,11 +376,9 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
376 | fs->nk = 0; | 376 | fs->nk = 0; |
377 | fs->h = luaH_new(ls->L, 0, 0); | 377 | fs->h = luaH_new(ls->L, 0, 0); |
378 | fs->np = 0; | 378 | fs->np = 0; |
379 | fs->nlineinfo = 0; | ||
380 | fs->nlocvars = 0; | 379 | fs->nlocvars = 0; |
381 | fs->nactloc = 0; | 380 | fs->nactloc = 0; |
382 | fs->nactvar = 0; | 381 | fs->nactvar = 0; |
383 | fs->lastline = 0; | ||
384 | fs->defaultglob = NO_REG; /* default is free globals */ | 382 | fs->defaultglob = NO_REG; /* default is free globals */ |
385 | fs->bl = NULL; | 383 | fs->bl = NULL; |
386 | f->code = NULL; | 384 | f->code = NULL; |
@@ -402,6 +400,7 @@ static void close_func (LexState *ls) { | |||
402 | G(L)->roottable = fs->h->next; | 400 | G(L)->roottable = fs->h->next; |
403 | luaH_free(L, fs->h); | 401 | luaH_free(L, fs->h); |
404 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); | 402 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); |
403 | luaM_reallocvector(L, f->lineinfo, f->sizecode, fs->pc, int); | ||
405 | f->sizecode = fs->pc; | 404 | f->sizecode = fs->pc; |
406 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); | 405 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject); |
407 | f->sizek = fs->nk; | 406 | f->sizek = fs->nk; |
@@ -409,9 +408,6 @@ static void close_func (LexState *ls) { | |||
409 | f->sizep = fs->np; | 408 | f->sizep = fs->np; |
410 | luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); | 409 | luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); |
411 | f->sizelocvars = fs->nlocvars; | 410 | f->sizelocvars = fs->nlocvars; |
412 | luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->nlineinfo+1, int); | ||
413 | f->lineinfo[fs->nlineinfo++] = MAX_INT; /* end flag */ | ||
414 | f->sizelineinfo = fs->nlineinfo; | ||
415 | lua_assert(luaG_checkcode(f)); | 411 | lua_assert(luaG_checkcode(f)); |
416 | lua_assert(fs->bl == NULL); | 412 | lua_assert(fs->bl == NULL); |
417 | ls->fs = fs->prev; | 413 | ls->fs = fs->prev; |
@@ -999,10 +995,10 @@ static int exp1 (LexState *ls) { | |||
999 | } | 995 | } |
1000 | 996 | ||
1001 | 997 | ||
1002 | static void fornum (LexState *ls, TString *varname) { | 998 | static void fornum (LexState *ls, TString *varname, int line) { |
1003 | /* fornum -> NAME = exp1,exp1[,exp1] DO body */ | 999 | /* fornum -> NAME = exp1,exp1[,exp1] DO body */ |
1004 | FuncState *fs = ls->fs; | 1000 | FuncState *fs = ls->fs; |
1005 | int prep; | 1001 | int prep, endfor; |
1006 | int base = fs->freereg; | 1002 | int base = fs->freereg; |
1007 | new_localvar(ls, varname, 0); | 1003 | new_localvar(ls, varname, 0); |
1008 | new_localvarstr(ls, "(for limit)", 1); | 1004 | new_localvarstr(ls, "(for limit)", 1); |
@@ -1024,7 +1020,9 @@ static void fornum (LexState *ls, TString *varname) { | |||
1024 | check(ls, TK_DO); | 1020 | check(ls, TK_DO); |
1025 | block(ls); | 1021 | block(ls); |
1026 | luaK_patchtohere(fs, prep-1); | 1022 | luaK_patchtohere(fs, prep-1); |
1027 | luaK_patchlist(fs, luaK_codeAsBc(fs, OP_FORLOOP, base, NO_JUMP), prep); | 1023 | endfor = luaK_codeAsBc(fs, OP_FORLOOP, base, NO_JUMP); |
1024 | luaK_patchlist(fs, endfor, prep); | ||
1025 | fs->f->lineinfo[endfor] = line; /* pretend that `OP_FOR' starts the loop */ | ||
1028 | } | 1026 | } |
1029 | 1027 | ||
1030 | 1028 | ||
@@ -1065,7 +1063,7 @@ static void forstat (LexState *ls, int line) { | |||
1065 | varname = str_checkname(ls); /* first variable name */ | 1063 | varname = str_checkname(ls); /* first variable name */ |
1066 | next(ls); /* skip var name */ | 1064 | next(ls); /* skip var name */ |
1067 | switch (ls->t.token) { | 1065 | switch (ls->t.token) { |
1068 | case '=': fornum(ls, varname); break; | 1066 | case '=': fornum(ls, varname, line); break; |
1069 | case ',': case TK_IN: forlist(ls, varname); break; | 1067 | case ',': case TK_IN: forlist(ls, varname); break; |
1070 | default: luaK_error(ls, "`=' or `in' expected"); | 1068 | default: luaK_error(ls, "`=' or `in' expected"); |
1071 | } | 1069 | } |