mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
basic working test case
This commit is contained in:
parent
8a21b42c20
commit
d6ed2147ae
4 changed files with 27 additions and 5 deletions
|
@ -5,15 +5,17 @@ const RocList = @import("list.zig").RocList;
|
||||||
const RocStr = @import("str.zig").RocStr;
|
const RocStr = @import("str.zig").RocStr;
|
||||||
|
|
||||||
pub fn NumParseResult(comptime T: type) type {
|
pub fn NumParseResult(comptime T: type) type {
|
||||||
|
// on the roc side we sort by alignment; putting the errorcode last
|
||||||
|
// always works out (no number with smaller alignment than 1)
|
||||||
return extern struct {
|
return extern struct {
|
||||||
errorcode: u8, // 0 indicates success
|
|
||||||
value: T,
|
value: T,
|
||||||
|
errorcode: u8, // 0 indicates success
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exportParseInt(comptime T: type, comptime name: []const u8) void {
|
pub fn exportParseInt(comptime T: type, comptime name: []const u8) void {
|
||||||
comptime var f = struct {
|
comptime var f = struct {
|
||||||
fn func(input: T, buf: RocStr) callconv(.C) NumParseResult(T) {
|
fn func(buf: RocStr) callconv(.C) NumParseResult(T) {
|
||||||
// a radix of 0 will make zig determine the radix from the frefix:
|
// a radix of 0 will make zig determine the radix from the frefix:
|
||||||
// * A prefix of "0b" implies radix=2,
|
// * A prefix of "0b" implies radix=2,
|
||||||
// * A prefix of "0o" implies radix=8,
|
// * A prefix of "0o" implies radix=8,
|
||||||
|
|
|
@ -1355,12 +1355,12 @@ fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
Access {
|
Access {
|
||||||
record_var,
|
record_var,
|
||||||
ext_var: var_store.fresh(),
|
ext_var: var_store.fresh(),
|
||||||
field: "errorcode".into(),
|
field: "b_errorcode".into(),
|
||||||
field_var: errorcode_var,
|
field_var: errorcode_var,
|
||||||
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
|
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(errorcode_var, int(errorcode_var, Variable::NATURAL, 0)),
|
(errorcode_var, int(errorcode_var, Variable::UNSIGNED8, 0)),
|
||||||
],
|
],
|
||||||
ret_var: bool_var,
|
ret_var: bool_var,
|
||||||
}),
|
}),
|
||||||
|
@ -1382,7 +1382,7 @@ fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
Access {
|
Access {
|
||||||
record_var,
|
record_var,
|
||||||
ext_var: var_store.fresh(),
|
ext_var: var_store.fresh(),
|
||||||
field: "value".into(),
|
field: "a_value".into(),
|
||||||
field_var: num_var,
|
field_var: num_var,
|
||||||
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
|
loc_expr: Box::new(no_region(Var(Symbol::ARG_2))),
|
||||||
},
|
},
|
||||||
|
|
|
@ -5285,6 +5285,9 @@ fn run_low_level<'a, 'ctx, 'env>(
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let string =
|
||||||
|
complex_bitcast(env.builder, string, env.str_list_c_abi().into(), "to_utf8");
|
||||||
|
|
||||||
call_bitcode_fn(env, &[string], intrinsic)
|
call_bitcode_fn(env, &[string], intrinsic)
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
|
@ -1297,3 +1297,20 @@ fn str_trim_right_small_to_small_shared() {
|
||||||
(RocStr, RocStr)
|
(RocStr, RocStr)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(feature = "gen-llvm"))]
|
||||||
|
fn str_to_num() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
when Str.toNum "1" is
|
||||||
|
Ok n -> n
|
||||||
|
Err _ -> 0
|
||||||
|
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
1,
|
||||||
|
i64
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue