Improve bytecode generation.

This commit is contained in:
James Roseborough
2010-08-12 17:00:47 +00:00
parent 02be06c7b6
commit a950957318
2 changed files with 34 additions and 1 deletions

View File

@@ -58,8 +58,11 @@ public class UpvalInfo {
for ( int j=0, m=b.next!=null? b.next.length: 0; j<m; j++ ) {
BasicBlock b1 = b.next[j];
VarInfo v1 = pi.vars[slot][b1.pc0];
if ( v1 != prior )
if ( v1 != prior ) {
loopDetected |= includeVarAndPosteriorVars( v1 );
if ( v1.isPhiVar() )
includePriorVarsIgnoreLoops( v1 );
}
}
} else {
for ( int pc=b.pc1-1; pc>=b.pc0; pc-- ) {

View File

@@ -549,5 +549,35 @@ public class FragmentsTest extends TestSuite {
" return env[k] or v\n" +
"end\n");
}
public void testPhiVarUpvalue() {
runFragment( LuaValue.valueOf(2),
"local a = 1\n"+
"local function b()\n"+
" a = a + 1\n"+
" return function() end\n"+
"end\n"+
"for i in b() do\n"+
" a = 3\n"+
"end\n" +
"return a\n");
}
public void testUpvaluesInElseClauses() {
runFragment( LuaValue.valueOf(111),
"if a then\n" +
" foo(bar)\n" +
"elseif _G then\n" +
" local x = 111\n" +
" if d then\n" +
" foo(bar)\n" +
" else\n" +
" local y = function()\n" +
" return x\n" +
" end\n" +
" return y()\n" +
" end\n" +
"end\n");
}
}
}