optimization: closures without upvalues don't need to be closures

This commit is contained in:
Roberto Ierusalimschy
1997-12-15 14:17:20 -02:00
parent 94144a7821
commit 45e533599f
13 changed files with 132 additions and 93 deletions

14
lua.stx
View File

@@ -1,6 +1,6 @@
%{
/*
** $Id: lua.stx,v 1.21 1997/12/09 13:35:19 roberto Exp roberto $
** $Id: lua.stx,v 1.22 1997/12/09 16:01:08 roberto Exp roberto $
** Syntax analizer and code generator
** See Copyright Notice in lua.h
*/
@@ -555,10 +555,14 @@ static void func_onstack (TProtoFunc *f)
int c = next_constant(L->currState);
ttype(&L->currState->f->consts[c]) = LUA_T_PROTO;
L->currState->f->consts[c].value.tf = (L->currState+1)->f;
for (i=0; i<nupvalues; i++)
lua_pushvar((L->currState+1)->upvalues[i]);
code_constant(c);
code_oparg(CLOSURE, 2, nupvalues, -nupvalues);
if (nupvalues == 0)
code_constant(c);
else {
for (i=0; i<nupvalues; i++)
lua_pushvar((L->currState+1)->upvalues[i]);
code_constant(c);
code_oparg(CLOSURE, 2, nupvalues, -nupvalues);
}
}