Skip to content

Commit 8d2fc10

Browse files
committed
Add support for casting primitives, expand comparsions/bitwise operations to support all rust primitives
- Includes a new test for both casting functionality and comparsions and bitwise across various rust primitive types including of different sizes and floats.
1 parent 01e5ec6 commit 8d2fc10

File tree

18 files changed

+1697
-856
lines changed

18 files changed

+1697
-856
lines changed

Tester.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def read_from_file(path: str) -> str:
99
return f.read()
1010

1111
def normalize_name(test_name: str) -> str:
12-
# Replace underscores with spaces and capitalize the first letter.
1312
return test_name.replace("_", " ").capitalize()
1413

1514
def run_command(cmd: list, cwd=None):
@@ -25,7 +24,6 @@ def process_test(test_dir: str, release_mode: bool):
2524
normalized = normalize_name(test_name)
2625
print(f"|-- Test '{test_name}' ({normalized})")
2726

28-
# Clean the folder: with cargo clean
2927
print("|--- 🧼 Cleaning test folder...")
3028
proc = run_command(["cargo", "clean"], cwd=test_dir)
3129
if proc.returncode != 0:
@@ -35,7 +33,6 @@ def process_test(test_dir: str, release_mode: bool):
3533
print(f"|---- ❌ cargo clean exited with code {proc.returncode}")
3634
return False
3735

38-
# Run cargo build.
3936
print("|--- ⚒️ Building with Cargo...")
4037
build_cmd = ["cargo", "build", "--release"] if release_mode else ["cargo", "build"]
4138
no_jvm_target = os.path.join(test_dir, "no_jvm_target.flag")
@@ -50,7 +47,6 @@ def process_test(test_dir: str, release_mode: bool):
5047
print(f"|---- ❌ cargo build exited with code {proc.returncode}")
5148
return False
5249

53-
# Run java with the generated jar.
5450
print("|--- 🤖 Running with Java...")
5551
target_dir = "release" if release_mode else "debug"
5652
if os.path.exists(no_jvm_target):
@@ -64,11 +60,12 @@ def process_test(test_dir: str, release_mode: bool):
6460
print("|---- ❌ No jar file found in target/{target_dir}/deps")
6561
return False
6662
os.makedirs(os.path.join(test_dir, "target", "jvm-unknown-unknown", target_dir), exist_ok=True)
67-
os.rename(os.path.join(test_dir, "target", target_dir, "deps", jar_file), os.path.join(test_dir, "target", "jvm-unknown-unknown", target_dir, f"{test_name}.jar"))
63+
os.rename(os.path.join(test_dir, "target", target_dir, "deps", jar_file),
64+
os.path.join(test_dir, "target", "jvm-unknown-unknown", target_dir, f"{test_name}.jar"))
65+
6866
jar_path = os.path.join(test_dir, "target", "jvm-unknown-unknown", target_dir, f"{test_name}.jar")
6967
proc = run_command(["java", "-jar", jar_path])
7068

71-
# Check for java-returncode.expected
7269
expected_returncode_file = os.path.join(test_dir, "java-returncode.expected")
7370
if os.path.exists(expected_returncode_file):
7471
expected_returncode = int(read_from_file(expected_returncode_file).strip())
@@ -86,17 +83,14 @@ def process_test(test_dir: str, release_mode: bool):
8683
print(f"|---- ❌ java exited with code {proc.returncode}")
8784
return False
8885

89-
# Compare the STDOUT and STDERR to {test_dir}/java-output.expected
9086
expected_file = os.path.join(test_dir, "java-output.expected")
9187
if os.path.exists(expected_file):
9288
expected_output = read_from_file(expected_file)
93-
# special case: blank file = no STDOUT or STDERR expected
9489
if expected_output.strip() == "":
9590
expected_output = "STDOUT:STDERR:"
9691
else:
9792
expected_output = expected_output.replace("\n", "")
9893
actual_output = f"STDOUT:{proc.stdout.strip()}STDERR:{proc.stderr.strip()}"
99-
# remove all remaining newlines
10094
actual_output = actual_output.replace("\n", "")
10195
if actual_output != expected_output.strip():
10296
diff_path = os.path.join(test_dir, "output-diff.generated")
@@ -114,6 +108,7 @@ def process_test(test_dir: str, release_mode: bool):
114108
def main():
115109
parser = argparse.ArgumentParser(description="Tester for Rustc's JVM Codegen Backend")
116110
parser.add_argument("--release", action="store_true", help="Run cargo in release mode")
111+
parser.add_argument("--only-run", type=str, help="Comma-separated list of specific test names to run")
117112
args = parser.parse_args()
118113

119114
print("🧪 Tester for Rustc's JVM Codegen Backend started!")
@@ -124,19 +119,24 @@ def main():
124119

125120
print(" ")
126121

127-
# Process binary tests.
122+
# Gather test directories
128123
binary_dir = os.path.join("tests", "binary")
129124
if os.path.isdir(binary_dir):
130125
binary_tests = [os.path.join(binary_dir, d) for d in os.listdir(binary_dir) if os.path.isdir(os.path.join(binary_dir, d))]
131126
else:
132127
binary_tests = []
133-
print(f"|- 📦 Running {len(binary_tests)} binary build tests...")
134-
for idx, test_dir in enumerate(binary_tests):
128+
129+
# Filter based on --only-run
130+
if args.only_run:
131+
requested_tests = set([name.strip() for name in args.only_run.split(",")])
132+
binary_tests = [t for t in binary_tests if os.path.basename(t) in requested_tests]
133+
134+
print(f"|- 📦 Running {len(binary_tests)} binary build test(s)...")
135+
for test_dir in binary_tests:
135136
if not process_test(test_dir, args.release):
136137
overall_success = False
137138

138139
print("")
139-
140140
if overall_success:
141141
print("|-✅ All tests passed!")
142142
sys.exit(0)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ public object Core {
6868
// Check for equality.
6969
return value1 == value2
7070
}
71+
72+
@JvmStatic
73+
public fun core_panicking_panic(message: String?) {
74+
// This is a placeholder for the panic function.
75+
// In a real implementation, this would handle the panic appropriately.
76+
throw RuntimeException("Rust panic: " + (message ?: "<no message>"))
77+
}
7178
}

shim-metadata-gen/core.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"descriptor": "(I)Ljava/lang/String;",
2424
"is_static": true
2525
},
26+
"core_panicking_panic": {
27+
"descriptor": "(Ljava/lang/String;)V",
28+
"is_static": true
29+
},
2630
"eq": {
2731
"descriptor": "(Ljava/lang/Object;Ljava/lang/Object;)Z",
2832
"is_static": true

src/lower1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_middle::{
1616
use std::collections::HashMap;
1717
use types::ty_to_oomir_type;
1818

19-
mod checked_ops;
2019
mod control_flow;
2120
mod operand;
2221
mod place;

0 commit comments

Comments
 (0)