mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Enable some more gen_wasm string builtins
This commit is contained in:
parent
9b2f01042e
commit
be55582290
2 changed files with 318 additions and 179 deletions
|
@ -28,11 +28,32 @@ pub fn decode_low_level<'a>(
|
||||||
|
|
||||||
match lowlevel {
|
match lowlevel {
|
||||||
StrConcat => return BuiltinCall(bitcode::STR_CONCAT),
|
StrConcat => return BuiltinCall(bitcode::STR_CONCAT),
|
||||||
|
StrJoinWith => return NotImplemented, // needs Array
|
||||||
|
StrIsEmpty => {
|
||||||
|
code_builder.i64_const(i64::MIN);
|
||||||
|
code_builder.i64_eq();
|
||||||
|
}
|
||||||
|
StrStartsWith => return BuiltinCall(bitcode::STR_STARTS_WITH),
|
||||||
|
StrStartsWithCodePt => return BuiltinCall(bitcode::STR_STARTS_WITH_CODE_PT),
|
||||||
|
StrEndsWith => return BuiltinCall(bitcode::STR_ENDS_WITH),
|
||||||
|
StrSplit => return NotImplemented, // needs Array
|
||||||
|
StrCountGraphemes => return NotImplemented, // test needs Array
|
||||||
|
StrFromInt => return NotImplemented, // choose builtin based on storage size
|
||||||
|
StrFromUtf8 => return NotImplemented, // needs Array
|
||||||
|
StrTrimLeft => return BuiltinCall(bitcode::STR_TRIM_LEFT),
|
||||||
|
StrTrimRight => return BuiltinCall(bitcode::STR_TRIM_RIGHT),
|
||||||
|
StrFromUtf8Range => return NotImplemented, // needs Array
|
||||||
|
StrToUtf8 => return NotImplemented, // needs Array
|
||||||
|
StrRepeat => return BuiltinCall(bitcode::STR_REPEAT),
|
||||||
|
StrFromFloat => {
|
||||||
|
// linker errors for __ashlti3, __fixunsdfti, __multi3, __udivti3, __umodti3
|
||||||
|
// https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html
|
||||||
|
// https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html
|
||||||
|
return NotImplemented;
|
||||||
|
}
|
||||||
|
StrTrim => return BuiltinCall(bitcode::STR_TRIM),
|
||||||
|
|
||||||
StrJoinWith | StrIsEmpty | StrStartsWith | StrStartsWithCodePt | StrEndsWith | StrSplit
|
ListLen | ListGetUnsafe | ListSet | ListSingle | ListRepeat | ListReverse | ListConcat
|
||||||
| StrCountGraphemes | StrFromInt | StrFromUtf8 | StrTrimLeft | StrTrimRight
|
|
||||||
| StrFromUtf8Range | StrToUtf8 | StrRepeat | StrFromFloat | StrTrim | ListLen
|
|
||||||
| ListGetUnsafe | ListSet | ListSingle | ListRepeat | ListReverse | ListConcat
|
|
||||||
| ListContains | ListAppend | ListPrepend | ListJoin | ListRange | ListMap | ListMap2
|
| ListContains | ListAppend | ListPrepend | ListJoin | ListRange | ListMap | ListMap2
|
||||||
| ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf | ListWalk | ListWalkUntil
|
| ListMap3 | ListMap4 | ListMapWithIndex | ListKeepIf | ListWalk | ListWalkUntil
|
||||||
| ListWalkBackwards | ListKeepOks | ListKeepErrs | ListSortWith | ListSublist
|
| ListWalkBackwards | ListKeepOks | ListKeepErrs | ListSortWith | ListSublist
|
||||||
|
|
|
@ -346,54 +346,54 @@ fn str_concat_empty() {
|
||||||
assert_evals_to!(r#"Str.concat "" """#, RocStr::default(), RocStr);
|
assert_evals_to!(r#"Str.concat "" """#, RocStr::default(), RocStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn small_str_is_empty() {
|
fn small_str_is_empty() {
|
||||||
// assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool);
|
assert_evals_to!(r#"Str.isEmpty "abc""#, false, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn big_str_is_empty() {
|
fn big_str_is_empty() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// r#"Str.isEmpty "this is more than 15 chars long""#,
|
r#"Str.isEmpty "this is more than 15 chars long""#,
|
||||||
// false,
|
false,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn empty_str_is_empty() {
|
fn empty_str_is_empty() {
|
||||||
// assert_evals_to!(r#"Str.isEmpty """#, true, bool);
|
assert_evals_to!(r#"Str.isEmpty """#, true, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with() {
|
fn str_starts_with() {
|
||||||
// assert_evals_to!(r#"Str.startsWith "hello world" "hell""#, true, bool);
|
assert_evals_to!(r#"Str.startsWith "hello world" "hell""#, true, bool);
|
||||||
// assert_evals_to!(r#"Str.startsWith "hello world" """#, true, bool);
|
assert_evals_to!(r#"Str.startsWith "hello world" """#, true, bool);
|
||||||
// assert_evals_to!(r#"Str.startsWith "nope" "hello world""#, false, bool);
|
assert_evals_to!(r#"Str.startsWith "nope" "hello world""#, false, bool);
|
||||||
// assert_evals_to!(r#"Str.startsWith "hell" "hello world""#, false, bool);
|
assert_evals_to!(r#"Str.startsWith "hell" "hello world""#, false, bool);
|
||||||
// assert_evals_to!(r#"Str.startsWith "" "hello world""#, false, bool);
|
assert_evals_to!(r#"Str.startsWith "" "hello world""#, false, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_code_point() {
|
fn str_starts_with_code_point() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// &format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32),
|
&format!(r#"Str.startsWithCodePt "foobar" {}"#, 'f' as u32),
|
||||||
// true,
|
true,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// &format!(r#"Str.startsWithCodePt "zoobar" {}"#, 'f' as u32),
|
&format!(r#"Str.startsWithCodePt "zoobar" {}"#, 'f' as u32),
|
||||||
// false,
|
false,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_ends_with() {
|
fn str_ends_with() {
|
||||||
// assert_evals_to!(r#"Str.endsWith "hello world" "world""#, true, bool);
|
assert_evals_to!(r#"Str.endsWith "hello world" "world""#, true, bool);
|
||||||
// assert_evals_to!(r#"Str.endsWith "nope" "hello world""#, false, bool);
|
assert_evals_to!(r#"Str.endsWith "nope" "hello world""#, false, bool);
|
||||||
// assert_evals_to!(r#"Str.endsWith "" "hello world""#, false, bool);
|
assert_evals_to!(r#"Str.endsWith "" "hello world""#, false, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn str_count_graphemes_small_str() {
|
// fn str_count_graphemes_small_str() {
|
||||||
|
@ -414,37 +414,37 @@ fn str_concat_empty() {
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_same_big_str() {
|
fn str_starts_with_same_big_str() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// r#"Str.startsWith "123456789123456789" "123456789123456789""#,
|
r#"Str.startsWith "123456789123456789" "123456789123456789""#,
|
||||||
// true,
|
true,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_different_big_str() {
|
fn str_starts_with_different_big_str() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// r#"Str.startsWith "12345678912345678910" "123456789123456789""#,
|
r#"Str.startsWith "12345678912345678910" "123456789123456789""#,
|
||||||
// true,
|
true,
|
||||||
// bool
|
bool
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_same_small_str() {
|
fn str_starts_with_same_small_str() {
|
||||||
// assert_evals_to!(r#"Str.startsWith "1234" "1234""#, true, bool);
|
assert_evals_to!(r#"Str.startsWith "1234" "1234""#, true, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_different_small_str() {
|
fn str_starts_with_different_small_str() {
|
||||||
// assert_evals_to!(r#"Str.startsWith "1234" "12""#, true, bool);
|
assert_evals_to!(r#"Str.startsWith "1234" "12""#, true, bool);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_starts_with_false_small_str() {
|
fn str_starts_with_false_small_str() {
|
||||||
// assert_evals_to!(r#"Str.startsWith "1234" "23""#, false, bool);
|
assert_evals_to!(r#"Str.startsWith "1234" "23""#, false, bool);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
// fn str_from_int() {
|
// fn str_from_int() {
|
||||||
|
@ -900,121 +900,239 @@ fn str_concat_empty() {
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_repeat_small() {
|
fn str_repeat_small() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(r#"Str.repeat "Roc" 3"#),
|
indoc!(r#"Str.repeat "Roc" 3"#),
|
||||||
// RocStr::from("RocRocRoc"),
|
RocStr::from("RocRocRoc"),
|
||||||
// RocStr
|
RocStr
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_repeat_big() {
|
fn str_repeat_big() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(r#"Str.repeat "more than 16 characters" 2"#),
|
indoc!(r#"Str.repeat "more than 16 characters" 2"#),
|
||||||
// RocStr::from("more than 16 charactersmore than 16 characters"),
|
RocStr::from("more than 16 charactersmore than 16 characters"),
|
||||||
// RocStr
|
RocStr
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_repeat_empty_string() {
|
fn str_repeat_empty_string() {
|
||||||
// assert_evals_to!(indoc!(r#"Str.repeat "" 3"#), RocStr::from(""), RocStr);
|
assert_evals_to!(indoc!(r#"Str.repeat "" 3"#), RocStr::from(""), RocStr);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_repeat_zero_times() {
|
fn str_repeat_zero_times() {
|
||||||
// assert_evals_to!(indoc!(r#"Str.repeat "Roc" 0"#), RocStr::from(""), RocStr);
|
assert_evals_to!(indoc!(r#"Str.repeat "Roc" 0"#), RocStr::from(""), RocStr);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_empty_string() {
|
fn str_trim_empty_string() {
|
||||||
// assert_evals_to!(indoc!(r#"Str.trim """#), RocStr::from(""), RocStr);
|
assert_evals_to!(indoc!(r#"Str.trim """#), RocStr::from(""), RocStr);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_small_blank_string() {
|
fn str_trim_small_blank_string() {
|
||||||
// assert_evals_to!(indoc!(r#"Str.trim " ""#), RocStr::from(""), RocStr);
|
assert_evals_to!(indoc!(r#"Str.trim " ""#), RocStr::from(""), RocStr);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_small_to_small() {
|
fn str_trim_small_to_small() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(r#"Str.trim " hello world ""#),
|
indoc!(r#"Str.trim " hello world ""#),
|
||||||
// RocStr::from("hello world"),
|
RocStr::from("hello world"),
|
||||||
// RocStr
|
RocStr
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_large_to_large_unique() {
|
fn str_trim_large_to_large_unique() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(r#"Str.trim (Str.concat " " "hello world from a large string ")"#),
|
indoc!(r#"Str.trim (Str.concat " " "hello world from a large string ")"#),
|
||||||
// RocStr::from("hello world from a large string"),
|
RocStr::from("hello world from a large string"),
|
||||||
// RocStr
|
RocStr
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_large_to_small_unique() {
|
fn str_trim_large_to_small_unique() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(r#"Str.trim (Str.concat " " "hello world ")"#),
|
indoc!(r#"Str.trim (Str.concat " " "hello world ")"#),
|
||||||
// RocStr::from("hello world"),
|
RocStr::from("hello world"),
|
||||||
// RocStr
|
RocStr
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_large_to_large_shared() {
|
fn str_trim_large_to_large_shared() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// original : Str
|
original : Str
|
||||||
// original = " hello world world "
|
original = " hello world world "
|
||||||
|
|
||||||
// { trimmed: Str.trim original, original: original }
|
{ trimmed: Str.trim original, original: original }
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// (
|
(
|
||||||
// RocStr::from(" hello world world "),
|
RocStr::from(" hello world world "),
|
||||||
// RocStr::from("hello world world"),
|
RocStr::from("hello world world"),
|
||||||
// ),
|
),
|
||||||
// (RocStr, RocStr)
|
(RocStr, RocStr)
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_large_to_small_shared() {
|
fn str_trim_large_to_small_shared() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// original : Str
|
original : Str
|
||||||
// original = " hello world "
|
original = " hello world "
|
||||||
|
|
||||||
// { trimmed: Str.trim original, original: original }
|
{ trimmed: Str.trim original, original: original }
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// (
|
(
|
||||||
// RocStr::from(" hello world "),
|
RocStr::from(" hello world "),
|
||||||
// RocStr::from("hello world"),
|
RocStr::from("hello world"),
|
||||||
// ),
|
),
|
||||||
// (RocStr, RocStr)
|
(RocStr, RocStr)
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn str_trim_small_to_small_shared() {
|
fn str_trim_small_to_small_shared() {
|
||||||
// assert_evals_to!(
|
assert_evals_to!(
|
||||||
// indoc!(
|
indoc!(
|
||||||
// r#"
|
r#"
|
||||||
// original : Str
|
original : Str
|
||||||
// original = " hello world "
|
original = " hello world "
|
||||||
|
|
||||||
// { trimmed: Str.trim original, original: original }
|
{ trimmed: Str.trim original, original: original }
|
||||||
// "#
|
"#
|
||||||
// ),
|
),
|
||||||
// (RocStr::from(" hello world "), RocStr::from("hello world"),),
|
(RocStr::from(" hello world "), RocStr::from("hello world"),),
|
||||||
// (RocStr, RocStr)
|
(RocStr, RocStr)
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_left_small_blank_string() {
|
||||||
|
assert_evals_to!(indoc!(r#"Str.trimLeft " ""#), RocStr::from(""), RocStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_left_small_to_small() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimLeft " hello world ""#),
|
||||||
|
RocStr::from("hello world "),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_left_large_to_large_unique() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimLeft (Str.concat " " "hello world from a large string ")"#),
|
||||||
|
RocStr::from("hello world from a large string "),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_left_large_to_small_unique() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimLeft (Str.concat " " "hello world ")"#),
|
||||||
|
RocStr::from("hello world "),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_small_blank_string() {
|
||||||
|
assert_evals_to!(indoc!(r#"Str.trimRight " ""#), RocStr::from(""), RocStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_small_to_small() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimRight " hello world ""#),
|
||||||
|
RocStr::from(" hello world"),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_large_to_large_unique() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimRight (Str.concat " hello world from a large string" " ")"#),
|
||||||
|
RocStr::from(" hello world from a large string"),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_large_to_small_unique() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(r#"Str.trimRight (Str.concat " hello world" " ")"#),
|
||||||
|
RocStr::from(" hello world"),
|
||||||
|
RocStr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_large_to_large_shared() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
original : Str
|
||||||
|
original = " hello world world "
|
||||||
|
|
||||||
|
{ trimmed: Str.trimRight original, original: original }
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
(
|
||||||
|
RocStr::from(" hello world world "),
|
||||||
|
RocStr::from(" hello world world"),
|
||||||
|
),
|
||||||
|
(RocStr, RocStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_large_to_small_shared() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
original : Str
|
||||||
|
original = " hello world "
|
||||||
|
|
||||||
|
{ trimmed: Str.trimRight original, original: original }
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
(
|
||||||
|
RocStr::from(" hello world "),
|
||||||
|
RocStr::from(" hello world"),
|
||||||
|
),
|
||||||
|
(RocStr, RocStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn str_trim_right_small_to_small_shared() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
original : Str
|
||||||
|
original = " hello world "
|
||||||
|
|
||||||
|
{ trimmed: Str.trimRight original, original: original }
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
(RocStr::from(" hello world "), RocStr::from(" hello world"),),
|
||||||
|
(RocStr, RocStr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue