mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: add Integer/Long.compareUnsigned
This commit is contained in:
parent
d25cb1fa16
commit
a70251fe83
|
@ -38,6 +38,13 @@ public class IntegerNativeGenerator implements Injector {
|
||||||
context.writeExpr(context.getArgument(1));
|
context.writeExpr(context.getArgument(1));
|
||||||
context.getWriter().append(")");
|
context.getWriter().append(")");
|
||||||
break;
|
break;
|
||||||
|
case "compareUnsigned":
|
||||||
|
context.getWriter().append("$rt_ucmp(");
|
||||||
|
context.writeExpr(context.getArgument(0));
|
||||||
|
context.getWriter().append(",").ws();
|
||||||
|
context.writeExpr(context.getArgument(1));
|
||||||
|
context.getWriter().append(")");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ public class LongNativeGenerator implements Generator {
|
||||||
.append(context.getParameterName(2)).append(");").softNewLine();
|
.append(context.getParameterName(2)).append(");").softNewLine();
|
||||||
context.useLongLibrary();
|
context.useLongLibrary();
|
||||||
break;
|
break;
|
||||||
|
case "compareUnsigned":
|
||||||
|
writer.append("return Long_ucompare(").append(context.getParameterName(1)).append(", ")
|
||||||
|
.append(context.getParameterName(2)).append(");").softNewLine();
|
||||||
|
context.useLongLibrary();
|
||||||
|
break;
|
||||||
case "divideUnsigned":
|
case "divideUnsigned":
|
||||||
writer.append("return Long_udiv(").append(context.getParameterName(1)).append(", ")
|
writer.append("return Long_udiv(").append(context.getParameterName(1)).append(", ")
|
||||||
.append(context.getParameterName(2)).append(");").softNewLine();
|
.append(context.getParameterName(2)).append(");").softNewLine();
|
||||||
|
|
|
@ -368,4 +368,8 @@ public class TInteger extends TNumber implements TComparable<TInteger> {
|
||||||
@InjectedBy(IntegerNativeGenerator.class)
|
@InjectedBy(IntegerNativeGenerator.class)
|
||||||
@NoSideEffects
|
@NoSideEffects
|
||||||
public static native int remainderUnsigned(int dividend, int divisor);
|
public static native int remainderUnsigned(int dividend, int divisor);
|
||||||
|
|
||||||
|
@InjectedBy(IntegerNativeGenerator.class)
|
||||||
|
@NoSideEffects
|
||||||
|
public static native int compareUnsigned(int a, int b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,4 +359,8 @@ public class TLong extends TNumber implements TComparable<TLong> {
|
||||||
@GeneratedBy(LongNativeGenerator.class)
|
@GeneratedBy(LongNativeGenerator.class)
|
||||||
@NoSideEffects
|
@NoSideEffects
|
||||||
public static native long remainderUnsigned(long dividend, long divisor);
|
public static native long remainderUnsigned(long dividend, long divisor);
|
||||||
|
|
||||||
|
@GeneratedBy(LongNativeGenerator.class)
|
||||||
|
@NoSideEffects
|
||||||
|
public static native int compareUnsigned(long a, long b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ var Long_ge;
|
||||||
var Long_lt;
|
var Long_lt;
|
||||||
var Long_le;
|
var Long_le;
|
||||||
var Long_compare;
|
var Long_compare;
|
||||||
|
var Long_ucompare;
|
||||||
var Long_add;
|
var Long_add;
|
||||||
var Long_sub;
|
var Long_sub;
|
||||||
var Long_inc;
|
var Long_inc;
|
||||||
|
@ -185,6 +186,18 @@ if (typeof BigInt !== 'function') {
|
||||||
return (a.lo & 1) - (b.lo & 1);
|
return (a.lo & 1) - (b.lo & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Long_ucompare = function(a, b) {
|
||||||
|
var r = $rt_ucmp(a.hi, b.hi);
|
||||||
|
if (r !== 0) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
r = (a.lo >>> 1) - (b.lo >>> 1);
|
||||||
|
if (r !== 0) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
return (a.lo & 1) - (b.lo & 1);
|
||||||
|
}
|
||||||
|
|
||||||
Long_mul = function(a, b) {
|
Long_mul = function(a, b) {
|
||||||
var positive = Long_isNegative(a) === Long_isNegative(b);
|
var positive = Long_isNegative(a) === Long_isNegative(b);
|
||||||
if (Long_isNegative(a)) {
|
if (Long_isNegative(a)) {
|
||||||
|
@ -608,6 +621,11 @@ if (typeof BigInt !== 'function') {
|
||||||
Long_compare = function(a, b) {
|
Long_compare = function(a, b) {
|
||||||
return a < b ? -1 : a > b ? 1 : 0;
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
Long_ucompare = function(a, b) {
|
||||||
|
a = BigInt.asUintN(64, a);
|
||||||
|
b = BigInt.asUintN(64, b);
|
||||||
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
Long_mul = function(a, b) {
|
Long_mul = function(a, b) {
|
||||||
return BigInt.asIntN(64, a * b);
|
return BigInt.asIntN(64, a * b);
|
||||||
|
|
|
@ -879,6 +879,11 @@ var $rt_udiv = function(a, b) {
|
||||||
var $rt_umod = function(a, b) {
|
var $rt_umod = function(a, b) {
|
||||||
return ((a >>> 0) % (b >>> 0)) >>> 0;
|
return ((a >>> 0) % (b >>> 0)) >>> 0;
|
||||||
};
|
};
|
||||||
|
var $rt_ucmp = function(a, b) {
|
||||||
|
a >>>= 0;
|
||||||
|
b >>>= 0;
|
||||||
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
|
};
|
||||||
function $rt_checkBounds(index, array) {
|
function $rt_checkBounds(index, array) {
|
||||||
if (index < 0 || index >= array.length) {
|
if (index < 0 || index >= array.length) {
|
||||||
$rt_throwAIOOBE();
|
$rt_throwAIOOBE();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user