@ -222,26 +222,26 @@ static Vardesc *getlocalvardesc (FuncState *fs, int vidx) {
/*
* * Convert ' nvar ' , a compiler index level , to it corresponding
* * stack index level . For that , search for the highest variable
* * below that level that is in the stack and uses its stack
* * index ( ' sidx ' ) .
* * Convert ' nvar ' , a compiler index level , to its corresponding
* * register . For that , search for the highest variable below that level
* * that is in a register and uses its register index ( ' ridx ' ) plus one .
*/
static int stack level ( FuncState * fs , int nvar ) {
static int reg level ( FuncState * fs , int nvar ) {
while ( nvar - - > 0 ) {
Vardesc * vd = getlocalvardesc ( fs , nvar ) ; /* get variable */
if ( vd - > vd . kind ! = RDKCTC ) /* is in the stack ? */
return vd - > vd . s idx + 1 ;
Vardesc * vd = getlocalvardesc ( fs , nvar ) ; /* get previous variable */
if ( vd - > vd . kind ! = RDKCTC ) /* is in a register ? */
return vd - > vd . r idx + 1 ;
}
return 0 ; /* no variables in the stack */
return 0 ; /* no variables in registers */
}
/*
* * Return the number of variables in the stack for function ' fs '
* * Return the number of variables in the register stack for the given
* * function .
*/
int luaY_nvarstack ( FuncState * fs ) {
return stack level( fs , fs - > nactvar ) ;
return reg level( fs , fs - > nactvar ) ;
}
@ -267,7 +267,7 @@ static void init_var (FuncState *fs, expdesc *e, int vidx) {
e - > f = e - > t = NO_JUMP ;
e - > k = VLOCAL ;
e - > u . var . vidx = vidx ;
e - > u . var . s idx = getlocalvardesc ( fs , vidx ) - > vd . s idx;
e - > u . var . r idx = getlocalvardesc ( fs , vidx ) - > vd . r idx;
}
@ -310,12 +310,12 @@ static void check_readonly (LexState *ls, expdesc *e) {
*/
static void adjustlocalvars ( LexState * ls , int nvars ) {
FuncState * fs = ls - > fs ;
int stk level = luaY_nvarstack ( fs ) ;
int reg level = luaY_nvarstack ( fs ) ;
int i ;
for ( i = 0 ; i < nvars ; i + + ) {
int vidx = fs - > nactvar + + ;
Vardesc * var = getlocalvardesc ( fs , vidx ) ;
var - > vd . sidx = stk level+ + ;
var - > vd . ridx = reg level+ + ;
var - > vd . pidx = registerlocalvar ( ls , fs , var - > vd . name ) ;
}
}
@ -366,7 +366,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
FuncState * prev = fs - > prev ;
if ( v - > k = = VLOCAL ) {
up - > instack = 1 ;
up - > idx = v - > u . var . s idx;
up - > idx = v - > u . var . r idx;
up - > kind = getlocalvardesc ( prev , v - > u . var . vidx ) - > vd . kind ;
lua_assert ( eqstr ( name , getlocalvardesc ( prev , v - > u . var . vidx ) - > vd . name ) ) ;
}
@ -620,7 +620,7 @@ static void movegotosout (FuncState *fs, BlockCnt *bl) {
for ( i = bl - > firstgoto ; i < gl - > n ; i + + ) { /* for each pending goto */
Labeldesc * gt = & gl - > arr [ i ] ;
/* leaving a variable scope? */
if ( stack level( fs , gt - > nactvar ) > stack level( fs , bl - > nactvar ) )
if ( reg level( fs , gt - > nactvar ) > reg level( fs , bl - > nactvar ) )
gt - > close | = bl - > upval ; /* jump may need a close */
gt - > nactvar = bl - > nactvar ; /* update goto level */
}
@ -661,7 +661,7 @@ static void leaveblock (FuncState *fs) {
BlockCnt * bl = fs - > bl ;
LexState * ls = fs - > ls ;
int hasclose = 0 ;
int stklevel = stack level( fs , bl - > nactvar ) ; /* level outside the block */
int stklevel = reg level( fs , bl - > nactvar ) ; /* level outside the block */
if ( bl - > isloop ) /* fix pending breaks? */
hasclose = createlabel ( ls , luaS_newliteral ( ls - > L , " break " ) , 0 , 0 ) ;
if ( ! hasclose & & bl - > previous & & bl - > upval )
@ -1330,13 +1330,13 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
}
}
else { /* table is a register */
if ( v - > k = = VLOCAL & & lh - > v . u . ind . t = = v - > u . var . s idx) {
if ( v - > k = = VLOCAL & & lh - > v . u . ind . t = = v - > u . var . r idx) {
conflict = 1 ; /* table is the local being assigned now */
lh - > v . u . ind . t = extra ; /* assignment will use safe copy */
}
/* is index the local being assigned? */
if ( lh - > v . k = = VINDEXED & & v - > k = = VLOCAL & &
lh - > v . u . ind . idx = = v - > u . var . s idx) {
lh - > v . u . ind . idx = = v - > u . var . r idx) {
conflict = 1 ;
lh - > v . u . ind . idx = extra ; /* previous assignment will use safe copy */
}
@ -1346,7 +1346,7 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
if ( conflict ) {
/* copy upvalue/local value to a temporary (in position 'extra') */
if ( v - > k = = VLOCAL )
luaK_codeABC ( fs , OP_MOVE , extra , v - > u . var . s idx, 0 ) ;
luaK_codeABC ( fs , OP_MOVE , extra , v - > u . var . r idx, 0 ) ;
else
luaK_codeABC ( fs , OP_GETUPVAL , extra , v - > u . info , 0 ) ;
luaK_reserveregs ( fs , 1 ) ;
@ -1411,7 +1411,7 @@ static void gotostat (LexState *ls) {
newgotoentry ( ls , name , line , luaK_jump ( fs ) ) ;
else { /* found a label */
/* backward jump; will be resolved here */
int lblevel = stack level( fs , lb - > nactvar ) ; /* label level */
int lblevel = reg level( fs , lb - > nactvar ) ; /* label level */
if ( luaY_nvarstack ( fs ) > lblevel ) /* leaving the scope of a variable? */
luaK_codeABC ( fs , OP_CLOSE , lblevel , 0 , 0 ) ;
/* create jump and link it to the label */
@ -1488,7 +1488,7 @@ static void repeatstat (LexState *ls, int line) {
if ( bl2 . upval ) { /* upvalues? */
int exit = luaK_jump ( fs ) ; /* normal exit must jump over fix */
luaK_patchtohere ( fs , condexit ) ; /* repetition must close upvalues */
luaK_codeABC ( fs , OP_CLOSE , stack level( fs , bl2 . nactvar ) , 0 , 0 ) ;
luaK_codeABC ( fs , OP_CLOSE , reg level( fs , bl2 . nactvar ) , 0 , 0 ) ;
condexit = luaK_jump ( fs ) ; /* repeat after closing upvalues */
luaK_patchtohere ( fs , exit ) ; /* normal exit comes to here */
}
@ -1708,7 +1708,7 @@ static void checktoclose (LexState *ls, int level) {
FuncState * fs = ls - > fs ;
markupval ( fs , level + 1 ) ;
fs - > bl - > insidetbc = 1 ; /* in the scope of a to-be-closed variable */
luaK_codeABC ( fs , OP_TBC , stack level( fs , level ) , 0 , 0 ) ;
luaK_codeABC ( fs , OP_TBC , reg level( fs , level ) , 0 , 0 ) ;
}
}