From 15478da9ed3ea79e636ccc1ec53aa2bde3c7453f Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Mon, 7 Apr 2014 11:15:39 +0400 Subject: [PATCH 1/3] Fixes ByteOrder error --- .../src/main/java/org/teavm/classlib/java/nio/TByteOrder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteOrder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteOrder.java index 9628ab746..e9ebe1872 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteOrder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteOrder.java @@ -21,7 +21,7 @@ package org.teavm.classlib.java.nio; */ public final class TByteOrder { public static final TByteOrder BIG_ENDIAN = new TByteOrder("BIG_ENDIAN"); - public static final TByteOrder LITTLE_ENDIAN = new TByteOrder("BIG_ENDIAN"); + public static final TByteOrder LITTLE_ENDIAN = new TByteOrder("LITTLE_ENDIAN"); private String name; private TByteOrder(String name) { From ad3fa3b53190049c5ae5547e5301552c9ad25eef Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Mon, 7 Apr 2014 13:01:19 +0400 Subject: [PATCH 2/3] Fixes bugs --- .../org/teavm/classlib/java/lang/TString.java | 3 ++ .../org/teavm/classlib/java/lang/TSystem.java | 7 ++- .../java/org/teavm/javascript/Renderer.java | 44 ++++++++++--------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java index f50977e12..efadef73b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java @@ -508,6 +508,9 @@ public class TString extends TObject implements TSerializable, TComparable nonInitMethods = new ArrayList<>(); List virtualMethods = new ArrayList<>(); + + writer.append("function ").appendClass(cls.getName()).append("_$clinit()").ws() + .append("{").softNewLine().indent(); + writer.appendClass(cls.getName()).append("_$clinit").ws().append("=").ws() + .append("function(){};").newLine(); + List stubNames = new ArrayList<>(); + for (MethodNode method : cls.getMethods()) { + if (!method.getModifiers().contains(NodeModifier.STATIC) && + !method.getReference().getName().equals("")) { + nonInitMethods.add(method); + } else { + renderBody(method, true); + stubNames.add(naming.getFullNameFor(method.getReference())); + } + } + MethodHolder methodHolder = classSource.get(cls.getName()).getMethod( + new MethodDescriptor("", ValueType.VOID)); + if (methodHolder != null) { + writer.appendMethodBody(new MethodReference(cls.getName(), methodHolder.getDescriptor())) + .append("();").softNewLine(); + } + writer.outdent().append("}").newLine(); if (!cls.getModifiers().contains(NodeModifier.INTERFACE)) { - writer.append("function ").appendClass(cls.getName()).append("_$clinit()").ws() - .append("{").softNewLine().indent(); - writer.appendClass(cls.getName()).append("_$clinit").ws().append("=").ws() - .append("function(){};").newLine(); - List stubNames = new ArrayList<>(); - for (MethodNode method : cls.getMethods()) { - if (!method.getModifiers().contains(NodeModifier.STATIC) && - !method.getReference().getName().equals("")) { - nonInitMethods.add(method); - } else { - renderBody(method, true); - stubNames.add(naming.getFullNameFor(method.getReference())); - } - } - MethodHolder methodHolder = classSource.get(cls.getName()).getMethod( - new MethodDescriptor("", ValueType.VOID)); - if (methodHolder != null) { - writer.appendMethodBody(new MethodReference(cls.getName(), methodHolder.getDescriptor())) - .append("();").softNewLine(); - } - writer.outdent().append("}").newLine(); for (MethodNode method : cls.getMethods()) { cls.getMethods(); if (!method.getModifiers().contains(NodeModifier.STATIC)) { @@ -286,6 +287,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append("]);").newLine(); } } + for (MethodNode method : nonInitMethods) { renderBody(method, false); } From 2421e6d46bf94142f7efa3e0ebfcef3b9ddb5058 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Tue, 8 Apr 2014 17:06:02 +0400 Subject: [PATCH 3/3] Optimize runtime.js --- .../java/org/teavm/javascript/Renderer.java | 8 +++---- .../resources/org/teavm/javascript/runtime.js | 23 +++---------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index debf53bda..8fef2ed31 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -882,14 +882,14 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append(')'); break; case BYTE_TO_INT: - writer.append("$rt_byteToInt("); + writer.append("(("); expr.getOperand().acceptVisitor(this); - writer.append(')'); + writer.ws().append("<<").ws().append("24)").ws().append(">>").ws().append("24)"); break; case SHORT_TO_INT: - writer.append("$rt_shortToInt("); + writer.append("(("); expr.getOperand().acceptVisitor(this); - writer.append(')'); + writer.ws().append("<<").ws().append("16)").ws().append(">>").ws().append("16)"); break; case NULL_CHECK: writer.append("$rt_nullCheck("); diff --git a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js index 02d572197..90151adde 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -201,19 +201,6 @@ $rt_voidcls = function() { } return $rt_voidclsCache; } -$rt_equals = function(a, b) { - if (a === b) { - return true; - } - if (a === null || b === null) { - return false; - } - if (typeof(a) == 'object') { - return a.equals(b); - } else { - return false; - } -} $rt_clinit = function(cls) { if (cls.$clinit) { var f = cls.$clinit; @@ -236,12 +223,6 @@ $rt_throw = function(ex) { } throw err; } -$rt_byteToInt = function(value) { - return value > 0xFF ? value | 0xFFFFFF00 : value; -} -$rt_shortToInt = function(value) { - return value > 0xFFFF ? value | 0xFFFF0000 : value; -} $rt_createMultiArray = function(cls, dimensions) { var arrays = new Array($rt_primitiveArrayCount(dimensions)); var firstDim = dimensions[0] | 0; @@ -546,6 +527,7 @@ Long_xor = function(a, b) { return new Long(a.lo ^ b.lo, a.hi ^ b.hi); } Long_shl = function(a, b) { + b &= 63; if (b < 32) { return new Long(a.lo << b, (a.lo >>> (32 - b)) | (a.hi << b)); } else { @@ -553,10 +535,11 @@ Long_shl = function(a, b) { } } Long_shr = function(a, b) { + b &= 63; if (b < 32) { return new Long((a.lo >>> b) | (a.hi << (32 - b)), a.hi >> b); } else { - return new Long((a.hi >> (b - 32)), -1); + return new Long((a.hi >> (b - 32)), a.hi >> 31); } } Long_shru = function(a, b) {