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