diff --git a/core/src/main/java/org/teavm/backend/wasm/Example.java b/core/src/main/java/org/teavm/backend/wasm/Example.java index 59124d4c6..eb79a2778 100644 --- a/core/src/main/java/org/teavm/backend/wasm/Example.java +++ b/core/src/main/java/org/teavm/backend/wasm/Example.java @@ -110,9 +110,9 @@ public final class Example { byte[] negatives = new byte[100]; for (int i = 0; i < array.length; ++i) { array[i] = (byte) i; - negatives[i] = (byte) -i; + negatives[i] = (byte) (-i - 1); } - System.arraycopy(negatives, 4, array, 0, 12); + System.arraycopy(negatives, 0, array, 4, 12); System.arraycopy(negatives, 1, array, 21, 12); System.arraycopy(negatives, 2, array, 35, 12); System.arraycopy(negatives, 1, array, 8, 3); diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java b/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java index 38d8c8c74..f3f1526e2 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmRuntime.java @@ -262,14 +262,14 @@ public final class WasmRuntime { alignedTargetStart.putInt(alignedSourceStart.getInt()); break; case 1: - alignedTargetStart.add(3).putByte(alignedSourceStart.add(3).getByte()); + alignedTargetStart.add(1).putByte(alignedSourceStart.add(1).getByte()); + alignedTargetStart.add(2).putShort(alignedSourceStart.add(2).getShort()); break; case 2: alignedTargetStart.add(2).putShort(alignedSourceStart.add(2).getShort()); break; case 3: - alignedTargetStart.add(1).putByte(alignedSourceStart.add(1).getByte()); - alignedTargetStart.add(2).putShort(alignedSourceStart.add(2).getShort()); + alignedTargetStart.add(3).putByte(alignedSourceStart.add(3).getByte()); break; } @@ -282,7 +282,7 @@ public final class WasmRuntime { alignedTargetStart = alignedTargetStart.add(4); } - switch (source.getInt() + count - alignedSourceEnd.getInt()) { + switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; case 1: @@ -297,7 +297,7 @@ public final class WasmRuntime { break; } } else { - switch (source.getInt() + count - alignedSourceEnd.getInt()) { + switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; case 1: @@ -312,7 +312,7 @@ public final class WasmRuntime { break; } - while (alignedSourceEnd.toInt() > alignedTargetEnd.toInt()) { + while (alignedSourceEnd.toInt() > alignedSourceStart.toInt()) { alignedTargetEnd.putInt(alignedSourceEnd.getInt()); alignedSourceEnd = alignedSourceEnd.add(-4); alignedTargetEnd = alignedTargetEnd.add(-4);