Improve bytecode generation.

This commit is contained in:
James Roseborough
2010-08-12 05:26:02 +00:00
parent 386e89aedf
commit 02be06c7b6
2 changed files with 16 additions and 1 deletions

View File

@@ -3,6 +3,8 @@
*/
package org.luaj.vm2.luajc;
import org.luaj.vm2.Lua;
public class UpvalInfo {
ProtoInfo pi; // where defined
int slot; // where defined
@@ -28,12 +30,25 @@ public class UpvalInfo {
return true;
var.upvalue = this;
appendVar( var );
if ( isLoopVariable( var ) )
return false;
boolean loopDetected = includePosteriorVarsCheckLoops( var );
if ( loopDetected )
includePriorVarsIgnoreLoops( var );
return loopDetected;
}
private boolean isLoopVariable(VarInfo var) {
if ( var.pc >= 0 ) {
switch ( Lua.GET_OPCODE(pi.prototype.code[var.pc]) ) {
case Lua.OP_TFORLOOP:
case Lua.OP_FORLOOP:
return true;
}
}
return false;
}
private boolean includePosteriorVarsCheckLoops( VarInfo prior ) {
boolean loopDetected = false;
for ( int i=0, n=pi.blocklist.length; i<n; i++ ) {

View File

@@ -535,7 +535,7 @@ public class FragmentsTest extends TestSuite {
"return 5\n" );
}
public void testTwoLoops() {
public void testLoopVarUpvalues() {
runFragment( LuaValue.valueOf("b"),
"local env = {}\n" +
"for a,b in pairs(_G) do\n" +