Convert to java 1.3 source style and enable all classes to be built using java class version 1.1

This commit is contained in:
James Roseborough
2007-10-10 03:53:22 +00:00
parent 8eab291c9b
commit 710f13dafc
7 changed files with 56 additions and 59 deletions

View File

@@ -1,12 +1,12 @@
#Tue Jul 03 19:42:15 PDT 2007 #Tue Oct 09 20:37:03 PDT 2007
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.compliance=1.3
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
org.eclipse.jdt.core.compiler.source=1.5 org.eclipse.jdt.core.compiler.source=1.3

View File

@@ -1,3 +0,0 @@
#Sat Jun 16 07:29:29 PDT 2007
eclipse.preferences.version=1
internal.default.compliance=default

View File

@@ -7,12 +7,10 @@
<target name="compile"> <target name="compile">
<mkdir dir="build/classes"/> <mkdir dir="build/classes"/>
<javac destdir="build/classes" encoding="utf-8" source="1.3" target="1.1"> <javac destdir="build/classes" encoding="utf-8" source="1.3" target="1.1"
classpath="lib/commons-cli-1.1.jar" >
<src path="src/main/java"/> <src path="src/main/java"/>
<src path="src/addon/java"/> <src path="src/addon/java"/>
<exclude name="lua/debug/**"/>
<exclude name="lua/LuaJVM.java"/>
<exclude name="lua/addon/luajava/**"/>
</javac> </javac>
</target> </target>

View File

