Small improvements

This commit is contained in:
konsoletyper 2014-02-24 15:00:30 +04:00
parent 68f9376242
commit 7782f1edb7
7 changed files with 79 additions and 8 deletions

View File

@ -30,6 +30,7 @@ public class JCLPlugin implements JavascriptBuilderPlugin {
public void install(JavascriptBuilderHost host) { public void install(JavascriptBuilderHost host) {
host.add(new EnumDependencySupport()); host.add(new EnumDependencySupport());
host.add(new EnumTransformer()); host.add(new EnumTransformer());
host.add(new ClassLookupDependencySupport());
host.add(new NewInstanceDependencySupport()); host.add(new NewInstanceDependencySupport());
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader()); ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
host.add(serviceLoaderSupp); host.add(serviceLoaderSupp);

View File

@ -53,10 +53,14 @@ public class TDouble extends TNumber {
return new TDouble(d); return new TDouble(d);
} }
public static TString toString(double d) {
return TString.wrap(new TStringBuilder().append(d).toString());
}
@Override @Override
@Rename("toString") @Rename("toString")
public TString toString0() { public TString toString0() {
return TString.wrap(new TStringBuilder().append(value).toString()); return toString(value);
} }
@Override @Override

View File

@ -16,12 +16,61 @@
package org.teavm.classlib.java.lang; package org.teavm.classlib.java.lang;
import org.teavm.javascript.ni.GeneratedBy; import org.teavm.javascript.ni.GeneratedBy;
import org.teavm.javascript.ni.Rename;
/** /**
* *
* @author Alexey Andreev * @author Alexey Andreev
*/ */
public class TFloat { public class TFloat extends TNumber {
private float value;
public TFloat(float value) {
this.value = value;
}
@Override
public int intValue() {
return (int)value;
}
@Override
public long longValue() {
return (long)value;
}
@Override
public float floatValue() {
return value;
}
@Override
public double doubleValue() {
return value;
}
public static TFloat valueOf(float d) {
return new TFloat(d);
}
public static TString toString(float d) {
return TString.wrap(new TStringBuilder().append(d).toString());
}
@Override
@Rename("toString")
public TString toString0() {
return toString(value);
}
@Override
public boolean equals(TObject other) {
if (this == other) {
return true;
}
return other instanceof TFloat && ((TFloat)other).value == value;
}
@GeneratedBy(FloatNativeGenerator.class) @GeneratedBy(FloatNativeGenerator.class)
public static native boolean isNaN(float v); public static native boolean isNaN(float v);

View File

@ -52,10 +52,14 @@ public class TLong extends TNumber {
return value; return value;
} }
public TString toString(long value) {
return TString.wrap(new TStringBuilder().append(value).toString());
}
@Override @Override
@Rename("toString") @Rename("toString")
public TString toString0() { public TString toString0() {
return TString.wrap(new TStringBuilder().append(value).toString()); return toString(value);
} }
@Override @Override

View File

@ -168,7 +168,7 @@ public class DependencyChecker implements DependencyInfo {
return methodCache.map(methodRef); return methodCache.map(methodRef);
} }
public void initClass(String className, DependencyStack stack) { public void initClass(String className, final DependencyStack stack) {
classStacks.putIfAbsent(className, stack); classStacks.putIfAbsent(className, stack);
MethodDescriptor clinitDesc = new MethodDescriptor("<clinit>", ValueType.VOID); MethodDescriptor clinitDesc = new MethodDescriptor("<clinit>", ValueType.VOID);
while (className != null) { while (className != null) {
@ -183,9 +183,13 @@ public class DependencyChecker implements DependencyInfo {
return; return;
} }
if (cls.getMethod(clinitDesc) != null) { if (cls.getMethod(clinitDesc) != null) {
MethodReference methodRef = new MethodReference(className, clinitDesc); final MethodReference methodRef = new MethodReference(className, clinitDesc);
executor.executeFast(new Runnable() {
@Override public void run() {
linkMethod(methodRef, new DependencyStack(methodRef, stack)).use(); linkMethod(methodRef, new DependencyStack(methodRef, stack)).use();
} }
});
}
className = cls.getParent(); className = cls.getParent();
} }
} }

View File

@ -307,6 +307,7 @@ class DependencyGraphBuilder {
FieldDependency fieldDep = dependencyChecker.linkField(field, callerStack); FieldDependency fieldDep = dependencyChecker.linkField(field, callerStack);
DependencyNode receiverNode = nodes[receiver.getIndex()]; DependencyNode receiverNode = nodes[receiver.getIndex()];
fieldDep.getValue().connect(receiverNode); fieldDep.getValue().connect(receiverNode);
initClass(field.getClassName());
} }
@Override @Override
@ -314,6 +315,7 @@ class DependencyGraphBuilder {
FieldDependency fieldDep = dependencyChecker.linkField(field, callerStack); FieldDependency fieldDep = dependencyChecker.linkField(field, callerStack);
DependencyNode valueNode = nodes[value.getIndex()]; DependencyNode valueNode = nodes[value.getIndex()];
valueNode.connect(fieldDep.getValue()); valueNode.connect(fieldDep.getValue());
initClass(field.getClassName());
} }
@Override @Override
@ -387,6 +389,7 @@ class DependencyGraphBuilder {
if (methodDep.getResult() != null && receiver != null) { if (methodDep.getResult() != null && receiver != null) {
methodDep.getResult().connect(nodes[receiver.getIndex()]); methodDep.getResult().connect(nodes[receiver.getIndex()]);
} }
initClass(method.getClassName());
} }
private void invokeVirtual(VariableReader receiver, VariableReader instance, MethodReference method, private void invokeVirtual(VariableReader receiver, VariableReader instance, MethodReference method,
@ -412,8 +415,12 @@ class DependencyGraphBuilder {
} }
@Override @Override
public void initClass(String className) { public void initClass(final String className) {
useRunners.add(new Runnable() {
@Override public void run() {
dependencyChecker.initClass(className, callerStack); dependencyChecker.initClass(className, callerStack);
} }
});
}
}; };
} }

View File

@ -101,6 +101,7 @@ public class JavascriptBuilder implements JavascriptBuilderHost {
} }
JavascriptEntryPoint entryPoint = new JavascriptEntryPoint(name, ref, JavascriptEntryPoint entryPoint = new JavascriptEntryPoint(name, ref,
dependencyChecker.linkMethod(ref, DependencyStack.ROOT)); dependencyChecker.linkMethod(ref, DependencyStack.ROOT));
dependencyChecker.initClass(ref.getClassName(), DependencyStack.ROOT);
entryPoints.put(name, entryPoint); entryPoints.put(name, entryPoint);
return entryPoint; return entryPoint;
} }
@ -110,6 +111,7 @@ public class JavascriptBuilder implements JavascriptBuilderHost {
throw new IllegalArgumentException("Class with public name `" + name + "' already defined for class " + throw new IllegalArgumentException("Class with public name `" + name + "' already defined for class " +
className); className);
} }
dependencyChecker.initClass(className, DependencyStack.ROOT);
exportedClasses.put(name, className); exportedClasses.put(name, className);
} }