Skip to content

Commit 0e4b5ad

Browse files
committed
Support for dynamic dispatch (&dyn Trait) and more idiomatic implementation of Traits (they are now interfaces)
1 parent c0ed2aa commit 0e4b5ad

File tree

25 files changed

+1332
-302
lines changed

25 files changed

+1332
-302
lines changed

Cargo.lock

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ md5 = "0.7.0"
1111
num-bigint = "0.4.6"
1212
num-traits = "0.2.19"
1313
regex = "1.11.1"
14-
ristretto_classfile = { version = "0.16.0" }
14+
ristretto_classfile = { path="../ristretto/ristretto_classfile" }
1515
serde = { version = "1.0.219", features = ["derive"] }
1616
serde_json = "1.0.140"
1717
sha2 = "0.10.8"

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ All examples live in `tests/binary` and are compiled to JVM bytecode & run/teste
3232
- **[Collatz conjecture](tests/binary/collatz/src/main.rs)** verifier
3333
- **[Large prime](tests/binary/primes/src/main.rs)** generator
3434
- Use of nested data structures: enums, structs, tuples, arrays, slices (**[enums](tests/binary/enums/src/main.rs)**, **[structs](tests/binary/structs/src/main.rs)** - both tests use arrays and tuples)
35-
* **[Implementation blocks](tests/binary/impl/src/main.rs)** and **[traits](tests/binary/traits/src/main.rs)**
35+
* **[Implementation blocks](tests/binary/impl/src/main.rs)** and **[traits](tests/binary/traits/src/main.rs)** (including dynamic dispatch!)
3636
- …and more!
3737

3838
---
@@ -52,7 +52,7 @@ All examples live in `tests/binary` and are compiled to JVM bytecode & run/teste
5252
- Executable `.jar` generation for binary crates
5353
- Mutable borrowing, references, and dereferencing
5454
- Implementations for ADTs, including using and returning `self`, `&self`, `&mut self`
55-
- Traits!
55+
- Traits, including dynamic dispatch (`&dyn Trait`)
5656
- **Integration tests** for all features, in debug and release modes
5757

5858
🚧 **Next Milestone:** Full support for the Rust `core` crate.

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package org.rustlang.core
33
import java.lang.reflect.Field
44
import java.util.Objects
55

6+
7+
public interface partialeq {
8+
9+
}
10+
611
/**
712
* Core functions needed by the Rust JVM backend stdlib shim.
813
*/
@@ -109,16 +114,11 @@ public object Core {
109114
}
110115

111116
@JvmStatic
112-
public fun arguments_new_v1(pieces: Array<String>, args: Array<Any?>): String {
117+
public fun core_fmt_rt_arguments_new_const_1(pieces: Array<String>): String {
113118
val sb = StringBuilder()
114119
var argIndex = 0
115120
for (i in pieces.indices) {
116-
sb.append(pieces[i]) // Append static piece
117-
if (argIndex < args.size) {
118-
// Append the corresponding argument (already formatted or convertible via toString)
119-
sb.append(args[argIndex]?.toString() ?: "null")
120-
argIndex++
121-
}
121+
sb.append(pieces[i])
122122
}
123123
return sb.toString()
124124
}
@@ -267,8 +267,8 @@ public object Core {
267267
}
268268

269269
@JvmStatic
270-
// tuple (i32, u8, bool)
271-
public fun i32_u8_bool_eq(value1: Any?, value2: Any?): Boolean {
270+
// tuple (i32, u8)
271+
public fun i32_u8_eq(value1: Any?, value2: Any?): Boolean {
272272
return eq(value1, value2)
273273
}
274274

proguard/default.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
-keep public class * { public static void main(java.lang.String[]); }
22
-keep class * {
33
<fields>;
4+
}
5+
-keepclassmembers class * implements * {
6+
<methods>;
47
}

shim-metadata-gen/core.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"descriptor": "([Ljava/lang/String;)Ljava/lang/String;",
44
"is_static": true
55
},
6-
"arguments_new_v1": {
7-
"descriptor": "([Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;",
8-
"is_static": true
9-
},
106
"core_assert_failed": {
117
"descriptor": "(Ljava/lang/String;)V",
128
"is_static": true
@@ -27,6 +23,10 @@
2723
"descriptor": "(I)Ljava/lang/String;",
2824
"is_static": true
2925
},
26+
"core_fmt_rt_arguments_new_const_1": {
27+
"descriptor": "([Ljava/lang/String;)Ljava/lang/String;",
28+
"is_static": true
29+
},
3030
"core_panicking_panic": {
3131
"descriptor": "(Ljava/lang/String;)V",
3232
"is_static": true
@@ -83,7 +83,7 @@
8383
"descriptor": "(Ljava/lang/Object;Ljava/lang/Object;)Z",
8484
"is_static": true
8585
},
86-
"i32_u8_bool_eq": {
86+
"i32_u8_eq": {
8787
"descriptor": "(Ljava/lang/Object;Ljava/lang/Object;)Z",
8888
"is_static": true
8989
},

0 commit comments

Comments
 (0)