From: Brendan Hansen Date: Wed, 23 Sep 2020 18:33:30 +0000 (-0500) Subject: added %f to bh_printf and fixed bug X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=556cbe44a2e090fbb5d9a37a57d6e7f44d39ba0b;p=onyx.git added %f to bh_printf and fixed bug --- diff --git a/include/bh.h b/include/bh.h index 9878f698..ffb5379f 100644 --- a/include/bh.h +++ b/include/bh.h @@ -1618,6 +1618,23 @@ isize bh__printi64(char* str, isize n, bh__print_format format, i64 value) { return bh__print_string(str, n, walker); } +isize bh__printf64(char* str, isize n, f64 value) { + fori (i, 0, 6) value *= 10.0; + i64 v = (i64) value; + + isize l1 = bh__printi64(str, n, ((bh__print_format) { .base = 10 }), v / 1000000); + str += l1; + n -= l1; + + *str = '.'; + str += 1; + n -= 1; + + isize l2 = bh__printi64(str, n, ((bh__print_format) { .base = 10 }), bh_abs(v) % 1000000); + + return l1 + l2 + 1; +} + // TODO: This is very hacked together but for now it will work. isize bh_snprintf_va(char *str, isize n, char const *fmt, va_list va) { char const *text_start = str; @@ -1674,6 +1691,11 @@ isize bh_snprintf_va(char *str, isize n, char const *fmt, va_list va) { len = bh__print_string(str, bh_min(l, n), s); } break; + case 'f': { + f64 f = va_arg(va, f64); + len = bh__printf64(str, n, f); + } break; + default: fmt--; } diff --git a/onyx b/onyx index cf023545..6ec963ca 100755 Binary files a/onyx and b/onyx differ diff --git a/src/onyxparser.c b/src/onyxparser.c index be50983d..82e75940 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -780,9 +780,9 @@ expression_done: // 'if' ('elseif' )* ('else' )? static AstIfWhile* parse_if_stmt(OnyxParser* parser) { - expect_token(parser, Token_Type_Keyword_If); - AstIfWhile* if_node = make_node(AstIfWhile, Ast_Kind_If); + if_node->token = expect_token(parser, Token_Type_Keyword_If); + AstIfWhile* root_if = if_node; if ((parser->curr + 1)->type == ':') {