Add support of strict mode

This commit is contained in:
konsoletyper 2014-10-18 15:32:43 +04:00
parent 991ca3e4a5
commit 5420ca89f6
4 changed files with 141 additions and 134 deletions

View File

@ -164,11 +164,11 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
} }
private void renderRuntimeCls() throws IOException { private void renderRuntimeCls() throws IOException {
writer.append("$rt_cls").ws().append("=").ws().append("function(clsProto)").ws().append("{") writer.append("function $rt_cls").ws().append("(clsProto)").ws().append("{")
.indent().softNewLine(); .indent().softNewLine();
String classClass = "java.lang.Class"; String classClass = "java.lang.Class";
writer.append("var cls").ws().append("=").ws().append("clsProto.classObject;").softNewLine(); writer.append("var cls").ws().append("=").ws().append("clsProto.classObject;").softNewLine();
writer.append("if").ws().append("(cls").ws().append("===").ws().append("undefined)").ws() writer.append("if").ws().append("(typeof cls").ws().append("===").ws().append("'undefined')").ws()
.append("{").softNewLine().indent(); .append("{").softNewLine().indent();
MethodReference createMethodRef = new MethodReference(classClass, "createNew", ValueType.object(classClass)); MethodReference createMethodRef = new MethodReference(classClass, "createNew", ValueType.object(classClass));
writer.append("cls").ws().append("=").ws().appendMethodBody(createMethodRef).append("();").softNewLine(); writer.append("cls").ws().append("=").ws().appendMethodBody(createMethodRef).append("();").softNewLine();
@ -199,10 +199,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
} }
private void renderRuntimeString() throws IOException { private void renderRuntimeString() throws IOException {
String stringClass = "java.lang.String"; MethodReference stringCons = new MethodReference(String.class, "<init>", char[].class, void.class);
MethodReference stringCons = new MethodReference(stringClass, "<init>", writer.append("function $rt_str(str) {").indent().softNewLine();
ValueType.arrayOf(ValueType.CHARACTER), ValueType.VOID);
writer.append("$rt_str = function(str) {").indent().softNewLine();
writer.append("var characters = $rt_createCharArray(str.length);").softNewLine(); writer.append("var characters = $rt_createCharArray(str.length);").softNewLine();
writer.append("var charsBuffer = characters.data;").softNewLine(); writer.append("var charsBuffer = characters.data;").softNewLine();
writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine(); writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine();
@ -214,11 +212,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
} }
private void renderRuntimeUnwrapString() throws IOException { private void renderRuntimeUnwrapString() throws IOException {
String stringClass = "java.lang.String"; MethodReference stringLen = new MethodReference(String.class, "length", int.class);
MethodReference stringLen = new MethodReference(stringClass, "length", ValueType.INTEGER); MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class,
MethodReference getChars = new MethodReference(stringClass, "getChars", ValueType.INTEGER, ValueType.INTEGER, char[].class, int.class, void.class);
ValueType.arrayOf(ValueType.CHARACTER), ValueType.INTEGER, ValueType.VOID); writer.append("function $rt_ustr(str) {").indent().softNewLine();
writer.append("$rt_ustr = function(str) {").indent().softNewLine();
writer.append("var result = \"\";").softNewLine(); writer.append("var result = \"\";").softNewLine();
writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine(); writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine();
writer.append("var array = $rt_createCharArray(sz);").softNewLine(); writer.append("var array = $rt_createCharArray(sz);").softNewLine();
@ -232,7 +229,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
private void renderRuntimeNullCheck() throws IOException { private void renderRuntimeNullCheck() throws IOException {
String npe = "java.lang.NullPointerException"; String npe = "java.lang.NullPointerException";
writer.append("$rt_nullCheck = function(val) {").indent().softNewLine(); writer.append("function $rt_nullCheck(val) {").indent().softNewLine();
writer.append("if (val === null) {").indent().softNewLine(); writer.append("if (val === null) {").indent().softNewLine();
writer.append("$rt_throw(").appendClass(npe).append('.').appendMethod(npe, "<init>", ValueType.VOID) writer.append("$rt_throw(").appendClass(npe).append('.').appendMethod(npe, "<init>", ValueType.VOID)
.append("());").softNewLine(); .append("());").softNewLine();
@ -242,14 +239,14 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
} }
private void renderRuntimeIntern() throws IOException { private void renderRuntimeIntern() throws IOException {
writer.append("$rt_intern = function(str) {").indent().softNewLine(); writer.append("function $rt_intern(str) {").indent().softNewLine();
writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class)) writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class))
.append("(str);").softNewLine(); .append("(str);").softNewLine();
writer.outdent().append("}").newLine(); writer.outdent().append("}").newLine();
} }
private void renderRuntimeObjcls() throws IOException { private void renderRuntimeObjcls() throws IOException {
writer.append("$rt_objcls = function() { return ").appendClass("java.lang.Object").append("; }").newLine(); writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine();
} }
public void render(ClassNode cls) throws RenderingException { public void render(ClassNode cls) throws RenderingException {

View File

@ -54,7 +54,7 @@ import org.teavm.vm.spi.TeaVMPlugin;
*vm.setMinifying(false); // optionally disable obfuscation *vm.setMinifying(false); // optionally disable obfuscation
*vm.installPlugins(); // install all default plugins *vm.installPlugins(); // install all default plugins
* // that are found in a classpath * // that are found in a classpath
*vm.addEntryPoint("main", new MethodReference( *vm.entryPoint("main", new MethodReference(
* "fully.qualified.ClassName", "main", * "fully.qualified.ClassName", "main",
* ValueType.array(ValueType.object("java.lang.String")), * ValueType.array(ValueType.object("java.lang.String")),
* ValueType.VOID)); * ValueType.VOID));
@ -434,6 +434,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
renderer.addInjector(entry.getKey(), entry.getValue()); renderer.addInjector(entry.getKey(), entry.getValue());
} }
try { try {
sourceWriter.append("\"use strict\"").newLine();
for (RendererListener listener : rendererListeners) { for (RendererListener listener : rendererListeners) {
listener.begin(renderer, target); listener.begin(renderer, target);
} }
@ -450,12 +451,12 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
} }
renderer.renderStringPool(); renderer.renderStringPool();
for (Map.Entry<String, TeaVMEntryPoint> entry : entryPoints.entrySet()) { for (Map.Entry<String, TeaVMEntryPoint> entry : entryPoints.entrySet()) {
sourceWriter.append(entry.getKey()).ws().append("=").ws().appendMethodBody(entry.getValue().reference) sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws()
.append(";").softNewLine(); .appendMethodBody(entry.getValue().reference).append(";").softNewLine();
} }
for (Map.Entry<String, String> entry : exportedClasses.entrySet()) { for (Map.Entry<String, String> entry : exportedClasses.entrySet()) {
sourceWriter.append(entry.getKey()).ws().append("=").ws().appendClass(entry.getValue()).append(";") sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws()
.softNewLine(); .appendClass(entry.getValue()).append(";").softNewLine();
} }
for (RendererListener listener : rendererListeners) { for (RendererListener listener : rendererListeners) {
listener.complete(); listener.complete();

View File

@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
$rt_lastObjectId = 0; "use strict";
$rt_nextId = function() { var $rt_lastObjectId = 0;
function $rt_nextId() {
return $rt_lastObjectId++; return $rt_lastObjectId++;
} }
$rt_compare = function(a, b) { function $rt_compare(a, b) {
return a > b ? 1 : a < b ? -1 : 0; return a > b ? 1 : a < b ? -1 : 0;
} }
$rt_isInstance = function(obj, cls) { function $rt_isInstance(obj, cls) {
return obj !== null && !!obj.constructor.$meta && $rt_isAssignable(obj.constructor, cls); return obj !== null && !!obj.constructor.$meta && $rt_isAssignable(obj.constructor, cls);
} }
$rt_isAssignable = function(from, to) { function $rt_isAssignable(from, to) {
if (from === to) { if (from === to) {
return true; return true;
} }
@ -35,7 +36,7 @@ $rt_isAssignable = function(from, to) {
} }
return false; return false;
} }
$rt_createArray = function(cls, sz) { function $rt_createArray(cls, sz) {
var data = new Array(sz); var data = new Array(sz);
var arr = new ($rt_arraycls(cls))(data); var arr = new ($rt_arraycls(cls))(data);
for (var i = 0; i < sz; i = (i + 1) | 0) { for (var i = 0; i < sz; i = (i + 1) | 0) {
@ -43,14 +44,14 @@ $rt_createArray = function(cls, sz) {
} }
return arr; return arr;
} }
$rt_wrapArray = function(cls, data) { function $rt_wrapArray(cls, data) {
var arr = new ($rt_arraycls(cls))(data); var arr = new ($rt_arraycls(cls))(data);
return arr; return arr;
} }
$rt_createUnfilledArray = function(cls, sz) { function $rt_createUnfilledArray(cls, sz) {
return new ($rt_arraycls(cls))(new Array(sz)); return new ($rt_arraycls(cls))(new Array(sz));
} }
$rt_createLongArray = function(sz) { function $rt_createLongArray(sz) {
var data = new Array(sz); var data = new Array(sz);
var arr = new ($rt_arraycls($rt_longcls()))(data); var arr = new ($rt_arraycls($rt_longcls()))(data);
for (var i = 0; i < sz; i = (i + 1) | 0) { for (var i = 0; i < sz; i = (i + 1) | 0) {
@ -58,10 +59,21 @@ $rt_createLongArray = function(sz) {
} }
return arr; return arr;
} }
var $rt_createNumericArray;
var $rt_createCharArray;
var $rt_createByteArray;
var $rt_createShortArray;
var $rt_createIntArray;
var $rt_createBooleanArray;
var $rt_createFloatArray;
var $rt_createDoubleArray;
if (ArrayBuffer) { if (ArrayBuffer) {
$rt_createNumericArray = function(cls, nativeArray) { $rt_createNumericArray = function(cls, nativeArray) {
return new ($rt_arraycls(cls))(nativeArray); return new ($rt_arraycls(cls))(nativeArray);
} };
$rt_createCharArray = function(sz) {
return $rt_createNumericArray($rt_bytecls(), new Uint16Array(new ArrayBuffer(sz << 1)), 0);
};
$rt_createByteArray = function(sz) { $rt_createByteArray = function(sz) {
return $rt_createNumericArray($rt_bytecls(), new Int8Array(new ArrayBuffer(sz)), 0); return $rt_createNumericArray($rt_bytecls(), new Int8Array(new ArrayBuffer(sz)), 0);
}; };
@ -80,17 +92,14 @@ if (ArrayBuffer) {
$rt_createDoubleArray = function(sz) { $rt_createDoubleArray = function(sz) {
return $rt_createNumericArray($rt_doublecls(), new Float64Array(new ArrayBuffer(sz << 3)), 0); return $rt_createNumericArray($rt_doublecls(), new Float64Array(new ArrayBuffer(sz << 3)), 0);
}; };
$rt_createCharArray = function(sz) {
return $rt_createNumericArray($rt_charcls(), new Uint16Array(new ArrayBuffer(sz << 1)), 0);
};
} else { } else {
$rt_createNumericArray = function(cls, sz) { $rt_createNumericArray = function(cls, sz) {
var data = new Array(sz); var data = new Array(sz);
var arr = new ($rt_arraycls(cls))(data); var arr = new ($rt_arraycls(cls))(data);
for (var i = 0; i < sz; i = (i + 1) | 0) { for (var i = 0; i < sz; i = (i + 1) | 0) {
data[i] = 0; data[i] = 0;
} }
return arr; return arr;
} }
$rt_createByteArray = function(sz) { return $rt_createNumericArray($rt_bytecls(), sz); } $rt_createByteArray = function(sz) { return $rt_createNumericArray($rt_bytecls(), sz); }
$rt_createShortArray = function(sz) { return $rt_createNumericArray($rt_shortcls(), sz); } $rt_createShortArray = function(sz) { return $rt_createNumericArray($rt_shortcls(), sz); }
@ -100,8 +109,8 @@ if (ArrayBuffer) {
$rt_createDoubleArray = function(sz) { return $rt_createNumericArray($rt_doublecls(), sz); } $rt_createDoubleArray = function(sz) { return $rt_createNumericArray($rt_doublecls(), sz); }
$rt_createCharArray = function(sz) { return $rt_createNumericArray($rt_charcls(), sz); } $rt_createCharArray = function(sz) { return $rt_createNumericArray($rt_charcls(), sz); }
} }
$rt_arraycls = function(cls) { function $rt_arraycls(cls) {
if (cls.$array == undefined) { if (typeof cls.$array === 'undefined') {
var arraycls = function(data) { var arraycls = function(data) {
this.data = data; this.data = data;
this.$id = $rt_nextId(); this.$id = $rt_nextId();
@ -124,51 +133,51 @@ $rt_arraycls = function(cls) {
} }
return cls.$array; return cls.$array;
} }
$rt_createcls = function() { function $rt_createcls() {
return { return {
$meta : { $meta : {
supertypes : [] supertypes : []
} }
}; };
} }
$rt_booleanclsCache = null; var $rt_booleanclsCache = null;
$rt_booleancls = function() { function $rt_booleancls() {
if ($rt_booleanclsCache == null) { if ($rt_booleanclsCache === null) {
$rt_booleanclsCache = $rt_createcls(); $rt_booleanclsCache = $rt_createcls();
$rt_booleanclsCache.primitive = true; $rt_booleanclsCache.primitive = true;
$rt_booleanclsCache.name = "boolean"; $rt_booleanclsCache.name = "boolean";
} }
return $rt_booleanclsCache; return $rt_booleanclsCache;
} }
$rt_charclsCache = null; var $rt_charclsCache = null;
$rt_charcls = function() { function $rt_charcls() {
if ($rt_charclsCache == null) { if ($rt_charclsCache === null) {
$rt_charclsCache = $rt_createcls(); $rt_charclsCache = $rt_createcls();
$rt_charclsCache.primitive = true; $rt_charclsCache.primitive = true;
$rt_charclsCache.name = "char"; $rt_charclsCache.name = "char";
} }
return $rt_charclsCache; return $rt_charclsCache;
} }
$rt_byteclsCache = null; var $rt_byteclsCache = null;
$rt_bytecls = function() { function $rt_bytecls() {
if ($rt_byteclsCache == null) { if ($rt_byteclsCache === null) {
$rt_byteclsCache = $rt_createcls(); $rt_byteclsCache = $rt_createcls();
$rt_byteclsCache.primitive = true; $rt_byteclsCache.primitive = true;
$rt_byteclsCache.name = "byte"; $rt_byteclsCache.name = "byte";
} }
return $rt_byteclsCache; return $rt_byteclsCache;
} }
$rt_shortclsCache = null; var $rt_shortclsCache = null;
$rt_shortcls = function() { function $rt_shortcls() {
if ($rt_shortclsCache == null) { if ($rt_shortclsCache === null) {
$rt_shortclsCache = $rt_createcls(); $rt_shortclsCache = $rt_createcls();
$rt_shortclsCache.primitive = true; $rt_shortclsCache.primitive = true;
$rt_shortclsCache.name = "short"; $rt_shortclsCache.name = "short";
} }
return $rt_shortclsCache; return $rt_shortclsCache;
} }
$rt_intclsCache = null; var $rt_intclsCache = null;
$rt_intcls = function() { function $rt_intcls() {
if ($rt_intclsCache === null) { if ($rt_intclsCache === null) {
$rt_intclsCache = $rt_createcls(); $rt_intclsCache = $rt_createcls();
$rt_intclsCache.primitive = true; $rt_intclsCache.primitive = true;
@ -176,8 +185,8 @@ $rt_intcls = function() {
} }
return $rt_intclsCache; return $rt_intclsCache;
} }
$rt_longclsCache = null; var $rt_longclsCache = null;
$rt_longcls = function() { function $rt_longcls() {
if ($rt_longclsCache === null) { if ($rt_longclsCache === null) {
$rt_longclsCache = $rt_createcls(); $rt_longclsCache = $rt_createcls();
$rt_longclsCache.primitive = true; $rt_longclsCache.primitive = true;
@ -185,8 +194,8 @@ $rt_longcls = function() {
} }
return $rt_longclsCache; return $rt_longclsCache;
} }
$rt_floatclsCache = null; var $rt_floatclsCache = null;
$rt_floatcls = function() { function $rt_floatcls() {
if ($rt_floatclsCache === null) { if ($rt_floatclsCache === null) {
$rt_floatclsCache = $rt_createcls(); $rt_floatclsCache = $rt_createcls();
$rt_floatclsCache.primitive = true; $rt_floatclsCache.primitive = true;
@ -194,8 +203,8 @@ $rt_floatcls = function() {
} }
return $rt_floatclsCache; return $rt_floatclsCache;
} }
$rt_doubleclsCache = null; var $rt_doubleclsCache = null;
$rt_doublecls = function() { function $rt_doublecls() {
if ($rt_doubleclsCache === null) { if ($rt_doubleclsCache === null) {
$rt_doubleclsCache = $rt_createcls(); $rt_doubleclsCache = $rt_createcls();
$rt_doubleclsCache.primitive = true; $rt_doubleclsCache.primitive = true;
@ -203,8 +212,8 @@ $rt_doublecls = function() {
} }
return $rt_doubleclsCache; return $rt_doubleclsCache;
} }
$rt_voidclsCache = null; var $rt_voidclsCache = null;
$rt_voidcls = function() { function $rt_voidcls() {
if ($rt_voidclsCache === null) { if ($rt_voidclsCache === null) {
$rt_voidclsCache = $rt_createcls(); $rt_voidclsCache = $rt_createcls();
$rt_voidclsCache.primitive = true; $rt_voidclsCache.primitive = true;
@ -212,7 +221,7 @@ $rt_voidcls = function() {
} }
return $rt_voidclsCache; return $rt_voidclsCache;
} }
$rt_clinit = function(cls) { function $rt_clinit(cls) {
if (cls.$clinit) { if (cls.$clinit) {
var f = cls.$clinit; var f = cls.$clinit;
delete cls.$clinit; delete cls.$clinit;
@ -220,12 +229,12 @@ $rt_clinit = function(cls) {
} }
return cls; return cls;
} }
$rt_init = function(cls, constructor, args) { function $rt_init(cls, constructor, args) {
var obj = new cls(); var obj = new cls();
cls.prototype[constructor].apply(obj, args); cls.prototype[constructor].apply(obj, args);
return obj; return obj;
} }
$rt_throw = function(ex) { function $rt_throw(ex) {
var err = ex.$jsException; var err = ex.$jsException;
if (!err) { if (!err) {
var err = new Error("Java exception thrown"); var err = new Error("Java exception thrown");
@ -234,7 +243,7 @@ $rt_throw = function(ex) {
} }
throw err; throw err;
} }
$rt_createMultiArray = function(cls, dimensions) { function $rt_createMultiArray(cls, dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -242,7 +251,7 @@ $rt_createMultiArray = function(cls, dimensions) {
} }
return $rt_createMultiArrayImpl(cls, arrays, dimensions); return $rt_createMultiArrayImpl(cls, arrays, dimensions);
} }
$rt_createByteMultiArray = function(dimensions) { function $rt_createByteMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -250,7 +259,7 @@ $rt_createByteMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_bytecls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_bytecls(), arrays, dimensions);
} }
$rt_createBooleanMultiArray = function(dimensions) { function $rt_createBooleanMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -258,7 +267,7 @@ $rt_createBooleanMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_booleancls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_booleancls(), arrays, dimensions);
} }
$rt_createShortMultiArray = function(dimensions) { function $rt_createShortMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -266,7 +275,7 @@ $rt_createShortMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_shortcls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_shortcls(), arrays, dimensions);
} }
$rt_createIntMultiArray = function(dimensions) { function $rt_createIntMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -274,7 +283,7 @@ $rt_createIntMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_intcls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_intcls(), arrays, dimensions);
} }
$rt_createLongMultiArray = function(dimensions) { function $rt_createLongMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -282,7 +291,7 @@ $rt_createLongMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_longcls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_longcls(), arrays, dimensions);
} }
$rt_createFloatMultiArray = function(dimensions) { function $rt_createFloatMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -290,7 +299,7 @@ $rt_createFloatMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_floatcls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_floatcls(), arrays, dimensions);
} }
$rt_createDoubleMultiArray = function(dimensions) { function $rt_createDoubleMultiArray(dimensions) {
var arrays = new Array($rt_primitiveArrayCount(dimensions)); var arrays = new Array($rt_primitiveArrayCount(dimensions));
var firstDim = dimensions[0] | 0; var firstDim = dimensions[0] | 0;
for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) { for (var i = 0 | 0; i < arrays.length; i = (i + 1) | 0) {
@ -298,14 +307,14 @@ $rt_createDoubleMultiArray = function(dimensions) {
} }
return $rt_createMultiArrayImpl($rt_doublecls(), arrays, dimensions); return $rt_createMultiArrayImpl($rt_doublecls(), arrays, dimensions);
} }
$rt_primitiveArrayCount = function(dimensions) { function $rt_primitiveArrayCount(dimensions) {
var val = dimensions[1] | 0; var val = dimensions[1] | 0;
for (var i = 2 | 0; i < dimensions.length; i = (i + 1) | 0) { for (var i = 2 | 0; i < dimensions.length; i = (i + 1) | 0) {
val = (val * (dimensions[i] | 0)) | 0; val = (val * (dimensions[i] | 0)) | 0;
} }
return val; return val;
} }
$rt_createMultiArrayImpl = function(cls, arrays, dimensions) { function $rt_createMultiArrayImpl(cls, arrays, dimensions) {
var limit = arrays.length; var limit = arrays.length;
for (var i = 1 | 0; i < dimensions.length; i = (i + 1) | 0) { for (var i = 1 | 0; i < dimensions.length; i = (i + 1) | 0) {
cls = $rt_arraycls(cls); cls = $rt_arraycls(cls);
@ -325,13 +334,13 @@ $rt_createMultiArrayImpl = function(cls, arrays, dimensions) {
} }
return arrays[0]; return arrays[0];
} }
$rt_assertNotNaN = function(value) { function $rt_assertNotNaN(value) {
if (typeof value == 'number' && isNaN(value)) { if (typeof value === 'number' && isNaN(value)) {
throw "NaN"; throw "NaN";
} }
return value; return value;
} }
$rt_methodStubs = function(clinit, names) { function $rt_methodStubs(clinit, names) {
for (var i = 0; i < names.length; i = (i + 1) | 0) { for (var i = 0; i < names.length; i = (i + 1) | 0) {
window[names[i]] = (function(name) { window[names[i]] = (function(name) {
return function() { return function() {
@ -341,9 +350,9 @@ $rt_methodStubs = function(clinit, names) {
})(names[i]); })(names[i]);
} }
} }
$rt_stdoutBuffer = ""; var $rt_stdoutBuffer = "";
$rt_putStdout = function(ch) { function $rt_putStdout(ch) {
if (ch === 0xA) { if (ch == 0xA) {
if (console) { if (console) {
console.info($rt_stdoutBuffer); console.info($rt_stdoutBuffer);
} }
@ -352,9 +361,9 @@ $rt_putStdout = function(ch) {
$rt_stdoutBuffer += String.fromCharCode(ch); $rt_stdoutBuffer += String.fromCharCode(ch);
} }
} }
$rt_stderrBuffer = ""; var $rt_stderrBuffer = "";
$rt_putStderr = function(ch) { function $rt_putStderr(ch) {
if (ch === 0xA) { if (ch == 0xA) {
if (console) { if (console) {
console.info($rt_stderrBuffer); console.info($rt_stderrBuffer);
} }
@ -364,7 +373,6 @@ $rt_putStderr = function(ch) {
} }
} }
function $rt_declClass(cls, data) { function $rt_declClass(cls, data) {
cls.name = data.name;
cls.$meta = {}; cls.$meta = {};
cls.$meta.superclass = data.superclass; cls.$meta.superclass = data.superclass;
cls.$meta.supertypes = data.interfaces ? data.interfaces.slice() : []; cls.$meta.supertypes = data.interfaces ? data.interfaces.slice() : [];
@ -383,7 +391,7 @@ function $rt_virtualMethods(cls) {
for (var i = 1; i < arguments.length; i += 2) { for (var i = 1; i < arguments.length; i += 2) {
var name = arguments[i]; var name = arguments[i];
var func = arguments[i + 1]; var func = arguments[i + 1];
if (typeof name == 'string') { if (typeof name === 'string') {
cls.prototype[name] = func; cls.prototype[name] = func;
} else { } else {
for (var j = 0; j < name.length; ++j) { for (var j = 0; j < name.length; ++j) {
@ -392,6 +400,7 @@ function $rt_virtualMethods(cls) {
} }
} }
} }
var $rt_stringPool_instance;
function $rt_stringPool(strings) { function $rt_stringPool(strings) {
$rt_stringPool_instance = new Array(strings.length); $rt_stringPool_instance = new Array(strings.length);
for (var i = 0; i < strings.length; ++i) { for (var i = 0; i < strings.length; ++i) {
@ -441,7 +450,7 @@ function $dbg_class(obj) {
return clsName; return clsName;
} }
Long = function(lo, hi) { function Long(lo, hi) {
this.lo = lo | 0; this.lo = lo | 0;
this.hi = hi | 0; this.hi = hi | 0;
} }
@ -461,18 +470,18 @@ Long.prototype.toString = function() {
result = result.reverse().join(''); result = result.reverse().join('');
return positive ? result : "-" + result; return positive ? result : "-" + result;
} }
Long_ZERO = new Long(0, 0); var Long_ZERO = new Long(0, 0);
Long_fromInt = function(val) { function Long_fromInt(val) {
return val >= 0 ? new Long(val, 0) : new Long(val, -1); return val >= 0 ? new Long(val, 0) : new Long(val, -1);
} }
Long_fromNumber = function(val) { function Long_fromNumber(val) {
if (val >= 0) { if (val >= 0) {
return new Long(val | 0, (val / 0x100000000) | 0); return new Long(val | 0, (val / 0x100000000) | 0);
} else { } else {
return new Long(val | 0, (-(Math.abs(val) / 0x100000000) - 1) | 0); return new Long(val | 0, (-(Math.abs(val) / 0x100000000) - 1) | 0);
} }
} }
Long_toNumber = function(val) { function Long_toNumber(val) {
var lo = val.lo; var lo = val.lo;
var hi = val.hi; var hi = val.hi;
if (lo < 0) { if (lo < 0) {
@ -480,7 +489,7 @@ Long_toNumber = function(val) {
} }
return 0x100000000 * hi + lo; return 0x100000000 * hi + lo;
} }
Long_add = function(a, b) { function Long_add(a, b) {
var a_lolo = a.lo & 0xFFFF; var a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; var a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; var a_hilo = a.hi & 0xFFFF;
@ -496,7 +505,7 @@ Long_add = function(a, b) {
var hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0; var hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0;
return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16));
} }
Long_inc = function(a) { function Long_inc(a) {
var lo = (a.lo + 1) | 0; var lo = (a.lo + 1) | 0;
var hi = a.hi; var hi = a.hi;
if (lo === 0) { if (lo === 0) {
@ -504,7 +513,7 @@ Long_inc = function(a) {
} }
return new Long(lo, hi); return new Long(lo, hi);
} }
Long_dec = function(a) { function Long_dec(a) {
var lo = (a.lo - 1) | 0; var lo = (a.lo - 1) | 0;
var hi = a.hi; var hi = a.hi;
if (lo === -1) { if (lo === -1) {
@ -512,10 +521,10 @@ Long_dec = function(a) {
} }
return new Long(lo, hi); return new Long(lo, hi);
} }
Long_neg = function(a) { function Long_neg(a) {
return Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF)); return Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF));
} }
Long_sub = function(a, b) { function Long_sub(a, b) {
var a_lolo = a.lo & 0xFFFF; var a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; var a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; var a_hilo = a.hi & 0xFFFF;
@ -531,7 +540,7 @@ Long_sub = function(a, b) {
var hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0; var hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0;
return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16));
} }
Long_compare = function(a, b) { function Long_compare(a, b) {
var r = a.hi - b.hi; var r = a.hi - b.hi;
if (r !== 0) { if (r !== 0) {
return r; return r;
@ -542,13 +551,13 @@ Long_compare = function(a, b) {
} }
return (a.lo & 1) - (b.lo & 1); return (a.lo & 1) - (b.lo & 1);
} }
Long_isPositive = function(a) { function Long_isPositive(a) {
return (a.hi & 0x80000000) === 0; return (a.hi & 0x80000000) === 0;
} }
Long_isNegative = function(a) { function Long_isNegative(a) {
return (a.hi & 0x80000000) !== 0; return (a.hi & 0x80000000) !== 0;
} }
Long_mul = function(a, b) { function Long_mul(a, b) {
var positive = Long_isNegative(a) === Long_isNegative(b); var positive = Long_isNegative(a) === Long_isNegative(b);
if (Long_isNegative(a)) { if (Long_isNegative(a)) {
a = Long_neg(a); a = Long_neg(a);
@ -586,13 +595,13 @@ Long_mul = function(a, b) {
var result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16)); var result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16));
return positive ? result : Long_neg(result); return positive ? result : Long_neg(result);
} }
Long_div = function(a, b) { function Long_div(a, b) {
return Long_divRem(a, b)[0]; return Long_divRem(a, b)[0];
} }
Long_rem = function(a, b) { function Long_rem(a, b) {
return Long_divRem(a, b)[1]; return Long_divRem(a, b)[1];
} }
Long_divRem = function(a, b) { function Long_divRem(a, b) {
var positive = Long_isNegative(a) === Long_isNegative(b); var positive = Long_isNegative(a) === Long_isNegative(b);
if (Long_isNegative(a)) { if (Long_isNegative(a)) {
a = Long_neg(a); a = Long_neg(a);
@ -607,22 +616,22 @@ Long_divRem = function(a, b) {
q = new Long(q.lo, q.hi); q = new Long(q.lo, q.hi);
return positive ? [q, a] : [Long_neg(q), Long_neg(a)]; return positive ? [q, a] : [Long_neg(q), Long_neg(a)];
} }
Long_shiftLeft16 = function(a) { function Long_shiftLeft16(a) {
return new Long(a.lo << 16, (a.lo >>> 16) | (a.hi << 16)); return new Long(a.lo << 16, (a.lo >>> 16) | (a.hi << 16));
} }
Long_shiftRight16 = function(a) { function Long_shiftRight16(a) {
return new Long((a.lo >>> 16) | (a.hi << 16), a.hi >>> 16); return new Long((a.lo >>> 16) | (a.hi << 16), a.hi >>> 16);
} }
Long_and = function(a, b) { function Long_and(a, b) {
return new Long(a.lo & b.lo, a.hi & b.hi); return new Long(a.lo & b.lo, a.hi & b.hi);
} }
Long_or = function(a, b) { function Long_or(a, b) {
return new Long(a.lo | b.lo, a.hi | b.hi); return new Long(a.lo | b.lo, a.hi | b.hi);
} }
Long_xor = function(a, b) { function Long_xor(a, b) {
return new Long(a.lo ^ b.lo, a.hi ^ b.hi); return new Long(a.lo ^ b.lo, a.hi ^ b.hi);
} }
Long_shl = function(a, b) { function Long_shl(a, b) {
b &= 63; b &= 63;
if (b == 0) { if (b == 0) {
return a; return a;
@ -634,7 +643,7 @@ Long_shl = function(a, b) {
return new Long(0, a.lo << (b - 32)); return new Long(0, a.lo << (b - 32));
} }
} }
Long_shr = function(a, b) { function Long_shr(a, b) {
b &= 63; b &= 63;
if (b == 0) { if (b == 0) {
return a; return a;
@ -646,7 +655,7 @@ Long_shr = function(a, b) {
return new Long((a.hi >> (b - 32)), a.hi >> 31); return new Long((a.hi >> (b - 32)), a.hi >> 31);
} }
} }
Long_shru = function(a, b) { function Long_shru(a, b) {
b &= 63; b &= 63;
if (b == 0) { if (b == 0) {
return a; return a;
@ -660,12 +669,12 @@ Long_shru = function(a, b) {
} }
// Represents a mutable 80-bit unsigned integer // Represents a mutable 80-bit unsigned integer
LongInt = function(lo, hi, sup) { function LongInt(lo, hi, sup) {
this.lo = lo; this.lo = lo;
this.hi = hi; this.hi = hi;
this.sup = sup; this.sup = sup;
} }
LongInt_mul = function(a, b) { function LongInt_mul(a, b) {
var a_lolo = ((a.lo & 0xFFFF) * b) | 0; var a_lolo = ((a.lo & 0xFFFF) * b) | 0;
var a_lohi = ((a.lo >>> 16) * b) | 0; var a_lohi = ((a.lo >>> 16) * b) | 0;
var a_hilo = ((a.hi & 0xFFFF) * b) | 0; var a_hilo = ((a.hi & 0xFFFF) * b) | 0;
@ -680,7 +689,7 @@ LongInt_mul = function(a, b) {
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup & 0xFFFF; a.sup = sup & 0xFFFF;
} }
LongInt_sub = function(a, b) { function LongInt_sub(a, b) {
var a_lolo = a.lo & 0xFFFF; var a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; var a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; var a_hilo = a.hi & 0xFFFF;
@ -694,12 +703,12 @@ LongInt_sub = function(a, b) {
a_lohi = (a_lohi - b_lohi + (a_lolo >> 16)) | 0; a_lohi = (a_lohi - b_lohi + (a_lolo >> 16)) | 0;
a_hilo = (a_hilo - b_hilo + (a_lohi >> 16)) | 0; a_hilo = (a_hilo - b_hilo + (a_lohi >> 16)) | 0;
a_hihi = (a_hihi - b_hihi + (a_hilo >> 16)) | 0; a_hihi = (a_hihi - b_hihi + (a_hilo >> 16)) | 0;
sup = (a.sup - b.sup + (a_hihi >> 16)) | 0; var sup = (a.sup - b.sup + (a_hihi >> 16)) | 0;
a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16);
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup; a.sup = sup;
} }
LongInt_add = function(a, b) { function LongInt_add(a, b) {
var a_lolo = a.lo & 0xFFFF; var a_lolo = a.lo & 0xFFFF;
var a_lohi = a.lo >>> 16; var a_lohi = a.lo >>> 16;
var a_hilo = a.hi & 0xFFFF; var a_hilo = a.hi & 0xFFFF;
@ -713,12 +722,12 @@ LongInt_add = function(a, b) {
a_lohi = (a_lohi + b_lohi + (a_lolo >> 16)) | 0; a_lohi = (a_lohi + b_lohi + (a_lolo >> 16)) | 0;
a_hilo = (a_hilo + b_hilo + (a_lohi >> 16)) | 0; a_hilo = (a_hilo + b_hilo + (a_lohi >> 16)) | 0;
a_hihi = (a_hihi + b_hihi + (a_hilo >> 16)) | 0; a_hihi = (a_hihi + b_hihi + (a_hilo >> 16)) | 0;
sup = (a.sup + b.sup + (a_hihi >> 16)) | 0; var sup = (a.sup + b.sup + (a_hihi >> 16)) | 0;
a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16);
a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16);
a.sup = sup; a.sup = sup;
} }
LongInt_inc = function(a) { function LongInt_inc(a) {
a.lo = (a.lo + 1) | 0; a.lo = (a.lo + 1) | 0;
if (a.lo == 0) { if (a.lo == 0) {
a.hi = (a.hi + 1) | 0; a.hi = (a.hi + 1) | 0;
@ -727,7 +736,7 @@ LongInt_inc = function(a) {
} }
} }
} }
LongInt_dec = function(a) { function LongInt_dec(a) {
a.lo = (a.lo - 1) | 0; a.lo = (a.lo - 1) | 0;
if (a.lo == -1) { if (a.lo == -1) {
a.hi = (a.hi - 1) | 0; a.hi = (a.hi - 1) | 0;
@ -736,7 +745,7 @@ LongInt_dec = function(a) {
} }
} }
} }
LongInt_ucompare = function(a, b) { function LongInt_ucompare(a, b) {
var r = (a.sup - b.sup); var r = (a.sup - b.sup);
if (r != 0) { if (r != 0) {
return r; return r;
@ -755,7 +764,7 @@ LongInt_ucompare = function(a, b) {
} }
return (a.lo & 1) - (b.lo & 1); return (a.lo & 1) - (b.lo & 1);
} }
LongInt_numOfLeadingZeroBits = function(a) { function LongInt_numOfLeadingZeroBits(a) {
var n = 0; var n = 0;
var d = 16; var d = 16;
while (d > 0) { while (d > 0) {
@ -767,14 +776,14 @@ LongInt_numOfLeadingZeroBits = function(a) {
} }
return 31 - n; return 31 - n;
} }
LongInt_shl = function(a, b) { function LongInt_shl(a, b) {
if (b === 0) { if (b == 0) {
return; return;
} else if (b < 32) { } else if (b < 32) {
a.sup = ((a.hi >>> (32 - b)) | (a.sup << b)) & 0xFFFF; a.sup = ((a.hi >>> (32 - b)) | (a.sup << b)) & 0xFFFF;
a.hi = (a.lo >>> (32 - b)) | (a.hi << b); a.hi = (a.lo >>> (32 - b)) | (a.hi << b);
a.lo <<= b; a.lo <<= b;
} else if (b === 32) { } else if (b == 32) {
a.sup = a.hi & 0xFFFF; a.sup = a.hi & 0xFFFF;
a.hi = a.lo; a.hi = a.lo;
a.lo = 0; a.lo = 0;
@ -782,7 +791,7 @@ LongInt_shl = function(a, b) {
a.sup = ((a.lo >>> (64 - b)) | (a.hi << (b - 32))) & 0xFFFF; a.sup = ((a.lo >>> (64 - b)) | (a.hi << (b - 32))) & 0xFFFF;
a.hi = a.lo << b; a.hi = a.lo << b;
a.lo = 0; a.lo = 0;
} else if (b === 64) { } else if (b == 64) {
a.sup = a.lo & 0xFFFF; a.sup = a.lo & 0xFFFF;
a.hi = 0; a.hi = 0;
a.lo = 0; a.lo = 0;
@ -792,10 +801,10 @@ LongInt_shl = function(a, b) {
a.lo = 0; a.lo = 0;
} }
} }
LongInt_shr = function(a, b) { function LongInt_shr(a, b) {
if (b === 0) { if (b == 0) {
return; return;
} else if (b === 32) { } else if (b == 32) {
a.lo = a.hi; a.lo = a.hi;
a.hi = a.sup; a.hi = a.sup;
a.sup = 0; a.sup = 0;
@ -803,7 +812,7 @@ LongInt_shr = function(a, b) {
a.lo = (a.lo >>> b) | (a.hi << (32 - b)); a.lo = (a.lo >>> b) | (a.hi << (32 - b));
a.hi = (a.hi >>> b) | (a.sup << (32 - b)); a.hi = (a.hi >>> b) | (a.sup << (32 - b));
a.sup >>>= b; a.sup >>>= b;
} else if (b === 64) { } else if (b == 64) {
a.lo = a.sup; a.lo = a.sup;
a.hi = 0; a.hi = 0;
a.sup = 0; a.sup = 0;
@ -817,17 +826,17 @@ LongInt_shr = function(a, b) {
a.sup = 0; a.sup = 0;
} }
} }
LongInt_copy = function(a) { function LongInt_copy(a) {
return new LongInt(a.lo, a.hi, a.sup); return new LongInt(a.lo, a.hi, a.sup);
} }
LongInt_div = function(a, b) { function LongInt_div(a, b) {
// Normalize divisor // Normalize divisor
var bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32; var bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32;
var sz = 1 + ((bits / 16) | 0); var sz = 1 + ((bits / 16) | 0);
var dividentBits = bits % 16; var dividentBits = bits % 16;
LongInt_shl(b, bits); LongInt_shl(b, bits);
LongInt_shl(a, dividentBits); LongInt_shl(a, dividentBits);
q = new LongInt(0, 0, 0); var q = new LongInt(0, 0, 0);
while (sz-- > 0) { while (sz-- > 0) {
LongInt_shl(q, 16); LongInt_shl(q, 16);
// Calculate approximate q // Calculate approximate q

View File

@ -91,7 +91,7 @@
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory> <targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass> <mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
<runtime>SEPARATE</runtime> <runtime>SEPARATE</runtime>
<minifying>true</minifying> <minifying>false</minifying>
<debugInformationGenerated>true</debugInformationGenerated> <debugInformationGenerated>true</debugInformationGenerated>
</configuration> </configuration>
</execution> </execution>