diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml
index 7497b4015..b9fc345ec 100644
--- a/teavm-classlib/pom.xml
+++ b/teavm-classlib/pom.xml
@@ -99,6 +99,7 @@
java.lang.annotation
java.lang.reflect
java.io
+ java.math
java.net
java.text
java.util
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
index be4538161..2f6bbd78a 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
@@ -26,48 +26,41 @@ import java.util.Random;
class TPrimality {
/** Just to denote that this class can't be instantiated. */
- private TPrimality() {}
+ private TPrimality() {
+ }
/** All prime numbers with bit length lesser than 10 bits. */
- private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
- 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
- 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
- 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,
- 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
- 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
- 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
- 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,
- 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,
- 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
- 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
- 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
- 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009,
- 1013, 1019, 1021 };
+ private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
+ 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
+ 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
+ 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
+ 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571,
+ 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
+ 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
+ 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,
+ 1009, 1013, 1019, 1021 };
/** All {@code BigInteger} prime numbers with bit length lesser than 8 bits. */
private static final TBigInteger BIprimes[] = new TBigInteger[primes.length];
/**
* It encodes how many iterations of Miller-Rabin test are need to get an
- * error bound not greater than {@code 2(-100)}. For example:
- * for a {@code 1000}-bit number we need {@code 4} iterations, since
+ * error bound not greater than {@code 2(-100)}. For example: for
+ * a {@code 1000}-bit number we need {@code 4} iterations, since
* {@code BITS[3] < 1000 <= BITS[4]}.
*/
- private static final int[] BITS = { 0, 0, 1854, 1233, 927, 747, 627, 543,
- 480, 431, 393, 361, 335, 314, 295, 279, 265, 253, 242, 232, 223,
- 216, 181, 169, 158, 150, 145, 140, 136, 132, 127, 123, 119, 114,
- 110, 105, 101, 96, 92, 87, 83, 78, 73, 69, 64, 59, 54, 49, 44, 38,
- 32, 26, 1 };
+ private static final int[] BITS = { 0, 0, 1854, 1233, 927, 747, 627, 543, 480, 431, 393, 361, 335, 314, 295, 279,
+ 265, 253, 242, 232, 223, 216, 181, 169, 158, 150, 145, 140, 136, 132, 127, 123, 119, 114, 110, 105, 101,
+ 96, 92, 87, 83, 78, 73, 69, 64, 59, 54, 49, 44, 38, 32, 26, 1 };
/**
* It encodes how many i-bit primes there are in the table for
* {@code i=2,...,10}. For example {@code offsetPrimes[6]} says that from
- * index {@code 11} exists {@code 7} consecutive {@code 6}-bit prime
- * numbers in the array.
+ * index {@code 11} exists {@code 7} consecutive {@code 6}-bit prime numbers
+ * in the array.
*/
- private static final int[][] offsetPrimes = { null, null, { 0, 2 },
- { 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 }, { 18, 13 }, { 31, 23 },
- { 54, 43 }, { 97, 75 } };
+ private static final int[][] offsetPrimes = { null, null, { 0, 2 }, { 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 },
+ { 18, 13 }, { 31, 23 }, { 54, 43 }, { 97, 75 } };
static {// To initialize the dual table of BigInteger primes
for (int i = 0; i < primes.length; i++) {
@@ -94,19 +87,17 @@ class TPrimality {
TBigInteger startPoint;
TBigInteger probPrime;
// If n < "last prime of table" searches next prime in the table
- if ((n.numberLength == 1) && (n.digits[0] >= 0)
- && (n.digits[0] < primes[primes.length - 1])) {
+ if ((n.numberLength == 1) && (n.digits[0] >= 0) && (n.digits[0] < primes[primes.length - 1])) {
for (i = 0; n.digits[0] >= primes[i]; i++) {
// do nothing
}
return BIprimes[i];
}
/*
- * Creates a "N" enough big to hold the next probable prime Note that: N <
- * "next prime" < 2*N
+ * Creates a "N" enough big to hold the next probable prime Note that: N
+ * < "next prime" < 2*N
*/
- startPoint = new TBigInteger(1, n.numberLength,
- new int[n.numberLength + 1]);
+ startPoint = new TBigInteger(1, n.numberLength, new int[n.numberLength + 1]);
System.arraycopy(n.digits, 0, startPoint.digits, 0, n.numberLength);
// To fix N to the "next odd number"
if (n.testBit(0)) {
@@ -204,8 +195,7 @@ class TPrimality {
}
// To check if 'n' is divisible by some prime of the table
for (int i = 1; i < primes.length; i++) {
- if (TDivision.remainderArrayByInt(n.digits, n.numberLength,
- primes[i]) == 0) {
+ if (TDivision.remainderArrayByInt(n.digits, n.numberLength, primes[i]) == 0) {
return false;
}
}
@@ -224,8 +214,10 @@ class TPrimality {
/**
* The Miller-Rabin primality test.
*
- * @param n the input number to be tested.
- * @param t the number of trials.
+ * @param n
+ * the input number to be tested.
+ * @param t
+ * the number of trials.
* @return {@code false} if the number is definitely compose, otherwise
* {@code true} with probability {@code 1 - 4(-t)}.
* @ar.org.fitc.ref "D. Knuth, The Art of Computer Programming Vo.2, Section
@@ -253,8 +245,7 @@ class TPrimality {
*/
do {
x = new TBigInteger(bitLength, rnd);
- } while ((x.compareTo(n) >= TBigInteger.EQUALS) || (x.sign == 0)
- || x.isOne());
+ } while ((x.compareTo(n) >= TBigInteger.EQUALS) || (x.sign == 0) || x.isOne());
}
y = x.modPow(q, n);
if (y.isOne() || y.equals(n_minus_1)) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java
index 5924878b0..366e9b310 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java
@@ -35,7 +35,7 @@ public class TRandom extends TObject implements TSerializable {
}
protected int next(int bits) {
- return (int)(random() * (1 << TMath.min(32, bits)));
+ return (int)(random() * (1L << TMath.min(32, bits)));
}
public void nextBytes(byte[] bytes) {
diff --git a/teavm-core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java b/teavm-core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java
index ba5f12c60..048749de6 100644
--- a/teavm-core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java
+++ b/teavm-core/src/main/java/org/teavm/javascript/BreakToContinueReplacer.java
@@ -37,6 +37,9 @@ class BreakToContinueReplacer implements StatementVisitor {
}
public void visitSequence(List statements) {
+ if (statements == null) {
+ return;
+ }
for (int i = 0; i < statements.size(); ++i) {
Statement stmt = statements.get(i);
stmt.acceptVisitor(this);
diff --git a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java
index 57b88d1d7..d67bb8ce2 100644
--- a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java
+++ b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java
@@ -199,8 +199,15 @@ public class Decompiler {
for (int i = 0; i < this.graph.size(); ++i) {
Block block = stack.peek();
while (block.end == i) {
+ Block oldBlock = block;
stack.pop();
block = stack.peek();
+ if (block.start >= 0) {
+ int mappedStart = indexer.nodeAt(block.start);
+ if (blockMap[mappedStart] == oldBlock) {
+ blockMap[mappedStart] = block;
+ }
+ }
}
while (parentNode.getEnd() == i) {
currentNode = parentNode.getNext();