De-genericize sources to build jse using class file format 1.3
This commit is contained in:
75
build.xml
75
build.xml
@@ -61,51 +61,64 @@
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="wtk-or-fail,bcel-lib">
|
||||
<mkdir dir="build/core/src"/>
|
||||
<mkdir dir="build/core/classes"/>
|
||||
<delete dir="build/jme/src"/>
|
||||
<delete dir="build/jse/src"/>
|
||||
<mkdir dir="build/jme/src"/>
|
||||
<mkdir dir="build/jse/src"/>
|
||||
<mkdir dir="build/jme/classes"/>
|
||||
<mkdir dir="build/jse/classes"/>
|
||||
<copy todir="build/core/src">
|
||||
<fileset dir="src/core">
|
||||
<include name="**/Lua.java"/>
|
||||
</fileset>
|
||||
<copy todir="build/jme/src">
|
||||
<fileset dir="src/core"/>
|
||||
<fileset dir="src/jme"/>
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<replacestring from='"Luaj 0.0"' to='"Luaj ${version}"'/>
|
||||
</tokenfilter>
|
||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"luaj-jme ${version}"'/></tokenfilter>
|
||||
</filterchain>
|
||||
</copy>
|
||||
<copy todir="build/jse/src">
|
||||
<fileset dir="src/core"/>
|
||||
<filterchain>
|
||||
<tokenfilter><replacestring from='"Luaj 0.0"' to='"luaj-jme ${version}"'/></tokenfilter>
|
||||
</filterchain>
|
||||
</copy>
|
||||
<copy todir="build/jse/src">
|
||||
<fileset dir="src/jse"/>
|
||||
<filterchain>
|
||||
<tokenfilter><replacestring from='<String>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Stat>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Exp>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Name>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Block>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<TableField>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<VarExp>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Exp.VarExp>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Object,String>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Double,String>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Integer,Integer>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<Exp,Integer>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<String,byte[]>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<String,Variable>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<LuaValue,String>' to=''/></tokenfilter>
|
||||
<tokenfilter><replacestring from='<LuaString,String>' to=''/></tokenfilter>
|
||||
</filterchain>
|
||||
</copy>
|
||||
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||
srcdir="src/core"/>
|
||||
<javac destdir="build/core/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||
classpath="build/core/classes"
|
||||
srcdir="build/core/src"
|
||||
excludes="**/Lua.java"/>
|
||||
<javac destdir="build/jme/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
|
||||
classpath="build/core/classes"
|
||||
srcdir="src/jme"/>
|
||||
srcdir="build/jme/src"/>
|
||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.3" target="1.3"
|
||||
classpath="lib/bcel-5.2.jar"
|
||||
srcdir="build/jse/src"
|
||||
excludes="**/script/*,**/Lua2Java*"/>
|
||||
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5"
|
||||
classpath="build/core/classes;lib/bcel-5.2.jar"
|
||||
classpath="build/jse/classes"
|
||||
srcdir="src/jse"
|
||||
excludes="**/antlr/**,**/lst/**,**/JavaCodeGenerator.java,**/LuaJCompiler.java" />
|
||||
includes="**/script/*,**/Lua2Java*"/>
|
||||
</target>
|
||||
|
||||
<target name="jar-jme" depends="compile">
|
||||
<jar destfile="${jar.name.jme}">
|
||||
<fileset dir="build/core/classes"/>
|
||||
<fileset dir="build/jme/classes"/>
|
||||
</jar>
|
||||
<jar destfile="${jar.name.jme}" basedir="build/jme/classes"/>
|
||||
</target>
|
||||
|
||||
<target name="jar-jse" depends="compile">
|
||||
<jar destfile="${jar.name.jse}">
|
||||
<fileset dir="build/core/classes"/>
|
||||
<fileset dir="build/jme/classes"/>
|
||||
<fileset dir="build/jse/classes"/>
|
||||
<fileset dir="src/jse/">
|
||||
<include name="META-INF/**"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<jar destfile="${jar.name.jse}" basedir="build/jse/classes"/>
|
||||
</target>
|
||||
|
||||
<target name="doc">
|
||||
|
||||
@@ -81,8 +81,10 @@ public class NameResolver extends Visitor {
|
||||
|
||||
public void visit(Assign stat) {
|
||||
super.visit(stat);
|
||||
for ( VarExp v : stat.vars )
|
||||
for ( int i=0, n=stat.vars.size(); i<n; i++ ) {
|
||||
VarExp v = (VarExp) stat.vars.get(i);
|
||||
v.markHasAssignment();
|
||||
}
|
||||
}
|
||||
|
||||
public void visit(LocalAssign stat) {
|
||||
@@ -90,13 +92,13 @@ public class NameResolver extends Visitor {
|
||||
defineLocalVars( stat.names );
|
||||
int n = stat.names.size();
|
||||
int m = stat.values!=null? stat.values.size(): 0;
|
||||
boolean isvarlist = m>0 && m<n && stat.values.get(m-1).isvarargexp();
|
||||
boolean isvarlist = m>0 && m<n && ((Exp)stat.values.get(m-1)).isvarargexp();
|
||||
for ( int i=0; i<n && i<(isvarlist?m-1:m); i++ )
|
||||
if ( stat.values.get(i) instanceof Constant )
|
||||
stat.names.get(i).variable.initialValue = ((Constant) stat.values.get(i)).value;
|
||||
((Name)stat.names.get(i)).variable.initialValue = ((Constant) stat.values.get(i)).value;
|
||||
if ( !isvarlist )
|
||||
for ( int i=m; i<n; i++ )
|
||||
stat.names.get(i).variable.initialValue = LuaValue.NIL;
|
||||
((Name)stat.names.get(i)).variable.initialValue = LuaValue.NIL;
|
||||
}
|
||||
|
||||
public void visit(ParList pars) {
|
||||
@@ -108,8 +110,8 @@ public class NameResolver extends Visitor {
|
||||
}
|
||||
|
||||
protected void defineLocalVars(List<Name> names) {
|
||||
for ( Name n : names )
|
||||
defineLocalVar(n);
|
||||
for ( int i=0, n=names.size(); i<n; i++ )
|
||||
defineLocalVar((Name) names.get(i));
|
||||
}
|
||||
|
||||
protected void defineLocalVar(Name name) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class NameScope {
|
||||
validateIsNotKeyword(name);
|
||||
for ( NameScope n = this; n!=null; n=n.outerScope )
|
||||
if ( n.namedVariables.containsKey(name) )
|
||||
return n.namedVariables.get(name);
|
||||
return (Variable)n.namedVariables.get(name);
|
||||
Variable value = new Variable(name);
|
||||
this.namedVariables.put(name, value);
|
||||
return value;
|
||||
|
||||
@@ -23,7 +23,7 @@ package org.luaj.vm2.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.luaj.vm2.ast.Exp.NameExp;
|
||||
import org.luaj.vm2.ast.Exp.VarExp;
|
||||
|
||||
abstract
|
||||
public class Stat {
|
||||
@@ -49,7 +49,7 @@ public class Stat {
|
||||
return new Return(exps);
|
||||
}
|
||||
|
||||
public static Stat assignment(List<Exp.VarExp> vars, List<Exp> exps) {
|
||||
public static Stat assignment(List<VarExp> vars, List<Exp> exps) {
|
||||
return new Assign(vars,exps);
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ public class Stat {
|
||||
}
|
||||
|
||||
public static class Assign extends Stat {
|
||||
public final List<Exp.VarExp> vars;
|
||||
public final List<VarExp> vars;
|
||||
public final List<Exp> exps;
|
||||
|
||||
public Assign(List<Exp.VarExp> vars, List<Exp> exps) {
|
||||
public Assign(List<VarExp> vars, List<Exp> exps) {
|
||||
this.vars = vars;
|
||||
this.exps = exps;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class Stat {
|
||||
|
||||
public int nreturns() {
|
||||
int n = values!=null? values.size(): 0;
|
||||
if ( n>0 && values.get(n-1).isvarargexp() )
|
||||
if ( n>0 && ((Exp)values.get(n-1)).isvarargexp() )
|
||||
n = -1;
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ package org.luaj.vm2.ast;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.luaj.vm2.ast.Exp.VarExp;
|
||||
|
||||
abstract public class Visitor {
|
||||
public void visit(Chunk chunk) {
|
||||
chunk.block.accept(this);
|
||||
@@ -30,8 +32,8 @@ abstract public class Visitor {
|
||||
public void visit(Block block) {
|
||||
visit(block.scope);
|
||||
if ( block.stats != null )
|
||||
for ( Stat s: block.stats )
|
||||
s.accept(this);
|
||||
for ( int i=0, n=block.stats.size(); i<n; i++ )
|
||||
((Stat)block.stats.get(i)).accept(this);
|
||||
};
|
||||
public void visit(Stat.Assign stat) {
|
||||
visitVars(stat.vars);
|
||||
@@ -56,8 +58,8 @@ abstract public class Visitor {
|
||||
stat.ifblock.accept(this);
|
||||
if ( stat.elseifblocks != null )
|
||||
for ( int i=0, n=stat.elseifblocks.size(); i<n; i++ ) {
|
||||
stat.elseifexps.get(i).accept(this);
|
||||
stat.elseifblocks.get(i).accept(this);
|
||||
((Exp)stat.elseifexps.get(i)).accept(this);
|
||||
((Block)stat.elseifblocks.get(i)).accept(this);
|
||||
}
|
||||
if ( stat.elseblock != null )
|
||||
visit( stat.elseblock );
|
||||
@@ -147,23 +149,23 @@ abstract public class Visitor {
|
||||
}
|
||||
public void visit(TableConstructor table) {
|
||||
if( table.fields != null)
|
||||
for ( TableField f: table.fields )
|
||||
f.accept(this);
|
||||
for ( int i=0, n=table.fields.size(); i<n; i++ )
|
||||
((TableField)table.fields.get(i)).accept(this);
|
||||
}
|
||||
public void visitVars(List<Exp.VarExp> vars) {
|
||||
public void visitVars(List<VarExp> vars) {
|
||||
if ( vars != null )
|
||||
for ( Exp.VarExp v: vars )
|
||||
v.accept(this);
|
||||
for ( int i=0, n=vars.size(); i<n; i++ )
|
||||
((Exp.VarExp)vars.get(i)).accept(this);
|
||||
}
|
||||
public void visitExps(List<Exp> exps) {
|
||||
if ( exps != null )
|
||||
for ( Exp e: exps )
|
||||
e.accept(this);
|
||||
for ( int i=0, n=exps.size(); i<n; i++ )
|
||||
((Exp)exps.get(i)).accept(this);
|
||||
}
|
||||
public void visitNames(List<Name> names) {
|
||||
if ( names != null )
|
||||
for ( Name n: names )
|
||||
visit(n);
|
||||
for ( int i=0, n=names.size(); i<n; i++ )
|
||||
visit((Name) names.get(i));
|
||||
}
|
||||
public void visit(Name name) {
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
consCache.put( clazz, cache = new HashMap() );
|
||||
|
||||
// look up in the cache
|
||||
Constructor c = (Constructor) cache.get( paramssig );
|
||||
Constructor c = (Constructor) cache.get( Long.valueOf(paramssig) );
|
||||
if ( c != null )
|
||||
return c;
|
||||
|
||||
@@ -378,7 +378,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
|
||||
// put into cache
|
||||
c = cons[besti];
|
||||
cache.put( paramssig, c );
|
||||
cache.put( Long.valueOf(paramssig), c );
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
nameCache.put( methodName, cache = new HashMap() );
|
||||
|
||||
// look up in the cache
|
||||
Method m = (Method) cache.get( paramssig );
|
||||
Method m = (Method) cache.get( Long.valueOf(paramssig) );
|
||||
if ( m != null )
|
||||
return m;
|
||||
|
||||
@@ -431,7 +431,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
|
||||
// put into cache
|
||||
m = (Method) list.get(besti);
|
||||
cache.put( paramssig, m );
|
||||
cache.put( Long.valueOf(paramssig), m );
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,8 +140,8 @@ public class JavaCodeGen {
|
||||
javascope = JavaScope.newJavaScope( chunk );
|
||||
writeBodyBlock(chunk.block);
|
||||
oute("}");
|
||||
for ( String s : constantDeclarations )
|
||||
outl( s );
|
||||
for ( int i=0, n=constantDeclarations.size(); i<n; i++ )
|
||||
outl( (String) constantDeclarations.get(i) );
|
||||
subindent();
|
||||
outi("}");
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class JavaCodeGen {
|
||||
private boolean endsInReturn(Block block) {
|
||||
int n = block.stats.size();
|
||||
if ( n<=0 ) return false;
|
||||
Stat s = block.stats.get(n-1);
|
||||
Stat s = (Stat) block.stats.get(n-1);
|
||||
if ( s instanceof Return || s instanceof Break )
|
||||
return true;
|
||||
else if ( isInfiniteLoop( s ) )
|
||||
@@ -173,8 +173,8 @@ public class JavaCodeGen {
|
||||
if ( ite.elseblock == null || ! endsInReturn(ite.ifblock) || ! endsInReturn(ite.elseblock) )
|
||||
return false;
|
||||
if ( ite.elseifblocks != null )
|
||||
for ( Block b : ite.elseifblocks )
|
||||
if ( ! endsInReturn(b) )
|
||||
for ( int i=0, nb=ite.elseifblocks.size(); i<nb; i++ )
|
||||
if ( ! endsInReturn((Block) ite.elseifblocks.get(i)) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -197,11 +197,11 @@ public class JavaCodeGen {
|
||||
outl( "return NONE;" );
|
||||
break;
|
||||
case 1:
|
||||
outl( "return "+evalLuaValue(s.values.get(0))+";" );
|
||||
outl( "return "+evalLuaValue((Exp) s.values.get(0))+";" );
|
||||
break;
|
||||
default:
|
||||
if ( s.values.size()==1 && s.values.get(0).isfunccall() )
|
||||
tailCall( s.values.get(0) );
|
||||
if ( s.values.size()==1 && ((Exp) s.values.get(0)).isfunccall() )
|
||||
tailCall( (Exp) s.values.get(0) );
|
||||
else
|
||||
outl( "return "+evalListAsVarargs(s.values)+";" );
|
||||
break;
|
||||
@@ -221,25 +221,25 @@ public class JavaCodeGen {
|
||||
List<Exp> values = stat.values;
|
||||
int n = names.size();
|
||||
int m = values != null? values.size(): 0;
|
||||
boolean isvarlist = m>0 && m<n && values.get(m-1).isvarargexp();
|
||||
boolean isvarlist = m>0 && m<n && ((Exp) values.get(m-1)).isvarargexp();
|
||||
for ( int i=0; i<n && i<(isvarlist? m-1: m); i++ )
|
||||
if ( ! names.get(i).variable.isConstant() )
|
||||
singleLocalDeclareAssign(names.get(i), evalLuaValue(values.get(i)));
|
||||
if ( ! ((Name) names.get(i)).variable.isConstant() )
|
||||
singleLocalDeclareAssign((Name) names.get(i), evalLuaValue((Exp) values.get(i)));
|
||||
if ( isvarlist ) {
|
||||
String t = javascope.getJavaName(tmpJavaVar("t").variable);
|
||||
outl( "final Varargs "+t+" = "+evalVarargs(values.get(m-1))+";" );
|
||||
outl( "final Varargs "+t+" = "+evalVarargs((Exp) values.get(m-1))+";" );
|
||||
for ( int i=m-1; i<n; i++ )
|
||||
singleLocalDeclareAssign(names.get(i), t+(i==m-1? ".arg1()": ".arg("+(i-m+2)+")"));
|
||||
singleLocalDeclareAssign((Name) names.get(i), t+(i==m-1? ".arg1()": ".arg("+(i-m+2)+")"));
|
||||
|
||||
} else {
|
||||
for ( int i=m; i<n; i++ ) {
|
||||
if ( ! names.get(i).variable.isConstant() )
|
||||
singleLocalDeclareAssign(names.get(i), "NIL");
|
||||
if ( ! ((Name) names.get(i)).variable.isConstant() )
|
||||
singleLocalDeclareAssign((Name) names.get(i), "NIL");
|
||||
}
|
||||
}
|
||||
for ( int i=n; i<m; i++ ) {
|
||||
String t = javascope.getJavaName(tmpJavaVar("t").variable);
|
||||
outl( "final Varargs "+t+" = "+evalVarargs(values.get(i)) );
|
||||
outl( "final Varargs "+t+" = "+evalVarargs((Exp) values.get(i)) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,12 +264,12 @@ public class JavaCodeGen {
|
||||
private void directMultiAssign(List varsOrNames, List<Exp> values) {
|
||||
int n = varsOrNames.size();
|
||||
int m = values != null? values.size(): 0;
|
||||
boolean isvarlist = m>0 && m<n && values.get(m-1).isvarargexp();
|
||||
boolean isvarlist = m>0 && m<n && ((Exp) values.get(m-1)).isvarargexp();
|
||||
for ( int i=0; i<n && i<(isvarlist? m-1: m); i++ )
|
||||
singleVarOrNameAssign(varsOrNames.get(i), evalLuaValue(values.get(i)));
|
||||
singleVarOrNameAssign(varsOrNames.get(i), evalLuaValue((Exp) values.get(i)));
|
||||
if ( isvarlist ) {
|
||||
String vname = javascope.getJavaName(tmpJavaVar("v").variable);
|
||||
outl( "final Varargs "+vname+" = "+evalVarargs(values.get(m-1))+";" );
|
||||
outl( "final Varargs "+vname+" = "+evalVarargs((Exp) values.get(m-1))+";" );
|
||||
for ( int i=m-1; i<n; i++ )
|
||||
singleVarOrNameAssign(varsOrNames.get(i), vname+(i==m-1? ".arg1()": ".arg("+(i-m+2)+")"));
|
||||
|
||||
@@ -278,25 +278,25 @@ public class JavaCodeGen {
|
||||
singleVarOrNameAssign(varsOrNames.get(i), "NIL");
|
||||
for ( int i=n; i<m; i++ ) {
|
||||
String tmp = javascope.getJavaName(tmpJavaVar("tmp").variable);
|
||||
outl( "final Varargs "+tmp+" = "+evalVarargs(values.get(i)) );
|
||||
outl( "final Varargs "+tmp+" = "+evalVarargs((Exp) values.get(i)) );
|
||||
}
|
||||
}
|
||||
|
||||
private void tmpvarsMultiAssign(List varsOrNames, List<Exp> exps) {
|
||||
int n = varsOrNames.size();
|
||||
int m = exps != null? exps.size(): 0;
|
||||
boolean isvarlist = m>0 && m<n && exps.get(m-1).isvarargexp();
|
||||
boolean isvarlist = m>0 && m<n && ((Exp) exps.get(m-1)).isvarargexp();
|
||||
List<String> tmpnames = new ArrayList<String>();
|
||||
for ( int i=0; i<m; i++ ) {
|
||||
tmpnames.add( javascope.getJavaName(tmpJavaVar("t").variable) );
|
||||
if ( isvarlist && (i==m-1) )
|
||||
outl( "final Varargs "+tmpnames.get(i)+" = "+evalVarargs(exps.get(i))+";" );
|
||||
outl( "final Varargs "+tmpnames.get(i)+" = "+evalVarargs((Exp) exps.get(i))+";" );
|
||||
else
|
||||
outl( "final LuaValue "+tmpnames.get(i)+" = "+evalLuaValue(exps.get(i))+";" );
|
||||
outl( "final LuaValue "+tmpnames.get(i)+" = "+evalLuaValue((Exp) exps.get(i))+";" );
|
||||
}
|
||||
for ( int i=0; i<n; i++ ) {
|
||||
if ( i < (isvarlist? m-1: m) )
|
||||
singleVarOrNameAssign( varsOrNames.get(i), tmpnames.get(i) );
|
||||
singleVarOrNameAssign( varsOrNames.get(i), (String) tmpnames.get(i) );
|
||||
else if ( isvarlist )
|
||||
singleVarOrNameAssign( varsOrNames.get(i), tmpnames.get(m-1)+(i==m-1? ".arg1()": ".arg("+(i-m+2)+")") );
|
||||
else
|
||||
@@ -386,16 +386,16 @@ public class JavaCodeGen {
|
||||
int n = values!=null? values.size(): 0;
|
||||
switch ( n ) {
|
||||
case 0: return "NONE";
|
||||
case 1: return evalVarargs(values.get(0));
|
||||
case 1: return evalVarargs((Exp) values.get(0));
|
||||
default:
|
||||
case 2: case 3:
|
||||
Writer x = pushWriter();
|
||||
out( n>3? "varargsOf(new LuaValue[] {":"varargsOf(" );
|
||||
for ( int i=1; i<n; i++ )
|
||||
out( evalLuaValue(values.get(i-1))+"," );
|
||||
out( evalLuaValue((Exp) values.get(i-1))+"," );
|
||||
if ( n>3 )
|
||||
out( "}," );
|
||||
out( evalVarargs(values.get(n-1))+")" );
|
||||
out( evalVarargs((Exp) values.get(n-1))+")" );
|
||||
return popWriter(x);
|
||||
}
|
||||
}
|
||||
@@ -404,14 +404,14 @@ public class JavaCodeGen {
|
||||
|
||||
public String evalLuaValue(Exp exp) {
|
||||
Writer x = pushWriter();
|
||||
callerExpects.put(exp,1);
|
||||
callerExpects.put(exp,Integer.valueOf(1));
|
||||
exp.accept(this);
|
||||
return popWriter(x);
|
||||
}
|
||||
|
||||
public String evalVarargs(Exp exp) {
|
||||
Writer x = pushWriter();
|
||||
callerExpects.put(exp,-1);
|
||||
callerExpects.put(exp,Integer.valueOf(-1));
|
||||
exp.accept(this);
|
||||
return popWriter(x);
|
||||
}
|
||||
@@ -634,7 +634,7 @@ public class JavaCodeGen {
|
||||
|
||||
private String evalLuaStringConstant(LuaString str) {
|
||||
if ( stringConstants.containsKey(str) )
|
||||
return stringConstants.get(str);
|
||||
return (String) stringConstants.get(str);
|
||||
String declvalue = quotedStringInitializer(str);
|
||||
String javaname = javascope.createConstantName(str.tojstring());
|
||||
constantDeclarations.add( "static final LuaValue "+javaname+" = valueOf("+declvalue+");" );
|
||||
@@ -646,12 +646,12 @@ public class JavaCodeGen {
|
||||
if ( value == 0 ) return "ZERO";
|
||||
if ( value == -1 ) return "MINUSONE";
|
||||
if ( value == 1 ) return "ONE";
|
||||
if ( numberConstants.containsKey(value) )
|
||||
return numberConstants.get(value);
|
||||
if ( numberConstants.containsKey(Double.valueOf(value)) )
|
||||
return (String) numberConstants.get(Double.valueOf(value));
|
||||
String declvalue = evalNumberLiteral(value);
|
||||
String javaname = javascope.createConstantName(declvalue);
|
||||
constantDeclarations.add( "static final LuaValue "+javaname+" = valueOf("+declvalue+");" );
|
||||
numberConstants.put(value,javaname);
|
||||
numberConstants.put(Double.valueOf(value),javaname);
|
||||
return javaname;
|
||||
}
|
||||
|
||||
@@ -685,14 +685,14 @@ public class JavaCodeGen {
|
||||
}
|
||||
|
||||
public void visit(VarargsExp exp) {
|
||||
int c = callerExpects.containsKey(exp)? callerExpects.get(exp): 0;
|
||||
int c = callerExpects.containsKey(exp)? ((Integer)callerExpects.get(exp)).intValue(): 0;
|
||||
out( c==1? "$arg.arg1()": "$arg" );
|
||||
}
|
||||
|
||||
public void visit(MethodCall exp) {
|
||||
List<Exp> e = exp.args.exps;
|
||||
int n = e != null? e.size(): 0;
|
||||
int c = callerExpects.containsKey(exp)? callerExpects.get(exp): 0;
|
||||
int c = callerExpects.containsKey(exp)? ((Integer)callerExpects.get(exp)).intValue(): 0;
|
||||
if ( c == -1 )
|
||||
n = -1;
|
||||
out( evalLuaValue(exp.lhs) );
|
||||
@@ -717,9 +717,9 @@ public class JavaCodeGen {
|
||||
public void visit(FuncCall exp) {
|
||||
List<Exp> e = exp.args.exps;
|
||||
int n = e != null? e.size(): 0;
|
||||
if ( n > 0 && e.get(n-1).isvarargexp() )
|
||||
if ( n > 0 && ((Exp)e.get(n-1)).isvarargexp() )
|
||||
n = -1;
|
||||
int c = callerExpects.containsKey(exp)? callerExpects.get(exp): 0;
|
||||
int c = callerExpects.containsKey(exp)? ((Integer)callerExpects.get(exp)).intValue(): 0;
|
||||
if ( c == -1 )
|
||||
n = -1;
|
||||
out( evalLuaValue(exp.lhs) );
|
||||
@@ -754,8 +754,8 @@ public class JavaCodeGen {
|
||||
int n = args.exps.size();
|
||||
if ( n > 0 ) {
|
||||
for ( int i=1; i<n; i++ )
|
||||
out( evalLuaValue( args.exps.get(i-1) )+"," );
|
||||
out( evalVarargs( args.exps.get(n-1) ) );
|
||||
out( evalLuaValue( (Exp) args.exps.get(i-1) )+"," );
|
||||
out( evalVarargs( (Exp) args.exps.get(n-1) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -775,28 +775,28 @@ public class JavaCodeGen {
|
||||
outr("new OneArgFunction(env) {");
|
||||
addindent();
|
||||
outb("public LuaValue call("
|
||||
+declareArg(body.parlist.names.get(0))+") {");
|
||||
assignArg(body.parlist.names.get(0));
|
||||
+declareArg((Name) body.parlist.names.get(0))+") {");
|
||||
assignArg((Name) body.parlist.names.get(0));
|
||||
break;
|
||||
case 2:
|
||||
outr("new TwoArgFunction(env) {");
|
||||
addindent();
|
||||
outb("public LuaValue call("
|
||||
+declareArg(body.parlist.names.get(0))+","
|
||||
+declareArg(body.parlist.names.get(1))+") {");
|
||||
assignArg(body.parlist.names.get(0));
|
||||
assignArg(body.parlist.names.get(1));
|
||||
+declareArg((Name) body.parlist.names.get(0))+","
|
||||
+declareArg((Name) body.parlist.names.get(1))+") {");
|
||||
assignArg((Name) body.parlist.names.get(0));
|
||||
assignArg((Name) body.parlist.names.get(1));
|
||||
break;
|
||||
case 3:
|
||||
outr("new ThreeArgFunction(env) {");
|
||||
addindent();
|
||||
outb("public LuaValue call("
|
||||
+declareArg(body.parlist.names.get(0))+","
|
||||
+declareArg(body.parlist.names.get(1))+","
|
||||
+declareArg(body.parlist.names.get(2))+") {");
|
||||
assignArg(body.parlist.names.get(0));
|
||||
assignArg(body.parlist.names.get(1));
|
||||
assignArg(body.parlist.names.get(2));
|
||||
+declareArg((Name) body.parlist.names.get(0))+","
|
||||
+declareArg((Name) body.parlist.names.get(1))+","
|
||||
+declareArg((Name) body.parlist.names.get(2))+") {");
|
||||
assignArg((Name) body.parlist.names.get(0));
|
||||
assignArg((Name) body.parlist.names.get(1));
|
||||
assignArg((Name) body.parlist.names.get(2));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -804,7 +804,7 @@ public class JavaCodeGen {
|
||||
addindent();
|
||||
outb("public Varargs invoke(Varargs $arg) {");
|
||||
for ( int i=0; i<m; i++ ) {
|
||||
Name name = body.parlist.names.get(i);
|
||||
Name name = (Name) body.parlist.names.get(i);
|
||||
String value = i>0? "$arg.arg("+(i+1)+")": "$arg.arg1()";
|
||||
singleLocalDeclareAssign( name, value );
|
||||
}
|
||||
@@ -849,8 +849,8 @@ public class JavaCodeGen {
|
||||
} else {
|
||||
singleReference( stat.name.name );
|
||||
for ( int i=0; i<n-1 || (m&&i<n); i++ )
|
||||
out( ".get("+evalStringConstant(stat.name.dots.get(i))+")" );
|
||||
outr( ".set("+evalStringConstant(m? stat.name.method: stat.name.dots.get(n))+", "+value+");" );
|
||||
out( ".get("+evalStringConstant((String) stat.name.dots.get(i))+")" );
|
||||
outr( ".set("+evalStringConstant(m? (String)stat.name.method: (String)stat.name.dots.get(n))+", "+value+");" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,9 +927,9 @@ public class JavaCodeGen {
|
||||
outb("while (true) {");
|
||||
outl( javav+" = "+javaf+".invoke(varargsOf("+javas+","+javavar+"));");
|
||||
outl( "if (("+javavar+"="+javav+".arg1()).isnil()) break;");
|
||||
singleLocalDeclareAssign(stat.names.get(0),javavar);
|
||||
singleLocalDeclareAssign((Name) stat.names.get(0),javavar);
|
||||
for ( int i=1, n=stat.names.size(); i<n; i++ )
|
||||
singleLocalDeclareAssign(stat.names.get(i),javav+".arg("+(i+1)+")");
|
||||
singleLocalDeclareAssign((Name) stat.names.get(i),javav+".arg("+(i+1)+")");
|
||||
super.visit(stat.block);
|
||||
oute("}");
|
||||
}
|
||||
@@ -944,9 +944,9 @@ public class JavaCodeGen {
|
||||
if ( stat.elseifblocks != null )
|
||||
for ( int i=0, n=stat.elseifblocks.size(); i<n; i++ ) {
|
||||
subindent();
|
||||
outl( "} else if ( "+evalBoolean(stat.elseifexps.get(i))+" ) {");
|
||||
outl( "} else if ( "+evalBoolean((Exp) stat.elseifexps.get(i))+" ) {");
|
||||
addindent();
|
||||
super.visit(stat.elseifblocks.get(i));
|
||||
super.visit((Block) stat.elseifblocks.get(i));
|
||||
}
|
||||
if ( stat.elseblock != null ) {
|
||||
subindent();
|
||||
@@ -968,7 +968,7 @@ public class JavaCodeGen {
|
||||
List<TableField> keyed = new ArrayList<TableField>();
|
||||
List<TableField> list = new ArrayList<TableField>();
|
||||
for ( int i=0; i<n; i++ ) {
|
||||
TableField f = table.fields.get(i);
|
||||
TableField f = (TableField) table.fields.get(i);
|
||||
(( f.name != null || f.index != null )? keyed: list).add(f);
|
||||
}
|
||||
int nk = keyed.size();
|
||||
@@ -978,7 +978,8 @@ public class JavaCodeGen {
|
||||
// named elements
|
||||
if ( nk != 0 ) {
|
||||
out( "new LuaValue[]{");
|
||||
for ( TableField f : keyed ) {
|
||||
for ( int i=0, nf=keyed.size(); i<nf; i++ ) {
|
||||
TableField f = (TableField) keyed.get(i);
|
||||
if ( f.name != null )
|
||||
out( evalStringConstant(f.name)+"," );
|
||||
else
|
||||
@@ -991,10 +992,10 @@ public class JavaCodeGen {
|
||||
// unnamed elements
|
||||
if ( nl != 0 ) {
|
||||
out( (nk!=0? ",": "") + "new LuaValue[]{" );
|
||||
Exp last = list.get(nl-1).rhs;
|
||||
Exp last = ((TableField)list.get(nl-1)).rhs;
|
||||
boolean vlist = last.isvarargexp();
|
||||
for ( int i=0, limit=vlist? nl-1: nl; i<limit ; i++ )
|
||||
out( evalLuaValue( list.get(i).rhs )+"," );
|
||||
out( evalLuaValue( ((TableField)list.get(i)).rhs )+"," );
|
||||
out( vlist? "}, "+evalVarargs(last): "}");
|
||||
}
|
||||
out( ")" );
|
||||
|
||||
@@ -66,10 +66,12 @@ public class JavaScope extends NameScope {
|
||||
static {
|
||||
for ( int i=0; i<specials.length; i++ )
|
||||
SPECIALS.add(specials[i]);
|
||||
for ( java.lang.reflect.Field f : LibFunction.class.getFields() )
|
||||
SPECIALS.add(f.getName());
|
||||
for ( java.lang.reflect.Method m : LibFunction.class.getMethods() )
|
||||
SPECIALS.add(m.getName());
|
||||
java.lang.reflect.Field[] fields = LibFunction.class.getFields();
|
||||
for ( int i=0, n=fields.length; i<n; i++ )
|
||||
SPECIALS.add(fields[i].getName());
|
||||
java.lang.reflect.Method[] methods = LibFunction.class.getMethods();
|
||||
for ( int i=0, n=methods.length; i<n; i++ )
|
||||
SPECIALS.add(methods[i].getName());
|
||||
}
|
||||
|
||||
public int nreturns;
|
||||
@@ -100,7 +102,7 @@ public class JavaScope extends NameScope {
|
||||
final String getJavaName(Variable nv) {
|
||||
for ( JavaScope s = this; s != null; s = (JavaScope) s.outerScope )
|
||||
if ( s.astele2javaname.containsKey(nv) )
|
||||
return s.astele2javaname.get(nv);
|
||||
return (String) s.astele2javaname.get(nv);
|
||||
return allocateJavaName( nv, nv.name );
|
||||
}
|
||||
|
||||
|
||||
@@ -82,14 +82,12 @@ public class Lua2Java implements LuaCompiler {
|
||||
writer.close();
|
||||
|
||||
// set up output location
|
||||
Iterable<? extends File> dest = Arrays.asList(new File[] { new File(binDirRoot) });
|
||||
StandardJavaFileManager fm = compiler.getStandardFileManager( null, null, null);
|
||||
fm.setLocation(StandardLocation.CLASS_OUTPUT, dest);
|
||||
fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File[] { new File(binDirRoot) }));
|
||||
|
||||
// compile the file
|
||||
Iterable<? extends JavaFileObject> compilationUnits = fm.getJavaFileObjects(source);
|
||||
CompilationTask task = compiler.getTask(null, fm, null, null, null, compilationUnits);
|
||||
boolean success = task.call();
|
||||
CompilationTask task = compiler.getTask(null, fm, null, null, null, fm.getJavaFileObjects(source));
|
||||
boolean success = task.call().booleanValue();
|
||||
|
||||
// instantiate, config and return
|
||||
if (success) {
|
||||
|
||||
@@ -247,7 +247,7 @@ public class JavaBuilder {
|
||||
} else {
|
||||
// fixed arg function between 0 and 3 arguments
|
||||
for ( slot=0; slot<p.numparams; slot++ ) {
|
||||
this.plainSlotVars.put( slot, 1+slot );
|
||||
this.plainSlotVars.put( Integer.valueOf(slot), Integer.valueOf(1+slot) );
|
||||
if ( slots.isUpvalueCreate(-1, slot) ) {
|
||||
append(new ALOAD(1+slot));
|
||||
storeLocal(-1, slot);
|
||||
@@ -320,12 +320,13 @@ public class JavaBuilder {
|
||||
private Map<Integer,Integer> plainSlotVars = new HashMap<Integer,Integer>();
|
||||
private Map<Integer,Integer> upvalueSlotVars = new HashMap<Integer,Integer>();
|
||||
private int findSlot( int slot, Map<Integer,Integer> map, String prefix, Type type ) {
|
||||
if ( map.containsKey(slot) )
|
||||
return map.get(slot);
|
||||
Integer islot = Integer.valueOf(slot);
|
||||
if ( map.containsKey(islot) )
|
||||
return ((Integer)map.get(islot)).intValue();
|
||||
String name = prefix+slot;
|
||||
LocalVariableGen local = mg.addLocalVariable(name, type, null, null);
|
||||
int index = local.getIndex();
|
||||
map.put(slot, index);
|
||||
map.put(islot, Integer.valueOf(index));
|
||||
return index;
|
||||
}
|
||||
private int findSlotIndex( int slot, boolean isupvalue ) {
|
||||
@@ -620,7 +621,7 @@ public class JavaBuilder {
|
||||
break;
|
||||
case LuaValue.TNUMBER:
|
||||
case LuaValue.TSTRING:
|
||||
String name = constants.get(value);
|
||||
String name = (String) constants.get(value);
|
||||
if ( name == null ) {
|
||||
name = value.type() == LuaValue.TNUMBER?
|
||||
value.isinttype()?
|
||||
|
||||
@@ -67,7 +67,7 @@ public class JavaLoader extends ClassLoader {
|
||||
}
|
||||
|
||||
public Class findClass(String classname) throws ClassNotFoundException {
|
||||
byte[] bytes = unloaded.get(classname);
|
||||
byte[] bytes = (byte[]) unloaded.get(classname);
|
||||
if ( bytes != null )
|
||||
return defineClass(classname, bytes, 0, bytes.length);
|
||||
return super.findClass(classname);
|
||||
|
||||
Reference in New Issue
Block a user