Improve bytecode generation.

This commit is contained in:
James Roseborough
2010-07-30 23:50:03 +00:00
parent e2249fc9ca
commit 08d9c148d0

View File

@@ -334,12 +334,14 @@ public class Slots {
private void markuninitialized() {
for ( int j=p.numparams; j<m; j++ )
if ( ! isreferrededtofirst(j) )
if ( ! needsinitialnil(j) )
slots[0][j] |= BIT_INVALID;
}
private boolean isreferrededtofirst(int j) {
private boolean needsinitialnil(int j) {
for ( int i=1; i<=n; i++ ) {
if ( isbranchsource(i) )
return true;
if ( (slots[i][j] & (BIT_REFER | BIT_UP_REFER)) != 0 )
return true;
if ( (slots[i][j] & (BIT_ASSIGN | BIT_UP_ASSIGN | BIT_UP_CREATE | BIT_INVALID)) != 0 )
@@ -348,6 +350,28 @@ public class Slots {
return false;
}
private boolean isbranchsource(int index) {
if (index >= p.code.length )
return false;
int ins = p.code[index];
switch ( Lua.GET_OPCODE(ins) ) {
case Lua.OP_LOADBOOL:
if ( Lua.GETARG_C(ins) == 0 )
return true;
case Lua.OP_EQ:
case Lua.OP_LT:
case Lua.OP_LE:
case Lua.OP_TEST:
case Lua.OP_TESTSET:
case Lua.OP_TFORLOOP:
case Lua.OP_JMP:
case Lua.OP_FORPREP:
case Lua.OP_FORLOOP:
return true;
}
return false;
}
private void markupvalues( ) {
for ( int pc=0; pc<n; ++pc ) {
if ( Lua.GET_OPCODE(p.code[pc]) == Lua.OP_CLOSURE ) {