Skip to content

Commit 619b7c2

Browse files
committed
Lower bool literals to Rust
1 parent d9b77ee commit 619b7c2

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ If a lowered package contains `fn main() -> Unit` or `fn main() -> Result<Unit,
418418

419419
`rss verify-rust <file.rss> --out-dir <directory>` keeps the generated package used for backend checking, including `rsscript-source-map.json`, so unmappable rustc diagnostics can be inspected against the generated Rust.
420420

421-
The first observable runtime boundaries are `Log.write(message: read String)` and `Assert.equal(left: read String, right: read String)`, which lower to explicit runtime hooks. Simple core operations such as `String.concat(left: read String, right: read String)` keep RSScript `.rssi` signatures for checking and review, but lower directly to Rust standard-library expressions. Built-in numeric and comparison operators lower to the corresponding Rust operators; user-defined operator overloading remains forbidden.
421+
The first observable runtime boundaries are `Log.write(message: read String)` and `Assert.equal(left: read String, right: read String)`, which lower to explicit runtime hooks. Simple core operations such as `String.concat(left: read String, right: read String)` keep RSScript `.rssi` signatures for checking and review, but lower directly to Rust standard-library expressions. Built-in boolean literals, numeric operators, and comparison operators lower to the corresponding Rust literals and operators; user-defined operator overloading remains forbidden.
422422

423423
Smallest runnable example:
424424

examples/bool_literals.rss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() -> Unit {
2+
let _ = true != false
3+
if true {
4+
Log.write(message: read "bool literals ran")
5+
}
6+
return Unit
7+
}

src/rust_lower.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ fn is_resource_pool_borrow_expr(expr: &Expr) -> bool {
10801080
fn lower_builtin_value_ident(name: &str) -> Option<&'static str> {
10811081
match name {
10821082
"Unit" => Some("()"),
1083+
"true" => Some("true"),
1084+
"false" => Some("false"),
10831085
"None" => Some("None"),
10841086
_ => None,
10851087
}

tests/checker.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,23 @@ fn main() -> Unit {
354354
assert!(rust.contains("let greater_equal = product >= quotient;"));
355355
}
356356

357+
#[test]
358+
fn rust_lowering_maps_bool_literals_to_rust_literals() {
359+
let source = r#"
360+
fn main() -> Unit {
361+
let enabled = true
362+
let disabled = false
363+
let changed = enabled != disabled
364+
return Unit
365+
}
366+
"#;
367+
let rust = lower_source_to_rust("bool.rss", source).expect("source should lower");
368+
369+
assert!(rust.contains("let enabled = true;"));
370+
assert!(rust.contains("let disabled = false;"));
371+
assert!(rust.contains("let changed = enabled != disabled;"));
372+
}
373+
357374
#[test]
358375
fn rust_lowering_maps_try_operator_to_rust_result_propagation() {
359376
let source = r#"

0 commit comments

Comments
 (0)