From 8ad4e5601cf06f44b2104a3209d6e3fa0288740d Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 5 Dec 2020 13:17:53 -0600 Subject: [PATCH] bugfixes from using during AOC --- core/file.onyx | 11 ++--------- core/stdio.onyx | 13 +++++++++++++ core/string.onyx | 9 +++++++-- docs/plan | 3 +++ onyx | Bin 495988 -> 495988 bytes src/onyxwasm.c | 4 ++-- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/core/file.onyx b/core/file.onyx index a93e28ac..30e8176e 100644 --- a/core/file.onyx +++ b/core/file.onyx @@ -74,16 +74,9 @@ file_close :: proc (file: File) -> bool { return true; } -file_get_size :: proc (file: File) -> i64 { - //size: i64 = 0l; - //prev: i64; - - //if fd_seek(file.fd, 0l, Whence.Cur, ^prev) != Errno.Success do return -1l; - //if fd_seek(file.fd, 0l, Whence.End, ^size) != Errno.Success do return -1l; - //if fd_seek(file.fd, prev, Whence.Set, ^prev) != Errno.Success do return -1l; - +file_get_size :: proc (file: File) -> u64 { fs: FileStat; - if fd_filestat_get(file.fd, ^fs) != Errno.Success do return -1l; + if fd_filestat_get(file.fd, ^fs) != Errno.Success do return 0l; return fs.size; } diff --git a/core/stdio.onyx b/core/stdio.onyx index 9f397d83..e1b2d0b3 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -123,6 +123,19 @@ printf :: proc (format: string, va: ...) { len += 1; } } + + case #char "p" { + n : rawptr; + if !vararg_get(va, ^n) do return; + + ibuf : [128] u8; + istr := i64_to_string(~~n, 16l, Buffer.{ ~~ibuf, 128 }); + + for a: istr { + buffer[len] = a; + len += 1; + } + } } state = 0; diff --git a/core/string.onyx b/core/string.onyx index 8fcd42c6..0014c7c1 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -312,13 +312,18 @@ string_read_char :: proc (str: ^string, out: ^u8) { str.count -= 1; } +string_discard_chars :: proc (str: ^string, char_count := 1) { + str.data += char_count; + str.count -= char_count; +} + // Goes up to but not including the closest newline or EOF string_read_line :: proc (str: ^string, out: ^string) { out.data = str.data; out.count = 0; - for i: 0 .. str.count { - if str.data[i] == #char "\n" do break; + for ch: *str { + if ch == #char "\n" do break; out.count += 1; } diff --git a/docs/plan b/docs/plan index f4f9e532..b51d9bad 100644 --- a/docs/plan +++ b/docs/plan @@ -265,6 +265,9 @@ HOW: [ ] Add threading intrinsics - This will actually be fairly easy since I think all that is needed is to implement the intrinsics. + - ^^^ This is a false statement. I also need to have 'thread local variables' for + stack pointers and separate stack allocation in the linear memory for each + of the threads. [X] Type parameterized structs diff --git a/onyx b/onyx index 8ba60afead625fdeda138ee71b390718422c18bc..373a69b7f7b02d0816f3636b51c406b66a5c52e1 100755 GIT binary patch delta 47 ycmeyeNbbubxrP?T7N#xC@}7+T+Z8;SUu!b@xAPP;12GE_vjQ>OcAjGP3^@Ri>JHZc delta 50 zcmeyeNbbubxrP?T7N#xC@}7)-+Z8;SUu#acQf9VncPVBDViq7~1!A`CF2(EyasbfK B5S9P{ diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 0a4611b8..5d3c809e 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -893,7 +893,7 @@ EMIT_FUNC(for_array, AstFor* for_node, u64 iter_local) { WIL(WI_LOCAL_GET, ptr_local); WIL(WI_LOCAL_GET, end_ptr_local); - WI(WI_I32_GE_S); + WI(WI_I32_GE_U); WID(WI_COND_JUMP, 0x02); if (!for_node->by_pointer) { @@ -991,7 +991,7 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { WIL(WI_LOCAL_GET, ptr_local); WIL(WI_LOCAL_GET, end_ptr_local); - WI(WI_I32_GE_S); + WI(WI_I32_GE_U); WID(WI_COND_JUMP, 0x02); if (!for_node->by_pointer) { -- 2.25.1