Skip to content

Commit eb02e25

Browse files
committed
Support for larger numbers (i128, u64, i128) as well as nightly-only floats f16/f128 and greater support for different number types in bitwise and normal operations.
All backed up and verified by an expansion to the ops test.
1 parent 8d56f75 commit eb02e25

File tree

16 files changed

+2407
-780
lines changed

16 files changed

+2407
-780
lines changed

Cargo.lock

+53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
half = "2.6.0"
8+
num-bigint = "0.4.6"
9+
num-traits = "0.2.19"
710
regex = "1.11.1"
811
ristretto_classfile = { version = "0.16.0" }
912
serde = { version = "1.0.219", features = ["derive"] }
@@ -14,4 +17,4 @@ sha2 = "0.10.8"
1417
crate-type = ["dylib"]
1518

1619
[package.metadata.rust-analyzer]
17-
rustc_private=true
20+
rustc_private=true

Readme.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ This backend currently supports a subset of Rust features:
2929

3030
* ✅ Compiling minimal `no_std` & `no_core` Rust programs (like an empty `main`) using the `jvm-unknown-unknown` target.
3131
* ✅ Compiling simple programs using basic `core` features (like other tests) using the host target but this codegen backend to produce JVM bytecode.
32-
* ✅ Basic integer arithmetic operations on all types of numbers:
32+
* ✅ Basic integer arithmetic operations on all types of numbers including floats:
3333
* Addition (`+`), Subtraction (`-`), Multiplication (`*`), Division (`/`), Remainder (`%`).
34-
* Checked addition, subtraction and multiplication returning `(result, overflowed_bool)` tuples (occurs in debug mode)
35-
* ✅ Comparisons (`==`, `!=`, `<`, `<=`, `>`, `>=`).
36-
* ✅ Bitwise operations (`&`, `|`, `^`, `<<`, `>>`).
37-
* ✅ Logical operations (`&&`, `||`, `!`), support for `if` (and `else if`/`else`) and `match` statements.
34+
* Checked addition, subtraction and multiplication returning `(result, overflowed_bool)` tuples (`rustc` requests this in debug mode even for normal operations to panic on overflow).
35+
* ✅ Comparisons between all number types (`==`, `!=`, `<`, `<=`, `>`, `>=`).
36+
* ✅ Bitwise operations on all numbers (`&`, `|`, `^`, `<<`, `>>`).
37+
* ✅ Logical operations(`&&`, `||`, `!`), support for `if` (and `else if`/`else`) and `match` statements.
3838
* ✅ Unary operations (`-`, `!`).
3939
* ✅ Type casting (e.g., `as` operator).
40-
* ✅ Support for all primitive types.
40+
* ✅ Support for all Rust primitive types.
4141
* ✅ Calling other functions (including recursion).
4242
* ✅ Loops such as `for`, `while`, and `loop`.
4343
* ✅ Variable assignment including subfield and array index assignment, including nesting.
4444
* ✅ Arrays and slices, including inserting, accessing and mutating at a given index (supporting nesting).
45-
* ✅ Floats (`f32`, `f64`).
45+
* ✅ Floats (`f16`, `f32`, `f64`, `f128`) and their operations.
4646
* ✅ Structs, Tuples and Enums (including traditional C-like enums but also Rust-like enums with anonymous structs and tuples in them) including nested access/setting/mutation of fields and array indices within these.
4747
* ✅ Generating executable `.jar` files for binary crates.
4848

library/src/main/kotlin/org/rustlang/core/Core.kt

+10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public object Core {
7676
return false
7777
}
7878

79+
// Special handling for floating point types
80+
// Java's .equals() method does not handle NaN correctly (NaN == NaN which is the opposite of what Rust expects)
81+
if ((value1 is Double || value1 is Float) && (value2 is Double || value2 is Float)) {
82+
val d1 = if (value1 is Float) value1.toDouble() else value1 as Double
83+
val d2 = if (value2 is Float) value2.toDouble() else value2 as Double
84+
// Direct comparison using IEEE 754 rules (NaN != NaN)
85+
@Suppress("FloatingPointLiteralComparison") // We WANT this specific comparison
86+
return d1 == d2
87+
}
88+
7989
// 2. Handle common Kotlin/Java types where '==' gives value equality
8090
// or specific content checks are needed.
8191
val class1 = value1::class.java

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![feature(alloc_error_hook)]
22
#![feature(box_patterns)]
33
#![feature(rustc_private)]
4+
#![feature(f16)]
5+
#![feature(f128)]
46
#![warn(clippy::pedantic)]
57
#![allow(clippy::cast_possible_truncation)]
68
#![allow(clippy::cast_sign_loss)]

0 commit comments

Comments
 (0)