mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 00:14:10 -08:00
Remove unnecessary Wasm runtime imports, implement isFinite method
This commit is contained in:
parent
c52b71292d
commit
5fb83ca2ac
|
@ -1451,7 +1451,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
expr.getIndex().acceptVisitor(this);
|
expr.getIndex().acceptVisitor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmExpression negate(WasmExpression expr) {
|
private static WasmExpression negate(WasmExpression expr) {
|
||||||
if (expr instanceof WasmIntBinary) {
|
if (expr instanceof WasmIntBinary) {
|
||||||
WasmIntBinary binary = (WasmIntBinary) expr;
|
WasmIntBinary binary = (WasmIntBinary) expr;
|
||||||
if (binary.getType() == WasmIntType.INT32 && binary.getOperation() == WasmIntBinaryOperation.XOR) {
|
if (binary.getType() == WasmIntType.INT32 && binary.getOperation() == WasmIntBinaryOperation.XOR) {
|
||||||
|
@ -1478,11 +1478,11 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
return new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, expr, new WasmInt32Constant(0));
|
return new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, expr, new WasmInt32Constant(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOne(WasmExpression expression) {
|
private static boolean isOne(WasmExpression expression) {
|
||||||
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 1;
|
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isZero(WasmExpression expression) {
|
private static boolean isZero(WasmExpression expression) {
|
||||||
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 0;
|
return expression instanceof WasmInt32Constant && ((WasmInt32Constant) expression).getValue() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1546,7 +1546,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmIntBinaryOperation negate(WasmIntBinaryOperation op) {
|
private static WasmIntBinaryOperation negate(WasmIntBinaryOperation op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case EQ:
|
case EQ:
|
||||||
return WasmIntBinaryOperation.NE;
|
return WasmIntBinaryOperation.NE;
|
||||||
|
@ -1573,7 +1573,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmFloatBinaryOperation negate(WasmFloatBinaryOperation op) {
|
private static WasmFloatBinaryOperation negate(WasmFloatBinaryOperation op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case EQ:
|
case EQ:
|
||||||
return WasmFloatBinaryOperation.NE;
|
return WasmFloatBinaryOperation.NE;
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class DoubleIntrinsic implements WasmIntrinsic {
|
||||||
case "getNaN":
|
case "getNaN":
|
||||||
case "isNaN":
|
case "isNaN":
|
||||||
case "isInfinite":
|
case "isInfinite":
|
||||||
|
case "isFinite":
|
||||||
case "doubleToLongBits":
|
case "doubleToLongBits":
|
||||||
case "longBitsToDouble":
|
case "longBitsToDouble":
|
||||||
return true;
|
return true;
|
||||||
|
@ -65,7 +66,14 @@ public class DoubleIntrinsic implements WasmIntrinsic {
|
||||||
WasmIntBinaryOperation.NE);
|
WasmIntBinaryOperation.NE);
|
||||||
case "isInfinite":
|
case "isInfinite":
|
||||||
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
||||||
WasmIntBinaryOperation.EQ);
|
WasmIntBinaryOperation.NE);
|
||||||
|
case "isFinite": {
|
||||||
|
WasmExpression result = testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
||||||
|
WasmIntBinaryOperation.NE);
|
||||||
|
result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, result,
|
||||||
|
new WasmInt32Constant(0));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
case "doubleToLongBits": {
|
case "doubleToLongBits": {
|
||||||
WasmConversion conversion = new WasmConversion(WasmType.FLOAT64, WasmType.INT64, false,
|
WasmConversion conversion = new WasmConversion(WasmType.FLOAT64, WasmType.INT64, false,
|
||||||
manager.generate(invocation.getArguments().get(0)));
|
manager.generate(invocation.getArguments().get(0)));
|
||||||
|
|
|
@ -46,6 +46,7 @@ public class FloatIntrinsic implements WasmIntrinsic {
|
||||||
case "getNaN":
|
case "getNaN":
|
||||||
case "isNaN":
|
case "isNaN":
|
||||||
case "isInfinite":
|
case "isInfinite":
|
||||||
|
case "isFinite":
|
||||||
case "floatToIntBits":
|
case "floatToIntBits":
|
||||||
case "intBitsToFloat":
|
case "intBitsToFloat":
|
||||||
return true;
|
return true;
|
||||||
|
@ -65,6 +66,13 @@ public class FloatIntrinsic implements WasmIntrinsic {
|
||||||
case "isInfinite":
|
case "isInfinite":
|
||||||
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
return testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
||||||
WasmIntBinaryOperation.EQ);
|
WasmIntBinaryOperation.EQ);
|
||||||
|
case "isFinite": {
|
||||||
|
WasmExpression result = testSpecialIEEE(manager.generate(invocation.getArguments().get(0)), manager,
|
||||||
|
WasmIntBinaryOperation.EQ);
|
||||||
|
result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, result,
|
||||||
|
new WasmInt32Constant(0));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
case "floatToIntBits": {
|
case "floatToIntBits": {
|
||||||
WasmConversion conversion = new WasmConversion(WasmType.FLOAT32, WasmType.INT32, false,
|
WasmConversion conversion = new WasmConversion(WasmType.FLOAT32, WasmType.INT32, false,
|
||||||
manager.generate(invocation.getArguments().get(0)));
|
manager.generate(invocation.getArguments().get(0)));
|
||||||
|
|
|
@ -16,9 +16,6 @@ float teavm_teavm_getNaN() {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define teavm_isnan isnan
|
|
||||||
#define teavm_isinf isinf
|
|
||||||
#define teavm_isfinite isfinite
|
|
||||||
#define teavmMath_sin sin
|
#define teavmMath_sin sin
|
||||||
#define teavmMath_cos cos
|
#define teavmMath_cos cos
|
||||||
#define teavmMath_sqrt sqrt
|
#define teavmMath_sqrt sqrt
|
||||||
|
|
|
@ -39,12 +39,6 @@ TeaVM.wasm = function() {
|
||||||
putwchar(memory[buffer++]);
|
putwchar(memory[buffer++]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function towlower(code) {
|
|
||||||
return String.fromCharCode(code).toLowerCase().charCodeAt(0);
|
|
||||||
}
|
|
||||||
function towupper(code) {
|
|
||||||
return String.fromCharCode(code).toUpperCase().charCodeAt(0);
|
|
||||||
}
|
|
||||||
function currentTimeMillis() {
|
function currentTimeMillis() {
|
||||||
return new Date().getTime();
|
return new Date().getTime();
|
||||||
}
|
}
|
||||||
|
@ -94,14 +88,8 @@ TeaVM.wasm = function() {
|
||||||
obj.teavm = {
|
obj.teavm = {
|
||||||
currentTimeMillis: currentTimeMillis,
|
currentTimeMillis: currentTimeMillis,
|
||||||
nanoTime: function() { return performance.now(); },
|
nanoTime: function() { return performance.now(); },
|
||||||
isnan: isNaN,
|
|
||||||
teavm_getNaN: function() { return NaN; },
|
|
||||||
isinf: function(n) { return !isFinite(n) },
|
|
||||||
isfinite: isFinite,
|
|
||||||
putwcharsOut: (chars, count) => putwchars(controller, chars, count),
|
putwcharsOut: (chars, count) => putwchars(controller, chars, count),
|
||||||
putwcharsErr: (chars, count) => putwchars(controller, chars, count),
|
putwcharsErr: (chars, count) => putwchars(controller, chars, count),
|
||||||
towlower: towlower,
|
|
||||||
towupper: towupper,
|
|
||||||
getNativeOffset: getNativeOffset,
|
getNativeOffset: getNativeOffset,
|
||||||
logString: string => logString(string, controller),
|
logString: string => logString(string, controller),
|
||||||
logInt: logInt,
|
logInt: logInt,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user