From 739f666c0a62e8d9a5447cb026e4d5c18fbac9d3 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 14 Mar 2014 13:03:26 +0400 Subject: [PATCH] Fixes java.io.BufferedReader.skip method. Fixes multiplication of negative long integers --- .../classlib/java/io/TBufferedReader.java | 8 +++-- .../resources/org/teavm/javascript/runtime.js | 10 ++++++- teavm-samples/pom.xml | 30 ------------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java index af7302bbf..ec50319bf 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java @@ -120,13 +120,17 @@ public class TBufferedReader extends TReader { requireOpened(); if (n < count - index) { index += n; + return n; } else { n -= (count - index); - if (innerReader.skip(n) == n) { + long skipped = innerReader.skip(n); + if (skipped == n) { fillBuffer(0); + } else { + eof = true; } + return skipped; } - return super.skip(n); } @Override 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 e51cb45cb..4ab5dea35 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -486,6 +486,13 @@ Long_isNegative = function(a) { return (a.hi & 0x80000000) !== 0; } Long_mul = function(a, b) { + var positive = Long_isNegative(a) === Long_isNegative(b); + if (Long_isNegative(a)) { + a = Long_neg(a); + } + if (Long_isNegative(b)) { + b = Long_neg(b); + } var a_lolo = a.lo & 0xFFFF; var a_lohi = a.lo >>> 16; var a_hilo = a.hi & 0xFFFF; @@ -499,7 +506,8 @@ Long_mul = function(a, b) { var lohi = (a_lohi * b_lolo + a_lolo * b_lohi + (lolo >> 16)) | 0; var hilo = (a_hilo * b_lolo + a_lohi * b_lohi + a_lolo * b_hilo + (lohi >> 16)) | 0; var hihi = (a_hihi * b_lolo + a_hilo * b_lohi + a_lohi * b_hilo + a_lolo * b_hihi + (hilo >> 16)) | 0; - return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); + var result = new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); + return positive ? result : Long_neg(result); } Long_div = function(a, b) { return Long_divRem(a, b)[0]; diff --git a/teavm-samples/pom.xml b/teavm-samples/pom.xml index 7d0a7ed4c..9e0fa1bbf 100644 --- a/teavm-samples/pom.xml +++ b/teavm-samples/pom.xml @@ -79,35 +79,5 @@ - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.teavm - teavm-maven-plugin - [0.0.1-SNAPSHOT,) - - build-javascript - - - - - - - - - - - - \ No newline at end of file