Merge pull request #3365 from rtfeldman/to-scalars

Add Str.toScalars builtin
This commit is contained in:
Folkert de Vries 2022-07-02 23:04:28 +02:00 committed by GitHub
commit 75b4b3a206
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 460 additions and 20 deletions

View file

@ -73,6 +73,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
BOOL_NOT => bool_not,
STR_CONCAT => str_concat,
STR_JOIN_WITH => str_join_with,
STR_TO_SCALARS => str_to_scalars,
STR_SPLIT => str_split,
STR_IS_EMPTY => str_is_empty,
STR_STARTS_WITH => str_starts_with,
@ -1672,6 +1673,26 @@ fn str_concat(symbol: Symbol, var_store: &mut VarStore) -> Def {
)
}
/// Str.toScalars : Str -> List U32
fn str_to_scalars(symbol: Symbol, var_store: &mut VarStore) -> Def {
let str_var = var_store.fresh();
let list_u32_var = var_store.fresh();
let body = RunLowLevel {
op: LowLevel::StrToScalars,
args: vec![(str_var, Var(Symbol::ARG_1))],
ret_var: list_u32_var,
};
defn(
symbol,
vec![(str_var, Symbol::ARG_1)],
var_store,
body,
list_u32_var,
)
}
/// Str.joinWith : List Str, Str -> Str
fn str_join_with(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_str_var = var_store.fresh();