From dd3d0a188efbfa9523e2bea13c3a4316310940c9 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 23 Apr 2023 18:16:08 +0200 Subject: [PATCH] string is empty for dev backend --- crates/compiler/builtins/bitcode/src/main.zig | 2 ++ crates/compiler/builtins/bitcode/src/str.zig | 4 ++++ crates/compiler/builtins/src/bitcode.rs | 1 + crates/compiler/gen_dev/src/lib.rs | 4 ++++ crates/compiler/test_gen/src/gen_str.rs | 8 ++++---- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/compiler/builtins/bitcode/src/main.zig b/crates/compiler/builtins/bitcode/src/main.zig index 6f0b59468d..9c871ccad1 100644 --- a/crates/compiler/builtins/bitcode/src/main.zig +++ b/crates/compiler/builtins/bitcode/src/main.zig @@ -133,6 +133,8 @@ comptime { exportStrFn(str.countSegments, "count_segments"); exportStrFn(str.countGraphemeClusters, "count_grapheme_clusters"); exportStrFn(str.countUtf8Bytes, "count_utf8_bytes"); + exportStrFn(str.isEmpty, "is_empty"); + exportStrFn(str.getCapacity, "capacity"); exportStrFn(str.startsWith, "starts_with"); exportStrFn(str.startsWithScalar, "starts_with_scalar"); diff --git a/crates/compiler/builtins/bitcode/src/str.zig b/crates/compiler/builtins/bitcode/src/str.zig index ea57a934e1..fc20537c5d 100644 --- a/crates/compiler/builtins/bitcode/src/str.zig +++ b/crates/compiler/builtins/bitcode/src/str.zig @@ -1525,6 +1525,10 @@ pub fn countUtf8Bytes(string: RocStr) callconv(.C) usize { return string.len(); } +pub fn isEmpty(string: RocStr) callconv(.C) bool { + return string.isEmpty(); +} + pub fn getCapacity(string: RocStr) callconv(.C) usize { return string.getCapacity(); } diff --git a/crates/compiler/builtins/src/bitcode.rs b/crates/compiler/builtins/src/bitcode.rs index d96496eae9..42c4c07260 100644 --- a/crates/compiler/builtins/src/bitcode.rs +++ b/crates/compiler/builtins/src/bitcode.rs @@ -308,6 +308,7 @@ pub const STR_SPLIT: &str = "roc_builtins.str.str_split"; pub const STR_TO_SCALARS: &str = "roc_builtins.str.to_scalars"; pub const STR_COUNT_GRAPEHEME_CLUSTERS: &str = "roc_builtins.str.count_grapheme_clusters"; pub const STR_COUNT_UTF8_BYTES: &str = "roc_builtins.str.count_utf8_bytes"; +pub const STR_IS_EMPTY: &str = "roc_builtins.str.is_empty"; pub const STR_CAPACITY: &str = "roc_builtins.str.capacity"; pub const STR_STARTS_WITH: &str = "roc_builtins.str.starts_with"; pub const STR_STARTS_WITH_SCALAR: &str = "roc_builtins.str.starts_with_scalar"; diff --git a/crates/compiler/gen_dev/src/lib.rs b/crates/compiler/gen_dev/src/lib.rs index b78788269e..39acdce3b9 100644 --- a/crates/compiler/gen_dev/src/lib.rs +++ b/crates/compiler/gen_dev/src/lib.rs @@ -1120,6 +1120,10 @@ trait Backend<'a> { self.build_fn_call(sym, intrinsic.to_string(), args, arg_layouts, ret_layout) } + LowLevel::StrIsEmpty => { + let intrinsic = bitcode::STR_IS_EMPTY.to_string(); + self.build_fn_call(sym, intrinsic, args, arg_layouts, ret_layout); + } x => todo!("low level, {:?}", x), } } diff --git a/crates/compiler/test_gen/src/gen_str.rs b/crates/compiler/test_gen/src/gen_str.rs index 40cedb9136..cfb3cbd34e 100644 --- a/crates/compiler/test_gen/src/gen_str.rs +++ b/crates/compiler/test_gen/src/gen_str.rs @@ -497,23 +497,23 @@ fn str_concat_empty() { } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))] fn small_str_is_empty() { assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool); } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))] fn big_str_is_empty() { assert_evals_to!( - r#"Str.isEmpty "this is more than 15 chars long""#, + r#"Str.isEmpty "this is more than 23 chars long""#, false, bool ); } #[test] -#[cfg(any(feature = "gen-llvm"))] +#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))] fn empty_str_is_empty() { assert_evals_to!(r#"Str.isEmpty """#, true, bool); }