Skip to content

omnibus pull from bobhanson/java2Script #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240114215407
20240225103130
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20240114215407
20240225103130
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// TODO: superclass inheritance for JAXB XmlAccessorType
// TODO: Transpiler bug allows static String name, but JavaScript function().name is read-only and will be "clazz"

//BH 2024.02.22 -- 3.3.1-v7 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #)
//BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
//BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx
//BH 2022.06.27 -- 3.3.1-v5 fixes missing method annotations
Expand Down Expand Up @@ -4313,11 +4314,10 @@ && boxType(exp) == NO_BOX) {
private void addExtendedOperands(List<?> extendedOperands, String op, char pre, char post, boolean isToString,
boolean isLongCall) {
buffer.append(' ');
if (isLongCall)
op = ",";
for (Iterator<?> iter = extendedOperands.iterator(); iter.hasNext();) {
Expression exp = (Expression) iter.next();
// op may be int for a while, but after that it changes to long
if (isLongCall && exp.resolveTypeBinding().getName().equals("long"))
op = ",";
buffer.append(op);
buffer.append(pre);
addOperand(exp, isToString);
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.java.core/dist_to_jsmol/Jmol-j2s-site.zip
Binary file not shown.
2 changes: 0 additions & 2 deletions sources/net.sf.j2s.java.core/site-resources/test-raf.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) {
if (!f$.stacks || f$.claxxReference !== clazzThis) {
//Generate a new delegating method for the class
var id = ++SAEMid;
console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName);
//console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName);
var delegate = function () {
return searchAndExecuteMethod(id, this, arguments.callee.claxxReference, arguments.callee.methodName, arguments);
};
Expand Down
50 changes: 33 additions & 17 deletions sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* 2024.02.21 BH modified for SwingJS with a few (more!) (x + 0x80000000)|0 adjustments
*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand All @@ -25,7 +27,7 @@

package java.math;

/**
/**
* A class used to represent multiprecision integers that makes efficient
* use of allocated space by allowing a number to occupy only part of
* an array so that the arrays do not have to be reallocated as often.
Expand Down Expand Up @@ -294,8 +296,8 @@ private int compareShifted(MutableBigInteger b, int ints) {
// comparison.
int[] bval = b.value;
for (int i = offset, j = b.offset; i < alen + offset; i++, j++) {
int b1 = value[i] + 0x80000000;
int b2 = bval[j] + 0x80000000;
int b1 = (value[i] + 0x80000000)| 0;
int b2 = (bval[j] + 0x80000000)| 0;
if (b1 < b2)
return -1;
if (b1 > b2)
Expand Down Expand Up @@ -339,7 +341,7 @@ final int compareHalf(MutableBigInteger b) {
long v = val[i++] & LONG_MASK;
if (v != hb)
return v < hb ? -1 : 1;
carry = (bv & 1) << 31; // carray will be either 0x80000000 or 0
carry = ((bv & 1) << 31)|0; // carray will be either 0x80000000 or 0
}
return carry == 0 ? 0 : -1;
}
Expand Down Expand Up @@ -1131,7 +1133,6 @@ int divideOneWord(int divisor, MutableBigInteger quotient) {
quotient.value[intLen - xlen] = q;
remLong = rem & LONG_MASK;
}

quotient.normalize();
// Unnormalize
if (shift > 0)
Expand Down Expand Up @@ -1362,8 +1363,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot
if (compareShifted(b, n) < 0) {
// step 3a: if a1<b1, let quotient=a12/b1 and r=a12%b1
r = a12.divide2n1n(b1, quotient);

// step 4: d=quotient*b2
// step 4: d=quotient*b2
d = new MutableBigInteger(quotient.toBigInteger().multiply(b2));
} else {
// step 3b: if a1>=b1, let quotient=beta^n-1 and r=a12-b1*2^n+b1
Expand All @@ -1378,7 +1378,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot
d.leftShift(32 * n);
d.subtract(new MutableBigInteger(b2));
}

// step 5: r = r*beta^n + a3 - d (paper says a4)
// However, don't subtract d until after the while loop so r doesn't become negative
r.leftShift(32 * n);
Expand Down Expand Up @@ -1548,13 +1548,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
int qrem = 0;
boolean skipCorrection = false;
int nh = rem.value[j+rem.offset];
int nh2 = nh + 0x80000000;
int nh2 = (nh + 0x80000000)| 0;
int nm = rem.value[j+1+rem.offset];

if (nh == dh) {
qhat = ~0;
qrem = nh + nm;
skipCorrection = qrem + 0x80000000 < nh2;
skipCorrection = ((qrem + 0x80000000)| 0) < nh2;
} else {
long nChunk = (((long)nh) << 32) | (nm & LONG_MASK);
if (nChunk >= 0) {
Expand Down Expand Up @@ -1607,13 +1607,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
int qrem = 0;
boolean skipCorrection = false;
int nh = rem.value[limit - 1 + rem.offset];
int nh2 = nh + 0x80000000;
int nh2 = (nh + 0x80000000)|0;
int nm = rem.value[limit + rem.offset];

if (nh == dh) {
qhat = ~0;
qrem = nh + nm;
skipCorrection = qrem + 0x80000000 < nh2;
skipCorrection = ((qrem + 0x80000000)|0) < nh2;
} else {
long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
if (nChunk >= 0) {
Expand Down Expand Up @@ -1653,7 +1653,7 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div,
borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset);

// D5 Test remainder
if (borrow + 0x80000000 > nh2) {
if (((borrow + 0x80000000)|0) > nh2) {
// D6 Add back
if(needRemainder)
divadd(divisor, rem.value, limit - 1 + 1 + rem.offset);
Expand Down Expand Up @@ -1723,13 +1723,13 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q
int qrem = 0;
boolean skipCorrection = false;
int nh = rem.value[j + rem.offset];
int nh2 = nh + 0x80000000;
int nh2 = (nh + 0x80000000)|0;
int nm = rem.value[j + 1 + rem.offset];

if (nh == dh) {
qhat = ~0;
qrem = nh + nm;
skipCorrection = qrem + 0x80000000 < nh2;
skipCorrection = ((qrem + 0x80000000)|0) < nh2;
} else {
long nChunk = (((long) nh) << 32) | (nm & LONG_MASK);
if (nChunk >= 0) {
Expand Down Expand Up @@ -1767,7 +1767,7 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q
int borrow = mulsubLong(rem.value, dh, dl, qhat, j + rem.offset);

// D5 Test remainder
if (borrow + 0x80000000 > nh2) {
if (((borrow + 0x80000000)|0) > nh2) {
// D6 Add back
divaddLong(dh,dl, rem.value, j + 1 + rem.offset);
qhat--;
Expand Down Expand Up @@ -1963,7 +1963,7 @@ static int binaryGcd(int a, int b) {
int t = (aZeros < bZeros ? aZeros : bZeros);

while (a != b) {
if ((a+0x80000000) > (b+0x80000000)) { // a > b as unsigned
if (((a + 0x80000000)|0) > ((b + 0x80000000)|0)) { // a > b as unsigned
a -= b;
a >>>= Integer.numberOfTrailingZeros(a);
} else {
Expand Down Expand Up @@ -2246,4 +2246,20 @@ MutableBigInteger euclidModInverse(int k) {
mod.subtract(t1);
return mod;
}

// static {
// int a = 100;
// int b = a + 0x80000000;
// System.out.println(b);
// System.out.println((a + 0x80000000) | 0);
// System.out.println(a + 0x80000000L); // NOT in Java
// System.out.println((int) (a + 0x80000000L));
// a = -100;
// b = a + 0x80000000;
// System.out.println("?");
// System.out.println(b); //NOT in JS
// System.out.println((a + 0x80000000) | 0);
// System.out.println(a + 0x80000000L);
// System.out.println((int) (a + 0x80000000L));
// }
}
5 changes: 4 additions & 1 deletion sources/net.sf.j2s.java.core/src/java/util/Hashtable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,10 @@ public T nextElement() {

@Override
public V setValue(V value) {
return Hashtable.this.put(getKey(), value);
int m = modCount;
V v = put(getKey(), value);
modCount = m;
return v;
}
};
}
Expand Down
21 changes: 1 addition & 20 deletions sources/net.sf.j2s.java.core/src/javajs/util/A4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,7 @@ conforming to the Java(TM) 3D API specification by Sun Microsystems.
* for unique constructor and method names
* for the optimization of compiled JavaScript using Java2Script
*/
public class A4d implements JSONEncodable, Serializable {

/*
* I assumed that the length of the axis vector is not significant.
*/

/**
* The x coordinate.
*/
public double x;

/**
* The y coordinate.
*/
public double y;

/**
* The z coordinate.
*/
public double z;
public class A4d extends P3d {

/**
* The angle.
Expand Down
38 changes: 18 additions & 20 deletions sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public Object getNext(Object array, int pt) throws Exception {
if (array == null) {
switch (b) {
case FLOAT32:
return Float.valueOf(doc.readFloat());
return Double.valueOf(doc.readFloat());
case FLOAT64:
return Float.valueOf((float) doc.readDouble());
return Double.valueOf(doc.readDouble());
case UINT8:
return Integer.valueOf(doc.readUInt8());
case UINT16:
Expand All @@ -203,17 +203,17 @@ public Object getNext(Object array, int pt) throws Exception {
case STR8:
return doc.readString(doc.readUInt8());
case STR16:
return doc.readString(doc.readShort());
return doc.readString(doc.readUnsignedShort());
case STR32:
return doc.readString(doc.readInt());
}
} else {
switch (b) {
case FLOAT32:
((float[]) array)[pt] = doc.readFloat();
((double[]) array)[pt] = doc.readFloat();
break;
case FLOAT64:
((float[]) array)[pt] = (float) doc.readDouble();
((double[]) array)[pt] = doc.readDouble();
break;
case UINT8:
((int[]) array)[pt] = doc.readUInt8();
Expand Down Expand Up @@ -243,10 +243,10 @@ public Object getNext(Object array, int pt) throws Exception {
((String[]) array)[pt] = doc.readString(doc.readUInt8());
break;
case STR16:
((String[]) array)[pt] = doc.readString(doc.readShort());
((String[]) array)[pt] = doc.readString(doc.readUnsignedShort());
break;
case STR32:
((String[]) array)[pt] = doc.readString(doc.readInt());
((String[]) array)[pt] = doc.readString(doc.readInt()); // technically shoild be unsigned int
break;
}
}
Expand All @@ -267,9 +267,9 @@ private Object getArray(int n) throws Exception {
int[] a = new int[n];
a[0] = ((Integer) v).intValue();
v = a;
} else if (v instanceof Float) {
float[] a = new float[n];
a[0] = ((Float) v).floatValue();
} else if (v instanceof Number) {
double[] a = new double[n];
a[0] = ((Number) v).doubleValue();
v = a;
} else if (v instanceof String) {
String[] a = new String[n];
Expand All @@ -296,8 +296,6 @@ private Object getMap(int n) throws Exception {
Map<String, Object> map = new Hashtable<String, Object>();
for (int i = 0; i < n; i++) {
String key = getNext(null, 0).toString();
//Logger.info(key);

Object value = getNext(null, 0);
if (value == null) {
//Logger.info("null value for " + key);
Expand Down Expand Up @@ -366,10 +364,10 @@ public static Object decode(byte[] b) {
* @param divisor
* @return array of floats
*/
public static float[] getFloats(byte[] b, int n, float divisor) {
public static double[] getFloats(byte[] b, int n, float divisor) {
if (b == null)
return null;
float[] a = new float[n];
double[] a = new double[n];
try {
switch ((b.length - 12) / n) {
case 2:
Expand Down Expand Up @@ -522,10 +520,10 @@ public static int[] rldecode32Delta(byte[] b, int n) {
* @param divisor
* @return array of floats
*/
public static float[] rldecodef(byte[] b, int n, float divisor) {
public static double[] rldecodef(byte[] b, int n, float divisor) {
if (b == null)
return null;
float[] ret = new float[n];
double[] ret = new double[n];
for (int i = 0, pt = 3; i < n;) {
int val = BC.bytesToInt(b, (pt++) << 2, true);
for (int j = BC.bytesToInt(b, (pt++) << 2, true); --j >= 0;)
Expand All @@ -545,10 +543,10 @@ public static float[] rldecodef(byte[] b, int n, float divisor) {
* @param divisor
* @return array of floats
*/
public static float[] unpack16Deltaf(byte[] b, int n, float divisor) {
public static double[] unpack16Deltaf(byte[] b, int n, float divisor) {
if (b == null)
return null;
float[] ret = new float[n];
double[] ret = new double[n];
for (int i = 0, pt = 6, val = 0, buf = 0; i < n;) {
int diff = BC.bytesToShort(b, (pt++) << 1, true);
if (diff == Short.MAX_VALUE || diff == Short.MIN_VALUE) {
Expand All @@ -575,10 +573,10 @@ public static float[] unpack16Deltaf(byte[] b, int n, float divisor) {
* @param divisor
* @return array of floats
*/
public static float[] unpackf(byte[] b, int nBytes, int n, float divisor) {
public static double[] unpackf(byte[] b, int nBytes, int n, float divisor) {
if (b == null)
return null;
float[] ret = new float[n];
double[] ret = new double[n];
switch (nBytes) {
case 1:
for (int i = 0, pt = 12, offset = 0; i < n;) {
Expand Down
Loading