From 06a96911a1989c61e07847b286dfb44cd6c6005c Mon Sep 17 00:00:00 2001
From: Alexey Andreev <Alexey.Andreev@jetbrains.com>
Date: Fri, 19 Aug 2016 20:35:08 +0300
Subject: [PATCH] Further improvements in WASM target

---
 .../teavm/classlib/java/lang/TCharacter.java  |  6 +-
 .../org/teavm/classlib/java/lang/TClass.java  |  5 --
 .../src/main/java/org/teavm/wasm/Example.java | 55 +++++++++++--------
 .../teavm/platform/PlatformPrimitives.java    |  3 -
 4 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
index 35a406d14..3dac5eaed 100644
--- a/classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
+++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
@@ -20,16 +20,12 @@ import org.teavm.platform.Platform;
 import org.teavm.platform.metadata.MetadataProvider;
 import org.teavm.platform.metadata.StringResource;
 
-/**
- *
- * @author Alexey Andreev
- */
 public class TCharacter extends TObject implements TComparable<TCharacter> {
     public static final int MIN_RADIX = 2;
     public static final int MAX_RADIX = 36;
     public static final char MIN_VALUE = '\0';
     public static final char MAX_VALUE = '\uFFFF';
-    public static final TClass<TCharacter> TYPE = TClass.charClass();
+    public static final Class<Character> TYPE = char.class;
     public static final byte UNASSIGNED = 0;
     public static final byte UPPERCASE_LETTER = 1;
     public static final byte LOWERCASE_LETTER = 2;
diff --git a/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java b/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
index 75f7c82de..e5f248449 100644
--- a/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
+++ b/classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
@@ -113,11 +113,6 @@ public class TClass<T> extends TObject implements TAnnotatedElement {
         return (TClass<TBoolean>) getClass(Platform.getPrimitives().getBooleanClass());
     }
 
-    @SuppressWarnings("unchecked")
-    static TClass<TCharacter> charClass() {
-        return (TClass<TCharacter>) getClass(Platform.getPrimitives().getCharClass());
-    }
-
     @SuppressWarnings("unchecked")
     static TClass<TByte> byteClass() {
         return (TClass<TByte>) getClass(Platform.getPrimitives().getByteClass());
diff --git a/core/src/main/java/org/teavm/wasm/Example.java b/core/src/main/java/org/teavm/wasm/Example.java
index 4bac1d189..7e5b9ba1d 100644
--- a/core/src/main/java/org/teavm/wasm/Example.java
+++ b/core/src/main/java/org/teavm/wasm/Example.java
@@ -26,39 +26,35 @@ public final class Example {
     public static void main(String[] args) {
         int a = 0;
         int b = 1;
+        println("Fibonacci numbers:");
         for (int i = 0; i < 30; ++i) {
             int c = a + b;
             a = b;
             b = c;
-            WasmRuntime.print(a);
+            println(String.valueOf(a));
         }
-        WasmRuntime.print(new A(2).getValue() + new A(3).getValue());
+
+        println("A(2) + A(3) = " + new A(2).getValue() + new A(3).getValue());
 
         for (int i = 0; i < 4; ++i) {
-            WasmRuntime.print(instance(i).foo());
+            println("instance(" + i + ") = " + instance(i).foo());
         }
 
         Base[] array = { new Derived1(), new Derived2() };
-        WasmRuntime.print(array.length);
+        println("array.length = " + array.length);
         for (Base elem : array) {
-            WasmRuntime.print(elem.foo());
+            println("array[i]" + elem.foo());
         }
 
-        WasmRuntime.print(new Derived2() instanceof Base ? 1 : 0);
-        WasmRuntime.print(new Derived3() instanceof Base ? 1 : 0);
-        WasmRuntime.print((Object) new Derived2() instanceof Derived1 ? 1 : 0);
-        WasmRuntime.print((Object) new Derived2() instanceof A ? 1 : 0);
-        WasmRuntime.print(new A(23) instanceof Base ? 1 : 0);
+        println("Derived2 instanceof Base = " + (new Derived2() instanceof Base));
+        println("Derived3 instanceof Base = " + (new Derived3() instanceof Base));
+        println("Derived2 instanceof Derived1 = " + ((Object) new Derived2() instanceof Derived1));
+        println("Derived2 instanceof A = " + ((Object) new Derived2() instanceof A));
+        println("A instanceof Base = " + (new A(23) instanceof Base));
 
         byte[] bytes = { 5, 6, 10, 15 };
         for (byte bt : bytes) {
-            WasmRuntime.print(bt);
-        }
-
-        String str = "foobar";
-        WasmRuntime.print(str.length());
-        for (int i = 0; i < str.length(); ++i) {
-            WasmRuntime.print(str.charAt(i));
+            println("bytes[i] = " + bt);
         }
 
         Initialized.foo();
@@ -66,17 +62,17 @@ public final class Example {
         Initialized.foo();
 
         Object o = new Object();
-        WasmRuntime.print(o.hashCode());
-        WasmRuntime.print(o.hashCode());
-        WasmRuntime.print(new Object().hashCode());
-        WasmRuntime.print(new Object().hashCode());
+        println("hashCode1 = " + o.hashCode());
+        println("hashCode1 = " + o.hashCode());
+        println("hashCode2 = " + new Object().hashCode());
+        println("hashCode3 = " + new Object().hashCode());
 
         List<Integer> list = new ArrayList<>(Arrays.asList(333, 444, 555));
         list.add(1234);
         list.remove((Integer) 444);
 
         for (int item : list) {
-            WasmRuntime.print(item);
+            println("list[i] = " + item);
         }
     }
 
@@ -135,11 +131,22 @@ public final class Example {
 
     static class Initialized {
         static {
-            WasmRuntime.print(9999);
+            println("Initialized.<clinit>()");
         }
 
         public static void foo() {
-            WasmRuntime.print(8888);
+            println("Initialized.foo()");
         }
     }
+
+    static void print(String value) {
+        for (int i = 0; i < value.length(); ++i) {
+            WasmRuntime.print(value.charAt(i));
+        }
+    }
+
+    static void println(String value) {
+        print(value);
+        WasmRuntime.print('\n');
+    }
 }
diff --git a/platform/src/main/java/org/teavm/platform/PlatformPrimitives.java b/platform/src/main/java/org/teavm/platform/PlatformPrimitives.java
index 402f1a616..e51c0ceb9 100644
--- a/platform/src/main/java/org/teavm/platform/PlatformPrimitives.java
+++ b/platform/src/main/java/org/teavm/platform/PlatformPrimitives.java
@@ -28,9 +28,6 @@ public interface PlatformPrimitives extends JSObject {
     @JSMethod("$rt_shortcls")
     PlatformClass getShortClass();
 
-    @JSMethod("$rt_charcls")
-    PlatformClass getCharClass();
-
     @JSMethod("$rt_longcls")
     PlatformClass getLongClass();