@@ -17,7 +17,7 @@ public class CoerceJavaToLua {
public LValue coerce( Object javaValue ); public LValue coerce( Object javaValue );
}; };
private static Map<Class,Coercion> COERCIONS = new HashMap<Class,Coercion>(); private static Map COERCIONS = new HashMap();
static { static {
Coercion boolCoercion = new Coercion() { Coercion boolCoercion = new Coercion() {
@@ -56,7 +56,7 @@ public class CoerceJavaToLua {
if ( o == null ) if ( o == null )
return LNil.NIL; return LNil.NIL;
Class clazz = o.getClass(); Class clazz = o.getClass();
Coercion c = COERCIONS.get( clazz ); Coercion c = (Coercion) COERCIONS.get( clazz );
if ( c != null ) if ( c != null )
return c.coerce( o ); return c.coerce( o );
return new LInstance( o, o.getClass() ); return new LInstance( o, o.getClass() );

View File

@@ -19,7 +19,7 @@ public class CoerceLuaToJava {
public int score( LValue value ); public int score( LValue value );
}; };
private static Map<Class,Coercion> COERCIONS = new HashMap<Class,Coercion>(); private static Map COERCIONS = new HashMap();
private static Coercion OBJECT_COERCION; private static Coercion OBJECT_COERCION;
static { static {
@@ -112,7 +112,7 @@ public class CoerceLuaToJava {
} }
static Object coerceArg(LValue v, Class type) { static Object coerceArg(LValue v, Class type) {
Coercion co = COERCIONS.get( type ); Coercion co = (Coercion) COERCIONS.get( type );
if ( co != null ) if ( co != null )
return co.coerce( v ); return co.coerce( v );
if ( v instanceof LUserData ) if ( v instanceof LUserData )
@@ -144,7 +144,7 @@ public class CoerceLuaToJava {
for ( int i=0; i<nargs && i<njava; i++ ) { for ( int i=0; i<nargs && i<njava; i++ ) {
LValue a = suppliedArgs[i]; LValue a = suppliedArgs[i];
Class c = paramTypes[i]; Class c = paramTypes[i];
Coercion co = COERCIONS.get( c ); Coercion co = (Coercion) COERCIONS.get( c );
if ( co != null ) { if ( co != null ) {
score += co.score( a ); score += co.score( a );
} else if ( a instanceof LUserData ) { } else if ( a instanceof LUserData ) {

View File

@@ -146,7 +146,7 @@ public final class LuaJava extends LFunction {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override
public boolean luaStackCall(VM vm) { public boolean luaStackCall(VM vm) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return super.luaStackCall(vm); return super.luaStackCall(vm);
@@ -185,41 +185,42 @@ public final class LuaJava extends LFunction {
} }
} }
private static Map<Class,Map<ParamsList,Constructor>> consCache = private static Map consCache =
new HashMap<Class,Map<ParamsList,Constructor>>(); new HashMap();
private static Map<Class,Map<Integer,List<Constructor>>> consIndex = private static Map consIndex =
new HashMap<Class,Map<Integer,List<Constructor>>>(); new HashMap();
private static Constructor resolveConstructor(Class clazz, ParamsList params ) { private static Constructor resolveConstructor(Class clazz, ParamsList params ) {
// get the cache // get the cache
Map<ParamsList,Constructor> cache = consCache.get( clazz ); Map cache = (Map) consCache.get( clazz );
if ( cache == null ) if ( cache == null )
consCache.put( clazz, cache = new HashMap<ParamsList,Constructor>() ); consCache.put( clazz, cache = new HashMap() );
// look up in the cache // look up in the cache
Constructor c = cache.get( params ); Constructor c = (Constructor) cache.get( params );
if ( c != null ) if ( c != null )
return c; return c;
// get index // get index
Map<Integer,List<Constructor>> index = consIndex.get( clazz ); Map index = (Map) consIndex.get( clazz );
if ( index == null ) { if ( index == null ) {
consIndex.put( clazz, index = new HashMap<Integer,List<Constructor>>() ); consIndex.put( clazz, index = new HashMap() );
Constructor[] cons = clazz.getConstructors(); Constructor[] cons = clazz.getConstructors();
for ( Constructor con : cons ) { for ( int i=0; i<cons.length; i++ ) {
int n = con.getParameterTypes().length; Constructor con = cons[i];
List<Constructor> list = index.get(n); Integer n = Integer.valueOf( con.getParameterTypes().length );
List list = (List) index.get(n);
if ( list == null ) if ( list == null )
index.put( n, list = new ArrayList<Constructor>() ); index.put( n, list = new ArrayList() );
list.add( con ); list.add( con );
} }
} }
// figure out best list of arguments == supplied args // figure out best list of arguments == supplied args
int n = params.classes.length; Integer n = Integer.valueOf( params.classes.length );
List<Constructor> list = index.get(n); List list = (List) index.get(n);
if ( list == null ) if ( list == null )
throw new IllegalArgumentException("no constructor with "+n+" args"); throw new IllegalArgumentException("no constructor with "+n+" args");
@@ -227,7 +228,7 @@ public final class LuaJava extends LFunction {
int bests = Integer.MAX_VALUE; int bests = Integer.MAX_VALUE;
int besti = 0; int besti = 0;
for ( int i=0, size=list.size(); i<size; i++ ) { for ( int i=0, size=list.size(); i<size; i++ ) {
Constructor con = list.get(i); Constructor con = (Constructor) list.get(i);
int s = CoerceLuaToJava.scoreParamTypes(params.values, con.getParameterTypes()); int s = CoerceLuaToJava.scoreParamTypes(params.values, con.getParameterTypes());
if ( s < bests ) { if ( s < bests ) {
bests = s; bests = s;
@@ -236,57 +237,58 @@ public final class LuaJava extends LFunction {
} }
// put into cache // put into cache
c = list.get(besti); c = (Constructor) list.get(besti);
cache.put( params, c ); cache.put( params, c );
return c; return c;
} }
private static Map<Class,Map<String,Map<ParamsList,Method>>> methCache = private static Map methCache =
new HashMap<Class,Map<String,Map<ParamsList,Method>>>(); new HashMap();
private static Map<Class,Map<String,Map<Integer,List<Method>>>> methIndex = private static Map methIndex =
new HashMap<Class,Map<String,Map<Integer,List<Method>>>>(); new HashMap();
private static Method resolveMethod(Class clazz, String methodName, ParamsList params ) { private static Method resolveMethod(Class clazz, String methodName, ParamsList params ) {
// get the cache // get the cache
Map<String,Map<ParamsList,Method>> nameCache = methCache.get( clazz ); Map nameCache = (Map) methCache.get( clazz );
if ( nameCache == null ) if ( nameCache == null )
methCache.put( clazz, nameCache = new HashMap<String,Map<ParamsList,Method>>() ); methCache.put( clazz, nameCache = new HashMap() );
Map<ParamsList,Method> cache = nameCache.get( methodName ); Map cache = (Map) nameCache.get( methodName );
if ( cache == null ) if ( cache == null )
nameCache.put( methodName, cache = new HashMap<ParamsList,Method>() ); nameCache.put( methodName, cache = new HashMap() );
// look up in the cache // look up in the cache
Method m = cache.get( params ); Method m = (Method) cache.get( params );
if ( m != null ) if ( m != null )
return m; return m;
// get index // get index
Map<String,Map<Integer,List<Method>>> index = methIndex.get( clazz ); Map index = (Map) methIndex.get( clazz );
if ( index == null ) { if ( index == null ) {
methIndex.put( clazz, index = new HashMap<String,Map<Integer,List<Method>>>() ); methIndex.put( clazz, index = new HashMap() );
Method[] meths = clazz.getMethods(); Method[] meths = clazz.getMethods();
for ( Method meth : meths ) { for ( int i=0; i<meths.length; i++ ) {
Method meth = meths[i];
String s = meth.getName(); String s = meth.getName();
int n = meth.getParameterTypes().length; Integer n = Integer.valueOf(meth.getParameterTypes().length);
Map<Integer,List<Method>> map = index.get(s); Map map = (Map) index.get(s);
if ( map == null ) if ( map == null )
index.put( s, map = new HashMap<Integer,List<Method>>() ); index.put( s, map = new HashMap() );
List<Method> list = map.get(n); List list = (List) map.get(n);
if ( list == null ) if ( list == null )
map.put( n, list = new ArrayList<Method>() ); map.put( n, list = new ArrayList() );
list.add( meth ); list.add( meth );
} }
} }
// figure out best list of arguments == supplied args // figure out best list of arguments == supplied args
Map<Integer,List<Method>> map = index.get(methodName); Map map = (Map) index.get(methodName);
if ( map == null ) if ( map == null )
throw new IllegalArgumentException("no method named '"+methodName+"'"); throw new IllegalArgumentException("no method named '"+methodName+"'");
int n = params.classes.length; Integer n = Integer.valueOf( params.classes.length );
List<Method> list = map.get(n); List list = (List) map.get(n);
if ( list == null ) if ( list == null )
throw new IllegalArgumentException("no method named '"+methodName+"' with "+n+" args"); throw new IllegalArgumentException("no method named '"+methodName+"' with "+n+" args");
@@ -294,7 +296,7 @@ public final class LuaJava extends LFunction {
int bests = Integer.MAX_VALUE; int bests = Integer.MAX_VALUE;
int besti = 0; int besti = 0;
for ( int i=0, size=list.size(); i<size; i++ ) { for ( int i=0, size=list.size(); i<size; i++ ) {
Method meth = list.get(i); Method meth = (Method) list.get(i);
int s = CoerceLuaToJava.scoreParamTypes(params.values, meth.getParameterTypes()); int s = CoerceLuaToJava.scoreParamTypes(params.values, meth.getParameterTypes());
if ( s < bests ) { if ( s < bests ) {
bests = s; bests = s;
@@ -303,7 +305,7 @@ public final class LuaJava extends LFunction {
} }
// put into cache // put into cache
m = list.get(besti); m = (Method) list.get(besti);
cache.put( params, m ); cache.put( params, m );
return m; return m;
} }

View File

@@ -39,7 +39,7 @@ public class LoadStateTest extends TestCase {
long bits = Double.doubleToLongBits( v ); long bits = Double.doubleToLongBits( v );
LNumber luaNumber = LoadState.longBitsToLuaNumber( bits ); LNumber luaNumber = LoadState.longBitsToLuaNumber( bits );
assertEquals( v, luaNumber.luaAsDouble() ); assertEquals( v, luaNumber.luaAsDouble(), 0 );
if ( v != Integer.MIN_VALUE ) { if ( v != Integer.MIN_VALUE ) {
// Special case of MIN_VALUE is probably not worth dealing with. // Special case of MIN_VALUE is probably not worth dealing with.