Skip to content

Commit 15ce14f

Browse files
committed
[java] Emit Float.isFinite/isInfinite/isNaN.
1 parent 1326a51 commit 15ce14f

5 files changed

Lines changed: 41 additions & 12 deletions

File tree

GenJava.fu

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,13 @@ public class GenJava : GenTyped
640640
WriteChar(')');
641641
}
642642

643+
void WriteMathIs!(string name, FuExpr arg)
644+
{
645+
WriteJavaType(arg.Type, true, true);
646+
Write(".is");
647+
WriteCall(name, arg);
648+
}
649+
643650
protected override void WriteCallExpr!(FuType type, FuExpr? obj, FuMethod method, List<FuExpr#> args, FuPriority parent)
644651
{
645652
switch (method.Id) {
@@ -1020,13 +1027,13 @@ public class GenJava : GenTyped
10201027
WriteCall("Math.fma", args[0], args[1], args[2]);
10211028
break;
10221029
case FuId.MathIsFinite:
1023-
WriteCall("Double.isFinite", args[0]);
1030+
WriteMathIs("Finite", args[0]);
10241031
break;
10251032
case FuId.MathIsInfinity:
1026-
WriteCall("Double.isInfinite", args[0]);
1033+
WriteMathIs("Infinite", args[0]);
10271034
break;
10281035
case FuId.MathIsNaN:
1029-
WriteCall("Double.isNaN", args[0]);
1036+
WriteMathIs("NaN", args[0]);
10301037
break;
10311038
case FuId.MathLog2:
10321039
if (type.Id == FuId.FloatType) {

libfut.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19199,6 +19199,13 @@ void GenJava::writeCompileRegex(const std::vector<std::shared_ptr<FuExpr>> * arg
1919919199
writeChar(')');
1920019200
}
1920119201

19202+
void GenJava::writeMathIs(std::string_view name, const FuExpr * arg)
19203+
{
19204+
writeJavaType(arg->type.get(), true, true);
19205+
write(".is");
19206+
writeCall(name, arg);
19207+
}
19208+
1920219209
void GenJava::writeCallExpr(const FuType * type, const FuExpr * obj, const FuMethod * method, const std::vector<std::shared_ptr<FuExpr>> * args, FuPriority parent)
1920319210
{
1920419211
switch (method->id) {
@@ -19572,13 +19579,13 @@ void GenJava::writeCallExpr(const FuType * type, const FuExpr * obj, const FuMet
1957219579
writeCall("Math.fma", (*args)[0].get(), (*args)[1].get(), (*args)[2].get());
1957319580
break;
1957419581
case FuId::mathIsFinite:
19575-
writeCall("Double.isFinite", (*args)[0].get());
19582+
writeMathIs("Finite", (*args)[0].get());
1957619583
break;
1957719584
case FuId::mathIsInfinity:
19578-
writeCall("Double.isInfinite", (*args)[0].get());
19585+
writeMathIs("Infinite", (*args)[0].get());
1957919586
break;
1958019587
case FuId::mathIsNaN:
19581-
writeCall("Double.isNaN", (*args)[0].get());
19588+
writeMathIs("NaN", (*args)[0].get());
1958219589
break;
1958319590
case FuId::mathLog2:
1958419591
if (type->id == FuId::floatType) {

libfut.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19815,6 +19815,13 @@ void WriteCompileRegex(List<FuExpr> args, int argIndex)
1981519815
WriteChar(')');
1981619816
}
1981719817

19818+
void WriteMathIs(string name, FuExpr arg)
19819+
{
19820+
WriteJavaType(arg.Type, true, true);
19821+
Write(".is");
19822+
WriteCall(name, arg);
19823+
}
19824+
1981819825
protected override void WriteCallExpr(FuType type, FuExpr obj, FuMethod method, List<FuExpr> args, FuPriority parent)
1981919826
{
1982019827
switch (method.Id) {
@@ -20186,13 +20193,13 @@ protected override void WriteCallExpr(FuType type, FuExpr obj, FuMethod method,
2018620193
WriteCall("Math.fma", args[0], args[1], args[2]);
2018720194
break;
2018820195
case FuId.MathIsFinite:
20189-
WriteCall("Double.isFinite", args[0]);
20196+
WriteMathIs("Finite", args[0]);
2019020197
break;
2019120198
case FuId.MathIsInfinity:
20192-
WriteCall("Double.isInfinite", args[0]);
20199+
WriteMathIs("Infinite", args[0]);
2019320200
break;
2019420201
case FuId.MathIsNaN:
20195-
WriteCall("Double.isNaN", args[0]);
20202+
WriteMathIs("NaN", args[0]);
2019620203
break;
2019720204
case FuId.MathLog2:
2019820205
if (type.Id == FuId.FloatType) {

libfut.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,6 +3308,7 @@ class GenJava : public GenTyped
33083308
void writeCollectionGet(const FuExpr * obj, std::string_view method, FuPriority parent);
33093309
void writeWrite(const FuMethod * method, const std::vector<std::shared_ptr<FuExpr>> * args, bool newLine);
33103310
void writeCompileRegex(const std::vector<std::shared_ptr<FuExpr>> * args, int argIndex);
3311+
void writeMathIs(std::string_view name, const FuExpr * arg);
33113312
void createJavaFile(std::string_view className);
33123313
void writeSignature(const FuMethod * method, int paramCount);
33133314
void writeOverloads(const FuMethod * method, int paramCount);

libfut.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20417,6 +20417,13 @@ export class GenJava extends GenTyped
2041720417
this.writeChar(41);
2041820418
}
2041920419

20420+
#writeMathIs(name, arg)
20421+
{
20422+
this.#writeJavaType(arg.type, true, true);
20423+
this.write(".is");
20424+
this.writeCall(name, arg);
20425+
}
20426+
2042020427
writeCallExpr(type, obj, method, args, parent)
2042120428
{
2042220429
switch (method.id) {
@@ -20791,13 +20798,13 @@ export class GenJava extends GenTyped
2079120798
this.writeCall("Math.fma", args[0], args[1], args[2]);
2079220799
break;
2079320800
case FuId.MATH_IS_FINITE:
20794-
this.writeCall("Double.isFinite", args[0]);
20801+
this.#writeMathIs("Finite", args[0]);
2079520802
break;
2079620803
case FuId.MATH_IS_INFINITY:
20797-
this.writeCall("Double.isInfinite", args[0]);
20804+
this.#writeMathIs("Infinite", args[0]);
2079820805
break;
2079920806
case FuId.MATH_IS_NA_N:
20800-
this.writeCall("Double.isNaN", args[0]);
20807+
this.#writeMathIs("NaN", args[0]);
2080120808
break;
2080220809
case FuId.MATH_LOG2:
2080320810
if (type.id == FuId.FLOAT_TYPE) {

0 commit comments

Comments
 (0)