mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
feat: match on a Union Layout and use index access to get the num layout
This commit is contained in:
parent
ba9d01773b
commit
0d74daf7d9
1 changed files with 14 additions and 10 deletions
|
@ -5274,17 +5274,21 @@ fn run_low_level<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
let (string, _string_layout) = load_symbol_and_layout(scope, &args[0]);
|
let (string, _string_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||||
|
|
||||||
|
if let Layout::Union(UnionLayout::NonRecursive(union_layout)) = layout {
|
||||||
// match on the return layout to figure out which zig builtin we need
|
// match on the return layout to figure out which zig builtin we need
|
||||||
let intrinsic = match layout {
|
let intrinsic = match union_layout[1][0] {
|
||||||
Layout::Builtin(Builtin::Int(int_width)) => &bitcode::STR_TO_INT[*int_width],
|
Layout::Builtin(Builtin::Int(int_width)) => &bitcode::STR_TO_INT[int_width],
|
||||||
Layout::Builtin(Builtin::Float(float_width)) => {
|
Layout::Builtin(Builtin::Float(float_width)) => {
|
||||||
&bitcode::STR_TO_FLOAT[*float_width]
|
&bitcode::STR_TO_FLOAT[float_width]
|
||||||
}
|
}
|
||||||
Layout::Builtin(Builtin::Decimal) => bitcode::STR_TO_DECIMAL,
|
Layout::Builtin(Builtin::Decimal) => bitcode::STR_TO_DECIMAL,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
call_bitcode_fn(env, &[string], intrinsic)
|
call_bitcode_fn(env, &[string], intrinsic)
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StrFromInt => {
|
StrFromInt => {
|
||||||
// Str.fromInt : Int -> Str
|
// Str.fromInt : Int -> Str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue