Fixes to luajc bytecode generation.
This commit is contained in:
@@ -21,8 +21,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm2;
|
package org.luaj.vm2;
|
||||||
|
|
||||||
import org.luaj.vm2.lib.DebugLib;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link LuaFunction} which executes lua bytecode.
|
* Extension of {@link LuaFunction} which executes lua bytecode.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -21,9 +21,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.vm2;
|
package org.luaj.vm2;
|
||||||
|
|
||||||
import org.luaj.vm2.Varargs.SubVarargs;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all concrete lua type values.
|
* Base class for all concrete lua type values.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -432,7 +429,7 @@ public class LuaValue extends Varargs {
|
|||||||
*/
|
*/
|
||||||
public boolean isuserdata(Class c) { return false; }
|
public boolean isuserdata(Class c) { return false; }
|
||||||
|
|
||||||
/** Convert to boolean false if {@link #NIL} or {@link FALSE}, true if anything else
|
/** Convert to boolean false if {@link #NIL} or {@link #FALSE}, true if anything else
|
||||||
* @return Value cast to byte if number or string convertible to number, otherwise 0
|
* @return Value cast to byte if number or string convertible to number, otherwise 0
|
||||||
* @see #optboolean(boolean)
|
* @see #optboolean(boolean)
|
||||||
* @see #checkboolean()
|
* @see #checkboolean()
|
||||||
|
|||||||
@@ -105,11 +105,12 @@ public class LuaJC implements LuaCompiler {
|
|||||||
|
|
||||||
private static String toStandardJavaClassName( String luachunkname ) {
|
private static String toStandardJavaClassName( String luachunkname ) {
|
||||||
String stub = toStub( luachunkname );
|
String stub = toStub( luachunkname );
|
||||||
String classname = stub.replace('/','.').replaceAll(NON_IDENTIFIER, "_");
|
StringBuffer classname = new StringBuffer();
|
||||||
int c = classname.charAt(0);
|
for (int i = 0, n = stub.length(); i < n; ++i) {
|
||||||
if ( c!='_' && !Character.isJavaIdentifierStart(c) )
|
final char c = stub.charAt(i);
|
||||||
classname = "_"+classname;
|
classname.append((((i == 0) && Character.isJavaIdentifierStart(c)) || ((i > 0) && Character.isJavaIdentifierPart(c)))? c: '_');
|
||||||
return classname;
|
}
|
||||||
|
return classname.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toStandardLuaFileName( String luachunkname ) {
|
private static String toStandardLuaFileName( String luachunkname ) {
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ public class ProtoInfo {
|
|||||||
// A main chunk proto info.
|
// A main chunk proto info.
|
||||||
public ProtoInfo(Prototype p, String name) {
|
public ProtoInfo(Prototype p, String name) {
|
||||||
// For the outer chunk, we have one upvalue which is the environment.
|
// For the outer chunk, we have one upvalue which is the environment.
|
||||||
this(p,name,new UpvalInfo[] { new UpvalInfo() });
|
this(p,name,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProtoInfo(Prototype p, String name, UpvalInfo[] u) {
|
private ProtoInfo(Prototype p, String name, UpvalInfo[] u) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.prototype = p;
|
this.prototype = p;
|
||||||
this.upvals = u;
|
this.upvals = u != null? u: new UpvalInfo[] { new UpvalInfo(this) };
|
||||||
this.subprotos = p.p!=null&&p.p.length>0? new ProtoInfo[p.p.length]: null;
|
this.subprotos = p.p!=null&&p.p.length>0? new ProtoInfo[p.p.length]: null;
|
||||||
|
|
||||||
// find basic blocks
|
// find basic blocks
|
||||||
@@ -364,6 +364,10 @@ public class ProtoInfo {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Lua.OP_JMP: /* sBx pc+=sBx */
|
case Lua.OP_JMP: /* sBx pc+=sBx */
|
||||||
|
a = Lua.GETARG_A( ins );
|
||||||
|
if (a > 0)
|
||||||
|
for ( --a; a<m; a++ )
|
||||||
|
v[a][pc] = VarInfo.INVALID;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -13,9 +13,12 @@ public class UpvalInfo {
|
|||||||
boolean rw; // read-write
|
boolean rw; // read-write
|
||||||
|
|
||||||
// Upval info representing the implied context containing only the environment.
|
// Upval info representing the implied context containing only the environment.
|
||||||
public UpvalInfo() {
|
public UpvalInfo(ProtoInfo pi) {
|
||||||
nvars = 1;
|
this.pi = pi;
|
||||||
var = new VarInfo[] { VarInfo.PARAM(0) };
|
this.slot = 0;
|
||||||
|
this.nvars = 1;
|
||||||
|
this.var = new VarInfo[] { VarInfo.PARAM(0) };
|
||||||
|
this.rw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpvalInfo(ProtoInfo pi, int pc, int slot) {
|
public UpvalInfo(ProtoInfo pi, int pc, int slot) {
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ public class TestLuaJC {
|
|||||||
// create the script
|
// create the script
|
||||||
public static String name = "script";
|
public static String name = "script";
|
||||||
public static String script =
|
public static String script =
|
||||||
"for n,p in ipairs({77}) do\n"+
|
"function f1(a) print( 'f1:', a ) return a end\n" +
|
||||||
" print('n,p',n,p)\n"+
|
"b = f1()\n" +
|
||||||
"end\n";
|
"return b";
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.println(script);
|
System.out.println(script);
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ public class CompatibiltyTest extends TestSuite {
|
|||||||
|
|
||||||
public static TestSuite suite() {
|
public static TestSuite suite() {
|
||||||
TestSuite suite = new TestSuite("Compatibility Tests");
|
TestSuite suite = new TestSuite("Compatibility Tests");
|
||||||
suite.addTest( new TestSuite( JseCompatibilityTest.class, "JSE Tests" ) );
|
suite.addTest( new TestSuite( JseCompatibilityTest.class, "JSE Compatibility Tests" ) );
|
||||||
suite.addTest( new TestSuite( JmeCompatibilityTest.class, "JME Tests" ) );
|
suite.addTest( new TestSuite( JmeCompatibilityTest.class, "JME Compatibility Tests" ) );
|
||||||
suite.addTest( new TestSuite( LuaJCTest.class, "JSE Bytecode Tests" ) );
|
suite.addTest( new TestSuite( LuaJCCompatibilityTest.class, "LuaJC Compatibility Tests" ) );
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +100,8 @@ public class CompatibiltyTest extends TestSuite {
|
|||||||
System.setProperty("JME", "false");
|
System.setProperty("JME", "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class LuaJCTest extends CompatibiltyTestSuite {
|
public static class LuaJCCompatibilityTest extends CompatibiltyTestSuite {
|
||||||
public LuaJCTest() {
|
public LuaJCCompatibilityTest() {
|
||||||
super(ScriptDrivenTest.PlatformType.LUAJIT);
|
super(ScriptDrivenTest.PlatformType.LUAJIT);
|
||||||
}
|
}
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
|||||||
@@ -545,5 +545,15 @@ public class FragmentsTest extends TestSuite {
|
|||||||
" end\n" +
|
" end\n" +
|
||||||
"end\n");
|
"end\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUpvalueInDoBlock() {
|
||||||
|
runFragment( LuaValue.NONE, "do\n"+
|
||||||
|
" local x = 10\n"+
|
||||||
|
" function g()\n"+
|
||||||
|
" return x\n"+
|
||||||
|
" end\n"+
|
||||||
|
"end\n"+
|
||||||
|
"g()\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package org.luaj.vm2;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -121,6 +122,8 @@ public class ScriptDrivenTest extends TestCase implements ResourceFinder {
|
|||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// Ignore and return null.
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ checkallpass('debug.setupvalue',{{f},{2,'3'},{nil,aboolean,astring,n=3}})
|
|||||||
print('p,q', p, q)
|
print('p,q', p, q)
|
||||||
checkallerrors('debug.setupvalue',{},'value expected')
|
checkallerrors('debug.setupvalue',{},'value expected')
|
||||||
checkallerrors('debug.setupvalue',{{f}},'value expected')
|
checkallerrors('debug.setupvalue',{{f}},'value expected')
|
||||||
checkallerrors('debug.setupvalue',{{f},{1}},'value expected')
|
checkallerrors('debug.setupvalue',{{f},{2}},'value expected')
|
||||||
checkallerrors('debug.setupvalue',{notafunction,{2}}, 'value expected')
|
checkallerrors('debug.setupvalue',{notafunction,{2}}, 'value expected')
|
||||||
checkallerrors('debug.setupvalue',{{f},notanumber}, 'value expected')
|
checkallerrors('debug.setupvalue',{{f},notanumber}, 'value expected')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user