-
Notifications
You must be signed in to change notification settings - Fork 7
frontend: simplify uses of comparison operators #466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b0a0ac
frontend: simplify uses of comparison operators
mikesamuel 1da4744
be-rust: Require parens for as inside cmp
tjpalmer 3f3210f
Fix backend tests
tjpalmer 1bcb7ed
be-rust: Require parens for as inside cmp (#467)
mikesamuel 9243cd0
fix obvious bug in Temper code in a testcase
mikesamuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -441,7 +441,7 @@ class RustBackendTest { | |
| |} | ||
| |pub fn hi(n__0: i32) { | ||
| | let mut i__0: i32 = 0; | ||
| | 'loop___0: while Some(i__0) < Some(n__0) { | ||
| | 'loop___0: while i__0 < n__0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Losing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Comparisons were just doing too much. Uses of non-nullable types shouldn't pay for null-safety. |
||
| | let mut a__0: std::sync::Arc<std::sync::RwLock<std::sync::Arc<String>>> = std::sync::Arc::new(std::sync::RwLock::new(std::sync::Arc::new(format!("{}", i__0)))); | ||
| | #[derive(Clone)] | ||
| | struct ClosureGroup___0 { | ||
|
|
@@ -495,7 +495,7 @@ class RustBackendTest { | |
| |} | ||
| |fn repeat__0(times__0: i32, act__0: std::sync::Arc<dyn Fn (i32) + std::marker::Send + std::marker::Sync>) { | ||
| | let mut i__0: i32 = 0; | ||
| | 'loop___0: while Some(i__0) < Some(times__0) { | ||
| | 'loop___0: while i__0 < times__0 { | ||
| | act__0(i__0); | ||
| | i__0 = i__0.wrapping_add(1); | ||
| | } | ||
|
|
@@ -648,6 +648,34 @@ class RustBackendTest { | |
| """.trimMargin(), | ||
| ) | ||
|
|
||
| @Test | ||
| fun floatComparisons() = assertGenerateWanted( | ||
| temper = """ | ||
| |export let f(a: Float64, b: Float64): Boolean { | ||
| | a != b && a < b + 1.0 | ||
| |} | ||
| """.trimMargin(), | ||
| rust = """ | ||
| |pub (crate) fn init() -> temper_core::Result<()> { | ||
| | static INIT_ONCE: std::sync::OnceLock<temper_core::Result<()>> = std::sync::OnceLock::new(); | ||
| | INIT_ONCE.get_or_init(| |{ | ||
| | Ok(()) | ||
| | }).clone() | ||
| |} | ||
| |pub fn f(a__0: f64, b__0: f64) -> bool { | ||
| | let return__0: bool; | ||
| | let mut t___0: f64; | ||
| | if temper_core::float64::cmp_option(Some(a__0), Some(b__0)) != 0 { | ||
| | t___0 = b__0 + 1.0f64; | ||
| | return__0 = temper_core::float64::cmp(a__0, t___0) < 0; | ||
| | } else { | ||
| | return__0 = false; | ||
| | } | ||
| | return return__0; | ||
| |} | ||
| """.trimMargin(), | ||
| ) | ||
|
|
||
| @Test | ||
| fun funArgWrong() = assertGenerateWanted( | ||
| temper = """ | ||
|
|
@@ -759,11 +787,11 @@ class RustBackendTest { | |
| | let this__0: temper_core::List<i32> = nums__0.clone(); | ||
| | let n__0: i32 = temper_core::ListedTrait::len( & this__0); | ||
| | let mut i__0: i32 = 0; | ||
| | 'loop___0: while Some(i__0) < Some(n__0) { | ||
| | 'loop___0: while i__0 < n__0 { | ||
| | let el__0: i32 = temper_core::ListedTrait::get( & this__0, i__0); | ||
| | i__0 = i__0.wrapping_add(1); | ||
| | let i__1: i32 = el__0; | ||
| | t___0 = Some(i__1) < Some(temper_core::ListedTrait::len( & nums__0)); | ||
| | t___0 = i__1 < temper_core::ListedTrait::len( & nums__0); | ||
| | #[derive(Clone)] | ||
| | struct ClosureGroup___0 {} | ||
| | impl ClosureGroup___0 { | ||
|
|
@@ -1008,7 +1036,7 @@ class RustBackendTest { | |
| |pub fn fib(mut i__0: i32) -> i32 { | ||
| | let mut a__0: i32 = 0; | ||
| | let mut b__0: i32 = 1; | ||
| | 'loop___0: while Some(i__0) > Some(0) { | ||
| | 'loop___0: while i__0 > 0 { | ||
| | let c__0: i32 = a__0.wrapping_add(b__0); | ||
| | a__0 = b__0; | ||
| | b__0 = c__0; | ||
|
|
@@ -2019,7 +2047,7 @@ class RustBackendTest { | |
| | let mut t___0: i32; | ||
| | 'outer__0: loop { | ||
| | let mut j__0: i32 = 0; | ||
| | 'loop___0: while Some(j__0) < Some(n__0) { | ||
| | 'loop___0: while j__0 < n__0 { | ||
| | continue 'outer__0; | ||
| | } | ||
| | break; | ||
|
|
@@ -2028,11 +2056,11 @@ class RustBackendTest { | |
| | 'loop___1: loop { | ||
| | 'continue___0: { | ||
| | t___0 = temper_core::ListedTrait::len( & nums__0); | ||
| | if ! (Some(i__0) < Some(t___0)) { | ||
| | if ! (i__0 < t___0) { | ||
| | break 'loop___1; | ||
| | } | ||
| | let mut j__1: i32 = 0; | ||
| | 'loop___2: while Some(j__1) < Some(n__0) { | ||
| | 'loop___2: while j__1 < n__0 { | ||
| | break 'continue___0; | ||
| | } | ||
| | } | ||
|
|
@@ -2075,7 +2103,7 @@ class RustBackendTest { | |
| |} | ||
| |pub fn part_one(i__0: i32) -> i32 { | ||
| | let return__0: i32; | ||
| | if Some(i__0) < Some(0) { | ||
| | if i__0 < 0 { | ||
| | return__0 = part_two(i__0); | ||
| | } else { | ||
| | return__0 = i__0; | ||
|
|
@@ -2770,7 +2798,7 @@ class RustBackendTest { | |
| | var i = start; | ||
| | while (i.compareTo(limit) < 0) { | ||
| | let cp = sourceText[i]; | ||
| | let digit = if (char'0' <= cp && cp <= char'0') { | ||
| | let digit = if (char'0' <= cp && cp <= char'9') { | ||
| | cp - char'0' | ||
| | } else if (char'A' <= cp && cp <= char'F') { | ||
| | cp - char'A' + 10 | ||
|
|
@@ -2803,28 +2831,28 @@ class RustBackendTest { | |
| | let mut n__0: i32 = 0; | ||
| | let mut i__0: usize = start__0; | ||
| | 'loop___0: loop { | ||
| | if ! (Some(Some(i__0).cmp( & Some(limit__0)) as i32) < Some(0)) { | ||
| | if ! ((Some(i__0).cmp( & Some(limit__0)) as i32) < 0) { | ||
| | break; | ||
| | } | ||
| | let cp__0: i32 = temper_core::string::get( & sourceText__0, i__0); | ||
| | if Some(48) <= Some(cp__0) { | ||
| | t___0 = Some(cp__0) <= Some(48); | ||
| | if 48 <= cp__0 { | ||
| | t___0 = cp__0 <= 57; | ||
| | } else { | ||
| | t___0 = false; | ||
| | } | ||
| | if t___0 { | ||
| | t___3 = cp__0.wrapping_sub(48); | ||
| | } else { | ||
| | if Some(65) <= Some(cp__0) { | ||
| | t___1 = Some(cp__0) <= Some(70); | ||
| | if 65 <= cp__0 { | ||
| | t___1 = cp__0 <= 70; | ||
| | } else { | ||
| | t___1 = false; | ||
| | } | ||
| | if t___1 { | ||
| | t___3 = cp__0.wrapping_sub(65).wrapping_add(10); | ||
| | } else { | ||
| | if Some(97) <= Some(cp__0) { | ||
| | t___2 = Some(cp__0) <= Some(102); | ||
| | if 97 <= cp__0 { | ||
| | t___2 = cp__0 <= 102; | ||
| | } else { | ||
| | t___2 = false; | ||
| | } | ||
|
|
@@ -2862,7 +2890,7 @@ class RustBackendTest { | |
| | }).clone() | ||
| |} | ||
| |pub fn not_empty(start__0: usize, limit__0: usize) -> bool { | ||
| | return Some(Some(start__0).cmp( & Some(limit__0)) as i32) < Some(0); | ||
| | return (Some(start__0).cmp( & Some(limit__0)) as i32) < 0; | ||
| |} | ||
| """.trimMargin(), | ||
| ) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want
==and!=for ints to eventually be non-null accepting, but for now, they still are.