sketch of StrToNum

This commit is contained in:
Folkert 2021-12-01 15:33:16 +01:00
parent d37ddeb162
commit 69fc1ad7e7
7 changed files with 60 additions and 0 deletions

View file

@ -5268,6 +5268,23 @@ fn run_low_level<'a, 'ctx, 'env>(
str_ends_with(env, scope, args[0], args[1])
}
StrToNum => {
debug_assert_eq!(args.len(), 1);
let (string, _string_layout) = load_symbol_and_layout(scope, &args[0]);
// match on the return layout to figure out which zig builtin we need
let intrinsic = match layout {
Layout::Builtin(Builtin::Int(int_width)) => &bitcode::STR_TO_INT[*int_width],
Layout::Builtin(Builtin::Float(float_width)) => {
&bitcode::STR_TO_FLOAT[*float_width]
}
Layout::Builtin(Builtin::Decimal) => bitcode::STR_TO_DECIMAL,
_ => unreachable!(),
};
call_bitcode_fn(env, &[string], intrinsic)
}
StrFromInt => {
// Str.fromInt : Int -> Str
debug_assert_eq!(args.len(), 1);