Let ant build download bcel jar as needed.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src/core"/>
|
<classpathentry kind="src" path="src/core"/>
|
||||||
<classpathentry kind="src" path="src/jse"/>
|
<classpathentry excluding="org/luaj/vm2/luajc/antlr/|org/luaj/vm2/luajc/lst/|org/luaj/vm2/luajc/JavaCodeGenerator.java" kind="src" path="src/jse"/>
|
||||||
<classpathentry kind="src" path="src/jme"/>
|
<classpathentry kind="src" path="src/jme"/>
|
||||||
<classpathentry kind="src" path="test/java"/>
|
<classpathentry kind="src" path="test/java"/>
|
||||||
<classpathentry kind="src" path="test/junit"/>
|
<classpathentry kind="src" path="test/junit"/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
bin
|
bin
|
||||||
target
|
target
|
||||||
build
|
build
|
||||||
|
lib
|
||||||
luaj*.jar
|
luaj*.jar
|
||||||
jit
|
jit
|
||||||
*.ser
|
*.ser
|
||||||
|
|||||||
59
build.xml
59
build.xml
@@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
<import file="wtk.xml"/>
|
<import file="wtk.xml"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
<property name="antlr.version" value="3.1.3"/>
|
<property name="antlr.version" value="3.1.3"/>
|
||||||
<property name="antlr.home" value="${env.ANTLR_HOME}"/>
|
<property name="antlr.home" value="${env.ANTLR_HOME}"/>
|
||||||
<property name="antlr.tool.jar" value="${antlr.home}/lib/antlr-${antlr.version}.jar"/>
|
<property name="antlr.tool.jar" value="${antlr.home}/lib/antlr-${antlr.version}.jar"/>
|
||||||
<property name="antlr.runtime.jar" value="${antlr.home}/lib/antlr-runtime-${antlr.version}.jar"/>
|
<property name="antlr.runtime.jar" value="${antlr.home}/lib/antlr-runtime-${antlr.version}.jar"/>
|
||||||
<property name="grammar.dir" value="src/jse/org/luaj/vm2/luajc/antlr"/>
|
<property name="grammar.dir" value="src/jse/org/luaj/vm2/luajc/antlr"/>
|
||||||
<property name="grammar.name" value="Lua"/>
|
<property name="grammar.name" value="Lua"/>
|
||||||
|
-->
|
||||||
|
|
||||||
<target name="clean">
|
<target name="clean">
|
||||||
<delete dir="build"/>
|
<delete dir="build"/>
|
||||||
@@ -22,44 +24,48 @@
|
|||||||
</delete>
|
</delete>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="generate">
|
<available file="lib/bcel-5.2.jar" property="bcel.lib.exists"/>
|
||||||
<fail unless="env.ANTLR_HOME" message="ANTLR_HOME must be set."/>
|
|
||||||
<available file="${antlr.tool.jar}" property="antlr.tool.exists"/>
|
<target name="bcel-lib" unless="bcel.lib.exists">
|
||||||
<fail unless="antlr.tool.exists" message="ANTLR tool not found: ${antlr.tool.jar}"/>
|
<mkdir dir="lib"/>
|
||||||
<echo>Generating files using ${antlr.tool.jar}</echo>
|
<get src="http://archive.apache.org/dist/jakarta/bcel/binaries/bcel-5.2.tar.gz" dest="lib/bcel-5.2.tar.gz"/>
|
||||||
<java classpath="${antlr.tool.jar}"
|
<gunzip src="lib/bcel-5.2.tar.gz" dest="lib/bcel-5.2.tar"/>
|
||||||
classname="org.antlr.Tool"
|
<untar src="lib/bcel-5.2.tar" dest="lib" overwrite="true">
|
||||||
dir="${grammar.dir}"
|
<patternset>
|
||||||
fork="true"
|
<include name="**/*.jar"/>
|
||||||
failonerror="true">
|
</patternset>
|
||||||
<arg line="${grammar.name}.g"/>
|
<mapper type="flatten"/>
|
||||||
</java>
|
</untar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile" depends="wtk-or-fail">
|
<target name="compile" depends="wtk-or-fail,bcel-lib">
|
||||||
<mkdir dir="build/core/src"/>
|
<mkdir dir="build/core/src"/>
|
||||||
<mkdir dir="build/core/classes"/>
|
<mkdir dir="build/core/classes"/>
|
||||||
<mkdir dir="build/jme/classes"/>
|
<mkdir dir="build/jme/classes"/>
|
||||||
<mkdir dir="build/jse/classes"/>
|
<mkdir dir="build/jse/classes"/>
|
||||||
<copy todir="build/core/src">
|
<copy todir="build/core/src">
|
||||||
<fileset dir="src/core"/>
|
<fileset dir="src/core">
|
||||||
|
<include name="**/Lua.java"/>
|
||||||
|
</fileset>
|
||||||
<filterchain>
|
<filterchain>
|
||||||
<tokenfilter>
|
<tokenfilter>
|
||||||
<replacestring from='"Luaj 0.0"' to='"Luaj ${version}"'/>
|
<replacestring from='"Luaj 0.0"' to='"Luaj ${version}"'/>
|
||||||
</tokenfilter>
|
</tokenfilter>
|
||||||
</filterchain>
|
</filterchain>
|
||||||
</copy>
|
</copy>
|
||||||
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs">
|
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||||
<src path="build/core/src"/>
|
srcdir="src/core"/>
|
||||||
</javac>
|
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||||
<javac destdir="build/jme/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs">
|
classpath="build/core/classes"
|
||||||
<classpath path="build/core/classes"/>
|
srcdir="build/core/src"
|
||||||
<src path="src/jme"/>
|
excludes="**/Lua.java"/>
|
||||||
</javac>
|
<javac destdir="build/jme/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5">
|
classpath="build/core/classes"
|
||||||
<classpath path="build/core/classes;${antlr.runtime.jar}"/>
|
srcdir="src/jme"/>
|
||||||
<src path="src/jse"/>
|
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5"
|
||||||
</javac>
|
classpath="build/core/classes;lib/bcel-5.2.jar"
|
||||||
|
srcdir="src/jse"
|
||||||
|
excludes="**/antlr/**,**/lst/**,**/JavaCodeGenerator.java" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar-jme" depends="compile">
|
<target name="jar-jme" depends="compile">
|
||||||
@@ -107,6 +113,9 @@
|
|||||||
<copy todir="build/luaj-${version}/src">
|
<copy todir="build/luaj-${version}/src">
|
||||||
<fileset dir="src">
|
<fileset dir="src">
|
||||||
<exclude name="src/test/**"/>
|
<exclude name="src/test/**"/>
|
||||||
|
<exclude name="**/antlr/**"/>
|
||||||
|
<exclude name="**/lst/**"/>
|
||||||
|
<exclude name="**/JavaCodeGenerator.java"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</copy>
|
</copy>
|
||||||
<copy todir="build/luaj-${version}/test">
|
<copy todir="build/luaj-${version}/test">
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import org.luaj.vm2.Lua;
|
import org.luaj.vm2.Lua;
|
||||||
import org.luaj.vm2.compiler.DumpState;
|
import org.luaj.vm2.compiler.DumpState;
|
||||||
import org.luaj.vm2.luajc.antlr.AntlrLuaJCompiler;
|
import org.luaj.vm2.luajc.JavaBytecodeCompiler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,7 +41,6 @@ public class luajc {
|
|||||||
"usage: java -cp luaj-jse.jar,antlr-3.1.3.jar luajc [options] [filenames].\n" +
|
"usage: java -cp luaj-jse.jar,antlr-3.1.3.jar luajc [options] [filenames].\n" +
|
||||||
"Available options are:\n" +
|
"Available options are:\n" +
|
||||||
" - process stdin\n" +
|
" - process stdin\n" +
|
||||||
" -l list\n" +
|
|
||||||
" -o name output to file 'name' (default is \"luac.out\")\n" +
|
" -o name output to file 'name' (default is \"luac.out\")\n" +
|
||||||
" -p parse only\n" +
|
" -p parse only\n" +
|
||||||
" -s strip debug information\n" +
|
" -s strip debug information\n" +
|
||||||
@@ -55,7 +54,6 @@ public class luajc {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean list = false;
|
|
||||||
private String output = "luacj.out";
|
private String output = "luacj.out";
|
||||||
private boolean parseonly = false;
|
private boolean parseonly = false;
|
||||||
private boolean stripdebug = false;
|
private boolean stripdebug = false;
|
||||||
@@ -80,9 +78,6 @@ public class luajc {
|
|||||||
// input file - defer to next stage
|
// input file - defer to next stage
|
||||||
} else {
|
} else {
|
||||||
switch ( args[i].charAt(1) ) {
|
switch ( args[i].charAt(1) ) {
|
||||||
case 'l':
|
|
||||||
list = true;
|
|
||||||
break;
|
|
||||||
case 'o':
|
case 'o':
|
||||||
if ( ++i >= args.length )
|
if ( ++i >= args.length )
|
||||||
usageExit();
|
usageExit();
|
||||||
@@ -157,16 +152,12 @@ public class luajc {
|
|||||||
private void processScript( InputStream script, String chunkname, OutputStream out ) throws IOException {
|
private void processScript( InputStream script, String chunkname, OutputStream out ) throws IOException {
|
||||||
try {
|
try {
|
||||||
// create the chunk
|
// create the chunk
|
||||||
String source = AntlrLuaJCompiler.compile(script, chunkname);
|
byte[] bytes = JavaBytecodeCompiler.loadClass(script, chunkname);
|
||||||
|
|
||||||
// list the chunk
|
|
||||||
if (list)
|
|
||||||
System.out.println(source);
|
|
||||||
|
|
||||||
// write out the chunk
|
// write out the chunk
|
||||||
if (!parseonly) {
|
if (!parseonly) {
|
||||||
FileOutputStream fos = new FileOutputStream( chunkname+".java" );
|
FileOutputStream fos = new FileOutputStream( chunkname+".java" );
|
||||||
fos.write( source.getBytes() );
|
fos.write( bytes );
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,15 +74,17 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
|||||||
return luac.compile(firstByte, stream, chunkname);
|
return luac.compile(firstByte, stream, chunkname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Compile and load a chunk
|
||||||
|
* @throws IOException */
|
||||||
|
public static byte[] loadClass(InputStream is, String filename) throws IOException {
|
||||||
|
return getInstance().loadClass( is.read(), is, filename );
|
||||||
|
}
|
||||||
|
|
||||||
/** Compile into class form. */
|
/** Compile into class form. */
|
||||||
public LuaFunction load(int firstByte, InputStream stream, String filename, LuaValue env) throws IOException {
|
public LuaFunction load(int firstByte, InputStream stream, String filename, LuaValue env) throws IOException {
|
||||||
Prototype p = compile( firstByte, stream, filename);
|
Prototype p = compile( firstByte, stream, filename);
|
||||||
try {
|
try {
|
||||||
String classname = filename.endsWith(".lua")? filename.substring(0,filename.length()-4): filename;
|
Class c = gen.toJavaBytecode(p, toClassname(filename), toSourcename(filename));
|
||||||
classname = classname.replace('/', '.');
|
|
||||||
classname = classname.replace('\\', '.');
|
|
||||||
String sourcename = filename.substring( filename.lastIndexOf('/')+1 );
|
|
||||||
Class c = gen.toJavaBytecode(p, classname, sourcename);
|
|
||||||
Object o = c.newInstance();
|
Object o = c.newInstance();
|
||||||
LuaFunction f = (LuaFunction) o;
|
LuaFunction f = (LuaFunction) o;
|
||||||
f.setfenv(env);
|
f.setfenv(env);
|
||||||
@@ -91,7 +93,24 @@ public class JavaBytecodeCompiler implements LuaCompiler {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return new LuaClosure( p, env );
|
return new LuaClosure( p, env );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compile into a class */
|
||||||
|
private byte[] loadClass(int firstByte, InputStream stream, String filename) throws IOException {
|
||||||
|
Prototype p = compile(firstByte, stream, filename);
|
||||||
|
return gen.generateBytecode(p, toClassname(filename), toSourcename(filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Convert filename to class name */
|
||||||
|
private static final String toClassname( String filename ) {
|
||||||
|
String classname = filename.endsWith(".lua")? filename.substring(0,filename.length()-4): filename;
|
||||||
|
classname = classname.replace('/', '.');
|
||||||
|
classname = classname.replace('\\', '.');
|
||||||
|
return classname;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String toSourcename( String filename ) {
|
||||||
|
return filename.substring( filename.lastIndexOf('/')+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package org.luaj.vm2.luajc;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import org.apache.bcel.Constants;
|
import org.apache.bcel.Constants;
|
||||||
import org.apache.bcel.classfile.Field;
|
import org.apache.bcel.classfile.Field;
|
||||||
@@ -60,8 +61,6 @@ import org.luaj.vm2.Prototype;
|
|||||||
import org.luaj.vm2.Varargs;
|
import org.luaj.vm2.Varargs;
|
||||||
import org.luaj.vm2.lib.VarArgFunction;
|
import org.luaj.vm2.lib.VarArgFunction;
|
||||||
|
|
||||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;
|
|
||||||
|
|
||||||
|
|
||||||
public class JavaBytecodeGenerator {
|
public class JavaBytecodeGenerator {
|
||||||
public static boolean DUMPCLASSES = "true".equals(System.getProperty("DUMPCLASSES"));
|
public static boolean DUMPCLASSES = "true".equals(System.getProperty("DUMPCLASSES"));
|
||||||
@@ -164,7 +163,7 @@ public class JavaBytecodeGenerator {
|
|||||||
return (i >> 14) & 0x1ff;
|
return (i >> 14) & 0x1ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] generateBytecode(Prototype p, String classname, String filename)
|
byte[] generateBytecode(Prototype p, String classname, String filename)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
// compile our class next
|
// compile our class next
|
||||||
@@ -211,6 +210,7 @@ public class JavaBytecodeGenerator {
|
|||||||
k[i].getName(), k[i].getType()));
|
k[i].getName(), k[i].getType()));
|
||||||
break;
|
break;
|
||||||
case LuaValue.TSTRING:
|
case LuaValue.TSTRING:
|
||||||
|
// TODO: quote non-utf8 byte sequences
|
||||||
il.append(new PUSH(cp, ki.toString()));
|
il.append(new PUSH(cp, ki.toString()));
|
||||||
il.append(factory.createInvoke(STR_LUASTRING, "valueOf",
|
il.append(factory.createInvoke(STR_LUASTRING, "valueOf",
|
||||||
TYPE_LUASTRING, new Type[] { Type.STRING },
|
TYPE_LUASTRING, new Type[] { Type.STRING },
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import javax.tools.ToolProvider;
|
|||||||
import javax.tools.JavaCompiler.CompilationTask;
|
import javax.tools.JavaCompiler.CompilationTask;
|
||||||
|
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.luajc.antlr.AntlrLuaJCompiler;
|
|
||||||
|
|
||||||
public class LuaJCompiler {
|
public class LuaJCompiler {
|
||||||
|
|
||||||
@@ -47,7 +46,8 @@ public class LuaJCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String compileToJava( InputStream luaSource, String chunkName ) throws Exception {
|
public static String compileToJava( InputStream luaSource, String chunkName ) throws Exception {
|
||||||
return AntlrLuaJCompiler.compile( luaSource, chunkName );
|
// return AntlrLuaJCompiler.compile( luaSource, chunkName );
|
||||||
|
throw new RuntimeException( "not supported" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
# on the way to version 2.0
|
# on the way to version 2.0
|
||||||
version: 1.9.50
|
version: 1.9.51
|
||||||
|
|||||||
Reference in New Issue
Block a user