diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-14 14:52:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-05-14 14:52:22 -0300 |
| commit | 1c328a191a8b86b7ad601cb9a935f1da5373fdf7 (patch) | |
| tree | 4ea6d9b0fc271ae38579b9fc6767d1c64f6bdd21 | |
| parent | 58bf77bc7f37d697c5bfc33be169c6b841dd8a1d (diff) | |
| download | lua-1c328a191a8b86b7ad601cb9a935f1da5373fdf7.tar.gz lua-1c328a191a8b86b7ad601cb9a935f1da5373fdf7.tar.bz2 lua-1c328a191a8b86b7ad601cb9a935f1da5373fdf7.zip | |
no more `global' declarations
| -rw-r--r-- | lcode.c | 6 | ||||
| -rw-r--r-- | ldebug.c | 7 | ||||
| -rw-r--r-- | lparser.c | 180 | ||||
| -rw-r--r-- | lparser.h | 21 |
4 files changed, 53 insertions, 161 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 1.102 2002/05/10 19:22:11 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 1.103 2002/05/13 13:07:48 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 | */ |
| @@ -191,7 +191,7 @@ void luaK_reserveregs (FuncState *fs, int n) { | |||
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | static void freereg (FuncState *fs, int reg) { | 193 | static void freereg (FuncState *fs, int reg) { |
| 194 | if (reg >= fs->nactloc && reg < MAXSTACK) { | 194 | if (reg >= fs->nactvar && reg < MAXSTACK) { |
| 195 | fs->freereg--; | 195 | fs->freereg--; |
| 196 | lua_assert(reg == fs->freereg); | 196 | lua_assert(reg == fs->freereg); |
| 197 | } | 197 | } |
| @@ -375,7 +375,7 @@ int luaK_exp2anyreg (FuncState *fs, expdesc *e) { | |||
| 375 | luaK_dischargevars(fs, e); | 375 | luaK_dischargevars(fs, e); |
| 376 | if (e->k == VNONRELOC) { | 376 | if (e->k == VNONRELOC) { |
| 377 | if (!hasjumps(e)) return e->info; /* exp is already in a register */ | 377 | if (!hasjumps(e)) return e->info; /* exp is already in a register */ |
| 378 | if (e->info >= fs->nactloc) { /* reg. is not a local? */ | 378 | if (e->info >= fs->nactvar) { /* reg. is not a local? */ |
| 379 | luaK_exp2reg(fs, e, e->info); /* put value on it */ | 379 | luaK_exp2reg(fs, e, e->info); /* put value on it */ |
| 380 | return e->info; | 380 | return e->info; |
| 381 | } | 381 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.113 2002/05/09 14:14:34 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.114 2002/05/13 13:09:00 roberto Exp roberto $ |
| 3 | ** Debug Interface | 3 | ** Debug Interface |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -432,11 +432,6 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, | |||
| 432 | break; | 432 | break; |
| 433 | } | 433 | } |
| 434 | case OP_GETTABLE: { | 434 | case OP_GETTABLE: { |
| 435 | *name = luaF_getlocalname(p, GETARG_B(i)+1, pc); | ||
| 436 | if (*name && *name[0] == '*') { | ||
| 437 | *name = kname(p, GETARG_C(i)); | ||
| 438 | return "global"; | ||
| 439 | } | ||
| 440 | *name = kname(p, GETARG_C(i)); | 435 | *name = kname(p, GETARG_C(i)); |
| 441 | return "field"; | 436 | return "field"; |
| 442 | break; | 437 | break; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.181 2002/05/10 19:22:11 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.182 2002/05/13 13:09:00 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 | */ |
| @@ -23,15 +23,18 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | |||
| 27 | #define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) | ||
| 28 | |||
| 29 | |||
| 30 | |||
| 26 | /* | 31 | /* |
| 27 | ** nodes for block list (list of active blocks) | 32 | ** nodes for block list (list of active blocks) |
| 28 | */ | 33 | */ |
| 29 | typedef struct BlockCnt { | 34 | typedef struct BlockCnt { |
| 30 | struct BlockCnt *previous; /* chain */ | 35 | struct BlockCnt *previous; /* chain */ |
| 31 | int breaklist; /* list of jumps out of this loop */ | 36 | int breaklist; /* list of jumps out of this loop */ |
| 32 | int nactloc; /* # active local variables outside the breakable structure */ | 37 | int nactvar; /* # active local variables outside the breakable structure */ |
| 33 | int nactvar; | ||
| 34 | int defaultglob; | ||
| 35 | int upval; /* true if some variable in the block is an upvalue */ | 38 | int upval; /* true if some variable in the block is an upvalue */ |
| 36 | int isbreakable; /* true if `block' is a loop */ | 39 | int isbreakable; /* true if `block' is a loop */ |
| 37 | } BlockCnt; | 40 | } BlockCnt; |
| @@ -138,51 +141,26 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | 143 | ||
| 141 | static vardesc *new_var (LexState *ls, int n) { | ||
| 142 | FuncState *fs = ls->fs; | ||
| 143 | luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "variables"); | ||
| 144 | return &fs->actvar[fs->nactvar+n]; | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | static void new_localvar (LexState *ls, TString *name, int n) { | 144 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 149 | vardesc *v = new_var(ls, n); | ||
| 150 | v->k = VLOCAL; | ||
| 151 | v->i = luaI_registerlocalvar(ls, name); | ||
| 152 | v->level = ls->fs->nactloc + n; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | static void adjustlocalvars (LexState *ls, int nvars) { | ||
| 157 | FuncState *fs = ls->fs; | 145 | FuncState *fs = ls->fs; |
| 158 | while (nvars--) { | 146 | luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables"); |
| 159 | lua_assert(fs->actvar[fs->nactvar].k == VLOCAL); | 147 | fs->actvar[fs->nactvar+n] = luaI_registerlocalvar(ls, name); |
| 160 | fs->f->locvars[fs->actvar[fs->nactvar].i].startpc = fs->pc; | ||
| 161 | fs->nactvar++; | ||
| 162 | fs->nactloc++; | ||
| 163 | } | ||
| 164 | } | 148 | } |
| 165 | 149 | ||
| 166 | 150 | ||
| 167 | static void adjustglobalvars (LexState *ls, int nvars, int level) { | 151 | static void adjustlocalvars (LexState *ls, int nvars) { |
| 168 | FuncState *fs = ls->fs; | 152 | FuncState *fs = ls->fs; |
| 169 | while (nvars--) { | 153 | fs->nactvar += nvars; |
| 170 | fs->actvar[fs->nactvar].k = VGLOBAL; | 154 | for (; nvars; nvars--) { |
| 171 | fs->actvar[fs->nactvar].level = level; | 155 | getlocvar(fs, fs->nactvar - nvars).startpc = fs->pc; |
| 172 | fs->nactvar++; | ||
| 173 | } | 156 | } |
| 174 | } | 157 | } |
| 175 | 158 | ||
| 176 | 159 | ||
| 177 | static void removevars (LexState *ls, int tolevel) { | 160 | static void removevars (LexState *ls, int tolevel) { |
| 178 | FuncState *fs = ls->fs; | 161 | FuncState *fs = ls->fs; |
| 179 | while (fs->nactvar > tolevel) { | 162 | while (fs->nactvar > tolevel) |
| 180 | fs->nactvar--; | 163 | getlocvar(fs, --fs->nactvar).endpc = fs->pc; |
| 181 | if (fs->actvar[fs->nactvar].k == VLOCAL) { | ||
| 182 | fs->nactloc--; | ||
| 183 | fs->f->locvars[fs->actvar[fs->nactvar].i].endpc = fs->pc; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | } | 164 | } |
| 187 | 165 | ||
| 188 | 166 | ||
| @@ -210,80 +188,48 @@ static int indexupvalue (FuncState *fs, expdesc *v) { | |||
| 210 | } | 188 | } |
| 211 | 189 | ||
| 212 | 190 | ||
| 213 | static vardesc *searchvar (FuncState *fs, TString *n) { | 191 | static int searchvar (FuncState *fs, TString *n) { |
| 214 | int i; | 192 | int i; |
| 215 | for (i=fs->nactvar-1; i >= 0; i--) { | 193 | for (i=fs->nactvar-1; i >= 0; i--) { |
| 216 | vardesc *v = &fs->actvar[i]; | 194 | if (n == getlocvar(fs, i).varname) |
| 217 | if (v->k == VLOCAL ? n == fs->f->locvars[v->i].varname | 195 | return i; |
| 218 | : n == tsvalue(&fs->f->k[v->i])) | ||
| 219 | return v; | ||
| 220 | } | 196 | } |
| 221 | return NULL; /* not found */ | 197 | return -1; /* not found */ |
| 222 | } | 198 | } |
| 223 | 199 | ||
| 224 | 200 | ||
| 225 | static void markupval (FuncState *fs, int level) { | 201 | static void markupval (FuncState *fs, int level) { |
| 226 | BlockCnt *bl = fs->bl; | 202 | BlockCnt *bl = fs->bl; |
| 227 | while (bl && bl->nactloc > level) bl = bl->previous; | 203 | while (bl && bl->nactvar > level) bl = bl->previous; |
| 228 | if (bl) bl->upval = 1; | 204 | if (bl) bl->upval = 1; |
| 229 | } | 205 | } |
| 230 | 206 | ||
| 231 | 207 | ||
| 232 | static int singlevar_aux (FuncState *fs, TString *n, expdesc *var, int nd) { | 208 | static void singlevar (FuncState *fs, TString *n, expdesc *var, int base) { |
| 233 | if (fs == NULL) { /* no more levels? */ | 209 | if (fs == NULL) /* no more levels? */ |
| 234 | init_exp(var, VGLOBAL, NO_REG); /* default is free global */ | 210 | init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ |
| 235 | return VNIL; /* not found */ | ||
| 236 | } | ||
| 237 | else { | 211 | else { |
| 238 | vardesc *v = searchvar(fs, n); /* look up at current level */ | 212 | int v = searchvar(fs, n); /* look up at current level */ |
| 239 | if (v) { | 213 | if (v >= 0) { |
| 240 | if (v->level == NO_REG) { /* free global? */ | 214 | init_exp(var, VLOCAL, v); |
| 241 | lua_assert(v->k == VGLOBAL); | 215 | if (!base) |
| 242 | init_exp(var, VGLOBAL, NO_REG); | 216 | markupval(fs, v); /* local will be used as an upval */ |
| 243 | } | ||
| 244 | else | ||
| 245 | init_exp(var, VLOCAL, v->level); | ||
| 246 | return v->k; | ||
| 247 | } | 217 | } |
| 248 | else { /* not found at current level; try upper one */ | 218 | else { /* not found at current level; try upper one */ |
| 249 | int k = singlevar_aux(fs->prev, n, var, nd && fs->defaultglob == NO_REG); | 219 | singlevar(fs->prev, n, var, 0); |
| 250 | if (var->k == VGLOBAL) { | 220 | if (var->k == VGLOBAL) { |
| 251 | if (k == VNIL && nd && fs->defaultglob != NO_REG) { | 221 | if (base) |
| 252 | if (fs->defaultglob == NO_REG1) | 222 | var->info = luaK_stringK(fs, n); /* info points to global name */ |
| 253 | luaX_syntaxerror(fs->ls, "undeclared global"); | ||
| 254 | init_exp(var, VLOCAL, fs->defaultglob); | ||
| 255 | k = VGLOBAL; /* now there is a declaration */ | ||
| 256 | } | ||
| 257 | } | 223 | } |
| 258 | else { /* LOCAL or UPVAL */ | 224 | else { /* LOCAL or UPVAL */ |
| 259 | if (var->k == VLOCAL) | ||
| 260 | markupval(fs->prev, var->info); /* local will be used as an upval */ | ||
| 261 | var->info = indexupvalue(fs, var); | 225 | var->info = indexupvalue(fs, var); |
| 262 | var->k = VUPVAL; /* upvalue in this level */ | 226 | var->k = VUPVAL; /* upvalue in this level */ |
| 263 | } | 227 | } |
| 264 | return k; | ||
| 265 | } | 228 | } |
| 266 | } | 229 | } |
| 267 | } | 230 | } |
| 268 | 231 | ||
| 269 | 232 | ||
| 270 | static void singlevar (FuncState *fs, TString *n, expdesc *var) { | ||
| 271 | int k = singlevar_aux(fs, n, var, 1); | ||
| 272 | if (k == VNIL || k == VGLOBAL) { /* global? */ | ||
| 273 | if (var->k == VGLOBAL) /* free global? */ | ||
| 274 | var->info = luaK_stringK(fs, n); | ||
| 275 | else { /* `indexed' global */ | ||
| 276 | expdesc e; | ||
| 277 | codestring(fs->ls, &e, n); | ||
| 278 | luaK_exp2anyreg(fs, var); | ||
| 279 | var->aux = luaK_exp2RK(fs, &e); | ||
| 280 | var->k = VINDEXED; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { | 233 | static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { |
| 288 | FuncState *fs = ls->fs; | 234 | FuncState *fs = ls->fs; |
| 289 | int extra = nvars - nexps; | 235 | int extra = nvars - nexps; |
| @@ -308,24 +254,22 @@ static void code_params (LexState *ls, int nparams, int dots) { | |||
| 308 | FuncState *fs = ls->fs; | 254 | FuncState *fs = ls->fs; |
| 309 | adjustlocalvars(ls, nparams); | 255 | adjustlocalvars(ls, nparams); |
| 310 | luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters"); | 256 | luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters"); |
| 311 | fs->f->numparams = cast(lu_byte, fs->nactloc); | 257 | fs->f->numparams = cast(lu_byte, fs->nactvar); |
| 312 | fs->f->is_vararg = cast(lu_byte, dots); | 258 | fs->f->is_vararg = cast(lu_byte, dots); |
| 313 | if (dots) | 259 | if (dots) |
| 314 | create_local(ls, "arg"); | 260 | create_local(ls, "arg"); |
| 315 | luaK_reserveregs(fs, fs->nactloc); /* reserve register for parameters */ | 261 | luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */ |
| 316 | } | 262 | } |
| 317 | 263 | ||
| 318 | 264 | ||
| 319 | static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { | 265 | static void enterblock (FuncState *fs, BlockCnt *bl, int isbreakable) { |
| 320 | bl->breaklist = NO_JUMP; | 266 | bl->breaklist = NO_JUMP; |
| 321 | bl->isbreakable = isbreakable; | 267 | bl->isbreakable = isbreakable; |
| 322 | bl->nactloc = fs->nactloc; | ||
| 323 | bl->nactvar = fs->nactvar; | 268 | bl->nactvar = fs->nactvar; |
| 324 | bl->defaultglob = fs->defaultglob; | ||
| 325 | bl->upval = 0; | 269 | bl->upval = 0; |
| 326 | bl->previous = fs->bl; | 270 | bl->previous = fs->bl; |
| 327 | fs->bl = bl; | 271 | fs->bl = bl; |
| 328 | lua_assert(fs->freereg == fs->nactloc); | 272 | lua_assert(fs->freereg == fs->nactvar); |
| 329 | } | 273 | } |
| 330 | 274 | ||
| 331 | 275 | ||
| @@ -334,11 +278,9 @@ static void leaveblock (FuncState *fs) { | |||
| 334 | fs->bl = bl->previous; | 278 | fs->bl = bl->previous; |
| 335 | removevars(fs->ls, bl->nactvar); | 279 | removevars(fs->ls, bl->nactvar); |
| 336 | if (bl->upval) | 280 | if (bl->upval) |
| 337 | luaK_codeABC(fs, OP_CLOSE, bl->nactloc, 0, 0); | 281 | luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); |
| 338 | lua_assert(bl->nactloc == fs->nactloc); | ||
| 339 | lua_assert(bl->nactvar == fs->nactvar); | 282 | lua_assert(bl->nactvar == fs->nactvar); |
| 340 | fs->freereg = fs->nactloc; /* free registers */ | 283 | fs->freereg = fs->nactvar; /* free registers */ |
| 341 | fs->defaultglob = bl->defaultglob; | ||
| 342 | luaK_patchtohere(fs, bl->breaklist); | 284 | luaK_patchtohere(fs, bl->breaklist); |
| 343 | } | 285 | } |
| 344 | 286 | ||
| @@ -373,9 +315,7 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
| 373 | fs->h = luaH_new(ls->L, 0, 0); | 315 | fs->h = luaH_new(ls->L, 0, 0); |
| 374 | fs->np = 0; | 316 | fs->np = 0; |
| 375 | fs->nlocvars = 0; | 317 | fs->nlocvars = 0; |
| 376 | fs->nactloc = 0; | ||
| 377 | fs->nactvar = 0; | 318 | fs->nactvar = 0; |
| 378 | fs->defaultglob = NO_REG; /* default is free globals */ | ||
| 379 | fs->bl = NULL; | 319 | fs->bl = NULL; |
| 380 | f->code = NULL; | 320 | f->code = NULL; |
| 381 | f->source = ls->source; | 321 | f->source = ls->source; |
| @@ -658,13 +598,13 @@ static void prefixexp (LexState *ls, expdesc *v) { | |||
| 658 | return; | 598 | return; |
| 659 | } | 599 | } |
| 660 | case TK_NAME: { | 600 | case TK_NAME: { |
| 661 | singlevar(ls->fs, str_checkname(ls), v); | 601 | singlevar(ls->fs, str_checkname(ls), v, 1); |
| 662 | next(ls); | 602 | next(ls); |
| 663 | return; | 603 | return; |
| 664 | } | 604 | } |
| 665 | case '%': { /* for compatibility only */ | 605 | case '%': { /* for compatibility only */ |
| 666 | next(ls); /* skip `%' */ | 606 | next(ls); /* skip `%' */ |
| 667 | singlevar(ls->fs, str_checkname(ls), v); | 607 | singlevar(ls->fs, str_checkname(ls), v, 1); |
| 668 | check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete"); | 608 | check_condition(ls, v->k == VUPVAL, "global upvalues are obsolete"); |
| 669 | next(ls); | 609 | next(ls); |
| 670 | return; | 610 | return; |
| @@ -1173,38 +1113,10 @@ static void localstat (LexState *ls) { | |||
| 1173 | } | 1113 | } |
| 1174 | 1114 | ||
| 1175 | 1115 | ||
| 1176 | static void globalstat (LexState *ls) { | ||
| 1177 | /* stat -> GLOBAL NAME {`,' NAME} [IN exp] | GLOBAL IN exp */ | ||
| 1178 | FuncState *fs = ls->fs; | ||
| 1179 | int nvars = 0; | ||
| 1180 | next(ls); /* skip GLOBAL */ | ||
| 1181 | if (ls->t.token == TK_NAME) { | ||
| 1182 | do { | ||
| 1183 | vardesc *v = new_var(ls, nvars++); | ||
| 1184 | v->i = luaK_stringK(ls->fs, str_checkname(ls)); | ||
| 1185 | next(ls); /* skip name */ | ||
| 1186 | } while (optional(ls, ',')); | ||
| 1187 | } | ||
| 1188 | if (!optional(ls, TK_IN)) { /* free globals? */ | ||
| 1189 | if (nvars == 0) /* default - free is invalid */ | ||
| 1190 | error_expected(ls, TK_IN); | ||
| 1191 | adjustglobalvars(ls, nvars, NO_REG); /* mark globals as free */ | ||
| 1192 | } | ||
| 1193 | else { | ||
| 1194 | int baselocal = fs->freereg; | ||
| 1195 | int k = exp1(ls); | ||
| 1196 | if (nvars == 0) | ||
| 1197 | fs->defaultglob = (k == VNIL) ? NO_REG1 : baselocal; | ||
| 1198 | adjustglobalvars(ls, nvars, baselocal); | ||
| 1199 | create_local(ls, "*"); | ||
| 1200 | } | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | |||
| 1204 | static int funcname (LexState *ls, expdesc *v) { | 1116 | static int funcname (LexState *ls, expdesc *v) { |
| 1205 | /* funcname -> NAME {field} [`:' NAME] */ | 1117 | /* funcname -> NAME {field} [`:' NAME] */ |
| 1206 | int needself = 0; | 1118 | int needself = 0; |
| 1207 | singlevar(ls->fs, str_checkname(ls), v); | 1119 | singlevar(ls->fs, str_checkname(ls), v, 1); |
| 1208 | next(ls); /* skip var name */ | 1120 | next(ls); /* skip var name */ |
| 1209 | while (ls->t.token == '.') { | 1121 | while (ls->t.token == '.') { |
| 1210 | luaY_field(ls, v); | 1122 | luaY_field(ls, v); |
| @@ -1259,7 +1171,7 @@ static void retstat (LexState *ls) { | |||
| 1259 | return; | 1171 | return; |
| 1260 | } | 1172 | } |
| 1261 | luaK_setcallreturns(fs, &e, LUA_MULTRET); | 1173 | luaK_setcallreturns(fs, &e, LUA_MULTRET); |
| 1262 | first = fs->nactloc; | 1174 | first = fs->nactvar; |
| 1263 | nret = LUA_MULTRET; /* return all values */ | 1175 | nret = LUA_MULTRET; /* return all values */ |
| 1264 | } | 1176 | } |
| 1265 | else { | 1177 | else { |
| @@ -1267,7 +1179,7 @@ static void retstat (LexState *ls) { | |||
| 1267 | first = luaK_exp2anyreg(fs, &e); | 1179 | first = luaK_exp2anyreg(fs, &e); |
| 1268 | else { | 1180 | else { |
| 1269 | luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ | 1181 | luaK_exp2nextreg(fs, &e); /* values must go to the `stack' */ |
| 1270 | first = fs->nactloc; /* return all `active' values */ | 1182 | first = fs->nactvar; /* return all `active' values */ |
| 1271 | lua_assert(nret == fs->freereg - first); | 1183 | lua_assert(nret == fs->freereg - first); |
| 1272 | } | 1184 | } |
| 1273 | } | 1185 | } |
| @@ -1289,7 +1201,7 @@ static void breakstat (LexState *ls) { | |||
| 1289 | if (!bl) | 1201 | if (!bl) |
| 1290 | luaX_syntaxerror(ls, "no loop to break"); | 1202 | luaX_syntaxerror(ls, "no loop to break"); |
| 1291 | if (upval) | 1203 | if (upval) |
| 1292 | luaK_codeABC(fs, OP_CLOSE, bl->nactloc, 0, 0); | 1204 | luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); |
| 1293 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); | 1205 | luaK_concat(fs, &bl->breaklist, luaK_jump(fs)); |
| 1294 | } | 1206 | } |
| 1295 | 1207 | ||
| @@ -1327,10 +1239,6 @@ static int statement (LexState *ls) { | |||
| 1327 | localstat(ls); | 1239 | localstat(ls); |
| 1328 | return 0; | 1240 | return 0; |
| 1329 | } | 1241 | } |
| 1330 | case TK_GLOBAL: { /* stat -> globalstat */ | ||
| 1331 | globalstat(ls); | ||
| 1332 | return 0; | ||
| 1333 | } | ||
| 1334 | case TK_RETURN: { /* stat -> retstat */ | 1242 | case TK_RETURN: { /* stat -> retstat */ |
| 1335 | retstat(ls); | 1243 | retstat(ls); |
| 1336 | return 1; /* must be last statement */ | 1244 | return 1; /* must be last statement */ |
| @@ -1391,8 +1299,8 @@ static void chunk (LexState *ls) { | |||
| 1391 | while (!islast && !block_follow(ls->t.token)) { | 1299 | while (!islast && !block_follow(ls->t.token)) { |
| 1392 | islast = statement(ls); | 1300 | islast = statement(ls); |
| 1393 | optional(ls, ';'); | 1301 | optional(ls, ';'); |
| 1394 | lua_assert(ls->fs->freereg >= ls->fs->nactloc); | 1302 | lua_assert(ls->fs->freereg >= ls->fs->nactvar); |
| 1395 | ls->fs->freereg = ls->fs->nactloc; /* free registers */ | 1303 | ls->fs->freereg = ls->fs->nactvar; /* free registers */ |
| 1396 | } | 1304 | } |
| 1397 | } | 1305 | } |
| 1398 | 1306 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.h,v 1.42 2002/05/09 18:00:38 roberto Exp roberto $ | 2 | ** $Id: lparser.h,v 1.43 2002/05/10 19:22:11 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 | */ |
| @@ -41,18 +41,9 @@ typedef struct expdesc { | |||
| 41 | } expdesc; | 41 | } expdesc; |
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | /* describe declared variables */ | ||
| 45 | typedef struct vardesc { | ||
| 46 | int i; /* if local, its index in `locvars'; | ||
| 47 | if global, its name index in `k' */ | ||
| 48 | lu_byte k; | ||
| 49 | lu_byte level; /* if local, stack level; | ||
| 50 | if global, corresponding local (NO_REG for free globals) */ | ||
| 51 | } vardesc; | ||
| 52 | |||
| 53 | |||
| 54 | struct BlockCnt; /* defined in lparser.c */ | 44 | struct BlockCnt; /* defined in lparser.c */ |
| 55 | 45 | ||
| 46 | |||
| 56 | /* state needed to generate code for a given function */ | 47 | /* state needed to generate code for a given function */ |
| 57 | typedef struct FuncState { | 48 | typedef struct FuncState { |
| 58 | Proto *f; /* current function header */ | 49 | Proto *f; /* current function header */ |
| @@ -63,16 +54,14 @@ typedef struct FuncState { | |||
| 63 | struct BlockCnt *bl; /* chain of current blocks */ | 54 | struct BlockCnt *bl; /* chain of current blocks */ |
| 64 | int pc; /* next position to code (equivalent to `ncode') */ | 55 | int pc; /* next position to code (equivalent to `ncode') */ |
| 65 | int lasttarget; /* `pc' of last `jump target' */ | 56 | int lasttarget; /* `pc' of last `jump target' */ |
| 66 | int jpc; /* list of jumps to `pc' */ | 57 | int jpc; /* list of pending jumps to `pc' */ |
| 67 | int freereg; /* first free register */ | 58 | int freereg; /* first free register */ |
| 68 | int defaultglob; /* where to look for non-declared globals */ | ||
| 69 | int nk; /* number of elements in `k' */ | 59 | int nk; /* number of elements in `k' */ |
| 70 | int np; /* number of elements in `p' */ | 60 | int np; /* number of elements in `p' */ |
| 71 | int nlocvars; /* number of elements in `locvars' */ | 61 | int nlocvars; /* number of elements in `locvars' */ |
| 72 | int nactloc; /* number of active local variables */ | 62 | int nactvar; /* number of active local variables */ |
| 73 | int nactvar; /* number of elements in array `actvar' */ | ||
| 74 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ | 63 | expdesc upvalues[MAXUPVALUES]; /* upvalues */ |
| 75 | vardesc actvar[MAXVARS]; /* declared-variable stack */ | 64 | int actvar[MAXVARS]; /* declared-variable stack */ |
| 76 | } FuncState; | 65 | } FuncState; |
| 77 | 66 | ||
| 78 | 67 | ||
