Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1239,13 +1239,13 @@ class CSharpBackendTest {
| {
| string t___0;
| string ? t__0 = C::Optional.OrNull<string>(new Identity<string>().Identity_(C::Optional.Of<string>(s__0)));
| if (!(t__0 == null))
| if (t__0 == null)
| {
| t___0 = t__0!;
| t___0 = "not";
| }
| else
| {
| t___0 = "not";
| t___0 = t__0!;
| }
| console___0.Log(t___0);
| }
Expand Down
24 changes: 12 additions & 12 deletions be-js/src/commonTest/kotlin/lang/temper/be/js/JsBackendTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1801,16 +1801,16 @@ class JsBackendTest {
| let body_0;
|## Similarly for body content.
| t_1 = yield await_0(netResponseGetBodyContent_0(r_0));
| if (!(t_1 == null)) {
| body_0 = t_1;
| } else {
| if (t_1 == null) {
| body_0 = "missing";
| } else {
| body_0 = t_1;
| }
| t_0 = netResponseGetContentType_0(r_0);
| if (!(t_0 == null)) {
| t_2 = t_0;
| } else {
| if (t_0 == null) {
| t_2 = "unknown";
| } else {
| t_2 = t_0;
| }
| console_0.log("Got " + body_0 + " / " + t_2);
| }
Expand Down Expand Up @@ -1865,10 +1865,10 @@ class JsBackendTest {
| */
| export function prod(i_0, j_0) {
| let t_0;
| if (!(j_0 == null)) {
| t_0 = j_0;
| } else {
| if (j_0 == null) {
| t_0 = 1;
| } else {
| t_0 = j_0;
| }
| return imul_0(i_0, t_0);
| };
Expand All @@ -1880,10 +1880,10 @@ class JsBackendTest {
| export function prodWrap(i_1, j_2) {
| let t_1;
| let t_2 = listedGet_0(j_2, 0);
| if (!(t_2 == null)) {
| t_1 = t_2;
| } else {
| if (t_2 == null) {
| t_1 = 1;
| } else {
| t_1 = t_2;
| }
| return imul_0(i_1, t_1);
| };
Expand Down
12 changes: 6 additions & 6 deletions be-py/src/commonTest/kotlin/lang/temper/be/py/PyBackendTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,15 @@ class PyBackendTest {
| if r_3.status == 200:
| body_4: 'str6'
| t_31 = yield do_await_4(r_3.text)
| if not t_31 is None:
| body_4 = t_31
| else:
| if t_31 is None:
| body_4 = 'missing'
| t_59 = r_3.content_type
| if not t_59 is None:
| t_36 = t_59
| else:
| body_4 = t_31
| t_59 = r_3.content_type
| if t_59 is None:
| t_36 = 'unknown'
| else:
| t_36 = t_59
| console_5.log(str_cat_73('Got ', body_4, ' / ', t_36))
| except Exception7:
| console_5.log('failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum class RustOperatorDefinition(
// Copied from CSharpOperatorDefinition.
override fun canNest(inner: OperatorDefinition, childIndex: Int) = when {
inner !is RustOperatorDefinition -> false
this == Relational && inner == As -> false // `as T < ...` interpreted as generic arguments
ordinal < inner.ordinal -> true
ordinal > inner.ordinal -> false
// TODO Does this allow `==` to nest?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,13 @@ private class Float64Compare(
returnType: Type2,
translator: RustTranslator,
): Rust.Expr {
val cmpFn = when (operator) {
RustOperator.Equals, RustOperator.NotEquals -> "cmp_option"

Copy link
Copy Markdown
Contributor Author

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.

else -> "cmp"
}
return Rust.Call(
pos,
callee = "temper_core".toKeyId(pos).extendWith(listOf("float64", "cmp_option")),
callee = "temper_core".toKeyId(pos.leftEdge).extendWith(listOf("float64", cmpFn)),
args = arguments.map { it.expr as Rust.Expr },
).infix(operator, Rust.NumberLiteral(pos, 0L))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Losing the Some is nice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 {
Expand Down Expand Up @@ -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);
| }
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
| }
| }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
| }
Expand Down Expand Up @@ -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(),
)
Expand Down
14 changes: 7 additions & 7 deletions be/src/commonTest/kotlin/lang/temper/be/tmpl/TmpLBackendTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class TmpLBackendTest {
"content":
```
//// work//for/ => for.tmpl
let nym`<#1` = builtins.nym`<` /* (Int32?, Int32?) -> Boolean */;
let nym`<#1` = builtins.nym`<` /* (Int32, Int32) -> Boolean */;
let nym`+#2` = builtins.nym`+` /* (Int32, Int32) -> Int32 */;
@QName("test-library/for.x=") var x__0: Int32 = 0;
module init {
Expand Down Expand Up @@ -383,7 +383,7 @@ class TmpLBackendTest {
| "content":
| ```
| //// work//fib/ => fib.tmpl
| let nym`>#9` = builtins.nym`>` /* (Int32?, Int32?) -> Boolean */;
| let nym`>#9` = builtins.nym`>` /* (Int32, Int32) -> Boolean */;
| let nym`+#10` = builtins.nym`+` /* (Int32, Int32) -> Int32 */;
| let nym`-#11` = builtins.nym`-` /* (Int32, Int32) -> Int32 */;
| @QName("test-library/fib.fib()") let fib__0(@QName("test-library/fib.fib().(i)") var i__0: Int32): Int32 {
Expand Down Expand Up @@ -638,7 +638,7 @@ class TmpLBackendTest {
"content":
```
//// work//do-nothing/ => do-nothing.tmpl
let nym`<#1` = builtins.nym`<` /* (Int32?, Int32?) -> Boolean */;
let nym`<#1` = builtins.nym`<` /* (Int32, Int32) -> Boolean */;
let nym`+#2` = builtins.nym`+` /* (Int32, Int32) -> Int32 */;
@QName("test-library/do-nothing.i") var i__0: Int32 = 0;
module init {
Expand Down Expand Up @@ -2076,10 +2076,10 @@ class TmpLBackendTest {
| content: ```
| //// work//foo/ => foo.tmpl
| let GetConsole#0 = builtins.GetConsole;
| let nym`<=#28` = builtins.nym`<=` /* (Int32?, Int32?) -> Boolean */;
| let nym`<=#28` = builtins.nym`<=` /* (Int32, Int32) -> Boolean */;
| let ConsoleLog#0 = builtins.ConsoleLog;
| let nym`+#30` = builtins.nym`+` /* (Int32, Int32) -> Int32 */;
| let nym`>=#31` = builtins.nym`>=` /* (Int32?, Int32?) -> Boolean */;
| let nym`>=#31` = builtins.nym`>=` /* (Int32, Int32) -> Boolean */;
| let console#0: Console = GetConsole#0();
| @QName("test-library/foo.f()") @reach(\none) let f__0(): Void {
| var t#0: Int32;
Expand Down Expand Up @@ -3103,7 +3103,7 @@ class TmpLBackendTest {
| content:
| ```
| //// work//bubble-ordering/ => bubble-ordering.tmpl
| let nym`<=#24` = builtins.nym`<=` /* (Int32?, Int32?) -> Boolean */;
| let nym`<=#24` = builtins.nym`<=` /* (Int32, Int32) -> Boolean */;
| @QName("test-library/bubble-ordering.type Apple") class Apple / Apple {
| @QName("test-library/bubble-ordering.type Apple.maybe()") let maybe__0(this = this__0, @QName("test-library/bubble-ordering.type Apple.maybe().(this)") @impliedThis(Apple) this__0: Apple): Apple | Bubble {
| return /* this */ this__0;
Expand Down Expand Up @@ -3148,7 +3148,7 @@ class TmpLBackendTest {
| content:
| ```
| //// work//bubble-ordering/ => bubble-ordering.tmpl
| let nym`<=#24` = builtins.nym`<=` /* (Int32?, Int32?) -> Boolean */;
| let nym`<=#24` = builtins.nym`<=` /* (Int32, Int32) -> Boolean */;
| @fail var fail#0: Boolean;
| @fail var fail#1: Boolean;
| @QName("test-library/bubble-ordering.type Apple") class Apple / Apple {
Expand Down
Loading
Loading