std: fix parse_u64 implementation and add test
also codegen implement comparision with pure errors
This commit is contained in:
parent
1d92700d08
commit
207862647c
@ -1269,6 +1269,9 @@ static LLVMValueRef gen_cmp_expr(CodeGen *g, AstNode *node) {
|
|||||||
} else {
|
} else {
|
||||||
zig_unreachable();
|
zig_unreachable();
|
||||||
}
|
}
|
||||||
|
} else if (op1_type->id == TypeTableEntryIdPureError) {
|
||||||
|
LLVMIntPredicate pred = cmp_op_to_int_predicate(node->data.bin_op_expr.bin_op, false);
|
||||||
|
return LLVMBuildICmp(g->builder, pred, val1, val2, "");
|
||||||
} else {
|
} else {
|
||||||
zig_unreachable();
|
zig_unreachable();
|
||||||
}
|
}
|
||||||
|
11
std/std.zig
11
std/std.zig
@ -158,7 +158,7 @@ pub fn parse_u64(buf: []u8, radix: u8) -> %u64 {
|
|||||||
for (buf) |c| {
|
for (buf) |c| {
|
||||||
const digit = char_to_digit(c);
|
const digit = char_to_digit(c);
|
||||||
|
|
||||||
if (digit > radix) {
|
if (digit >= radix) {
|
||||||
return error.InvalidChar;
|
return error.InvalidChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,3 +342,12 @@ pub fn buf_print_f64(out_buf: []u8, x: f64, decimals: isize) -> isize {
|
|||||||
|
|
||||||
len
|
len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#attribute("test")
|
||||||
|
fn parse_u64_digit_too_big() {
|
||||||
|
parse_u64("123a", 10) %% |err| {
|
||||||
|
if (err == error.InvalidChar) return;
|
||||||
|
unreachable{};
|
||||||
|
};
|
||||||
|
unreachable{};
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import "test_std.zig";
|
||||||
|
|
||||||
#attribute("test")
|
#attribute("test")
|
||||||
fn empty_function() {}
|
fn empty_function() {}
|
||||||
|
|
||||||
|
1
test/test_std.zig
Normal file
1
test/test_std.zig
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "std.zig";
|
Loading…
x
Reference in New Issue
Block a user