diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-16 08:59:34 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-16 08:59:34 -0200 |
| commit | 45ccb0e881064492a3f422b15b50dad71eed36fa (patch) | |
| tree | d819206b4af4fb9a257534471455ce233c1c93e3 /lua.stx | |
| parent | 4be18fa889657ebd317f5311ecf65da64891242b (diff) | |
| download | lua-45ccb0e881064492a3f422b15b50dad71eed36fa.tar.gz lua-45ccb0e881064492a3f422b15b50dad71eed36fa.tar.bz2 lua-45ccb0e881064492a3f422b15b50dad71eed36fa.zip | |
"nupvalues" is kept in Closure, not in prototype (as a preparation
for C closures...)
Diffstat (limited to 'lua.stx')
| -rw-r--r-- | lua.stx | 15 |
1 files changed, 9 insertions, 6 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | /* | 2 | /* |
| 3 | ** $Id: lua.stx,v 1.9 1997/10/13 22:12:04 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.10 1997/10/15 20:16:00 roberto Exp roberto $ |
| 4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| @@ -57,6 +57,7 @@ typedef struct State { | |||
| 57 | int stacksize; /* number of values on activation register */ | 57 | int stacksize; /* number of values on activation register */ |
| 58 | int maxstacksize; /* maximum number of values on activation register */ | 58 | int maxstacksize; /* maximum number of values on activation register */ |
| 59 | int nlocalvar; /* number of active local variables */ | 59 | int nlocalvar; /* number of active local variables */ |
| 60 | int nupvalues; /* number of upvalues */ | ||
| 60 | int nvars; /* number of entries in f->locvars */ | 61 | int nvars; /* number of entries in f->locvars */ |
| 61 | int maxcode; /* size of f->code */ | 62 | int maxcode; /* size of f->code */ |
| 62 | int maxvars; /* size of f->locvars (-1 if no debug information) */ | 63 | int maxvars; /* size of f->locvars (-1 if no debug information) */ |
| @@ -347,14 +348,14 @@ static int indexupvalue (TaggedString *n) | |||
| 347 | { | 348 | { |
| 348 | vardesc v = singlevar(n, currState-1); | 349 | vardesc v = singlevar(n, currState-1); |
| 349 | int i; | 350 | int i; |
| 350 | for (i=0; i<currState->f->nupvalues; i++) { | 351 | for (i=0; i<currState->nupvalues; i++) { |
| 351 | if (currState->upvalues[i] == v) | 352 | if (currState->upvalues[i] == v) |
| 352 | return i; | 353 | return i; |
| 353 | } | 354 | } |
| 354 | /* new one */ | 355 | /* new one */ |
| 355 | if (++currState->f->nupvalues > MAXUPVALUES) | 356 | if (++currState->nupvalues > MAXUPVALUES) |
| 356 | luaY_error("too many upvalues in a single function"); | 357 | luaY_error("too many upvalues in a single function"); |
| 357 | currState->upvalues[i] = v; /* i = currState->f->nupvalues - 1 */ | 358 | currState->upvalues[i] = v; /* i = currState->nupvalues - 1 */ |
| 358 | return i; | 359 | return i; |
| 359 | } | 360 | } |
| 360 | 361 | ||
| @@ -515,13 +516,14 @@ static void codereturn (void) | |||
| 515 | static void func_onstack (TProtoFunc *f) | 516 | static void func_onstack (TProtoFunc *f) |
| 516 | { | 517 | { |
| 517 | int i; | 518 | int i; |
| 518 | int nupvalues = (currState+1)->f->nupvalues; | 519 | int nupvalues = (currState+1)->nupvalues; |
| 519 | int c = next_constant(currState); | 520 | int c = next_constant(currState); |
| 520 | ttype(&currState->f->consts[c]) = LUA_T_PROTO; | 521 | ttype(&currState->f->consts[c]) = LUA_T_PROTO; |
| 521 | currState->f->consts[c].value.tf = (currState+1)->f; | 522 | currState->f->consts[c].value.tf = (currState+1)->f; |
| 523 | code_constant(c); | ||
| 522 | for (i=0; i<nupvalues; i++) | 524 | for (i=0; i<nupvalues; i++) |
| 523 | lua_pushvar((currState+1)->upvalues[i]); | 525 | lua_pushvar((currState+1)->upvalues[i]); |
| 524 | code_oparg(CLOSURE, 0, c, 1-nupvalues); | 526 | code_oparg(CLOSURE, 2, nupvalues, -nupvalues); |
| 525 | } | 527 | } |
| 526 | 528 | ||
| 527 | 529 | ||
| @@ -531,6 +533,7 @@ static void init_state (TaggedString *filename) | |||
| 531 | currState->stacksize = 0; | 533 | currState->stacksize = 0; |
| 532 | currState->maxstacksize = 0; | 534 | currState->maxstacksize = 0; |
| 533 | currState->nlocalvar = 0; | 535 | currState->nlocalvar = 0; |
| 536 | currState->nupvalues = 0; | ||
| 534 | currState->f = f; | 537 | currState->f = f; |
| 535 | f->fileName = filename; | 538 | f->fileName = filename; |
| 536 | currState->pc = 0; | 539 | currState->pc = 0; |
