From: Brendan Hansen Date: Mon, 28 Sep 2020 02:22:16 +0000 (-0500) Subject: testing with varargs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0277da3d54851b538b4afde86dbb914bfd4e2ace;p=onyx.git testing with varargs --- diff --git a/core/stdio.onyx b/core/stdio.onyx index f37512fd..9f397d83 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -49,7 +49,6 @@ printf :: proc (format: string, va: ...) { len := 0; state := 0; - for ch: format do switch (state) { case 0 { if ch == #char "%" do state = 1; @@ -59,7 +58,7 @@ printf :: proc (format: string, va: ...) { } } - case 1 { + case #default { switch (ch) { case #char "%" { buffer[len] = ch; len += 1; } diff --git a/docs/plan b/docs/plan index bbf3a28d..f4f9e532 100644 --- a/docs/plan +++ b/docs/plan @@ -274,7 +274,7 @@ HOW: [ ] explicit memory controls at top level - [ ] 'use' enums and packages at an arbitrary scope + [X] 'use' enums and packages at an arbitrary scope [ ] look into creating a source map - first-look looks really gross @@ -295,7 +295,7 @@ HOW: - Compile time conditions - Only evalutate code blocks that evaluate to be true - [ ] Top level variable initialization + [X] Top level variable initialization - Works for numeric literals [ ] multiple lvals and compound assignment diff --git a/onyx b/onyx index d18afafd..7d901db8 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/vararg_test.onyx b/progs/vararg_test.onyx index eddefa22..eeb515e9 100644 --- a/progs/vararg_test.onyx +++ b/progs/vararg_test.onyx @@ -4,24 +4,29 @@ package main use package core; -old_va_test :: proc (prefix: string, va: ..i32) { - println(prefix); +old_va_test :: proc (fix: Fixes, va: ..i32) { + println(fix.prefix); for v: va do println(v); + println(fix.suffix); } -new_va_test :: proc (prefix: string, va: ...) { - println(prefix); +Fixes :: struct { prefix: string; suffix: string; } + +new_va_test :: proc (fix: Fixes, va: ...) { + println(fix.prefix); for i: 0 .. va.count { x : i32; vararg_get(va, ^x); println(x); } + + println(fix.suffix); } main :: proc (args: [] cstring) { - new_va_test("foo", 1, 2, 3.0f, 5.0f); - old_va_test("bar", 1); + new_va_test(Fixes.{ "foo", "foozle" }, 1, 2, 3.0f, 5.0f); + old_va_test(Fixes.{ "bar", "barzle" }, 1); - printf("Hello, %i, %s!\n", 1234, "World"); + printf("Hello, %%%i, %s!\n", 1234, "World"); } diff --git a/src/onyxchecker.c b/src/onyxchecker.c index ebe8cadd..4b1a3261 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1237,12 +1237,12 @@ b32 check_block(AstBlock* block) { bh_table_each_start(AstTyped *, block->scope->symbols); fill_in_type(value); - if (value->type == NULL) { - onyx_report_error(value->token->pos, - "Unable to resolve type for local '%b'.", - value->token->text, value->token->length); - return 1; - } + // if (value->type == NULL) { + // onyx_report_error(value->token->pos, + // "Unable to resolve type for local '%b'.", + // value->token->text, value->token->length); + // return 1; + // } bh_table_each_end; return 0;