fix: int value not correctly recognized

This commit is contained in:
TopchetoEU 2024-09-14 19:54:42 +03:00
parent 9b957335bf
commit 0670ffcdd1
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
3 changed files with 11 additions and 1 deletions

View File

@ -383,6 +383,15 @@ public class SimpleRepl {
}
System.out.println();
return Value.UNDEFINED;
}));
glob.defineOwnMember(null, "measure", new NativeFunction("measure", args -> {
var start = System.nanoTime();
((FunctionValue)args.get(0)).invoke(args.env, Value.UNDEFINED);
System.out.println(String.format("Finished in %sns", System.nanoTime() - start));
return Value.UNDEFINED;
}));
}

View File

@ -522,6 +522,7 @@ public abstract class Value {
else if (this instanceof VoidValue) return ((VoidValue)this).name;
else if (this instanceof StringValue) return JSON.stringify(JSONElement.string(((StringValue)this).value));
else if (this instanceof SymbolValue) return this.toString();
else if (this instanceof NumberValue num && num.isLong()) return num.getLong() + "i";
else return this.toString(env);
}

View File

@ -4,7 +4,7 @@ public final class IntValue extends NumberValue {
public final long value;
@Override public boolean isInt() {
return (value & 0xFFFFFFFF00000000l) == 0;
return (int)value == value;
}
@Override public boolean isLong() {
return true;