bugfixes from using during AOC
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 5 Dec 2020 19:17:53 +0000 (13:17 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 5 Dec 2020 19:17:53 +0000 (13:17 -0600)
core/file.onyx
core/stdio.onyx
core/string.onyx
docs/plan
onyx
src/onyxwasm.c

index a93e28ac0b0f736fcc58bbe616f49fbd9f74cc09..30e8176e17fe3d0fc8b59a6be4d314c556af5d94 100644 (file)
@@ -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;
 }
index 9f397d83def4edc7646b40c8283816a8b16d9c8a..e1b2d0b3b7e8887054b7c313e3a27b37ac7c8b7f 100644 (file)
@@ -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;
index 8fcd42c659e1e8cf7883663ef99f10b9735ef830..0014c7c1b1fa3e2999d5d25a327414944470f5d9 100644 (file)
@@ -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;
     }
 
index f4f9e532afbb7feeca506943fd41712e2a5f6172..b51d9badd6cce91698edfd98a2730ac04a8354cc 100644 (file)
--- 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 (executable)
Binary files a/onyx and b/onyx differ
index 0a4611b8b93ba1f41e9147e6d6e206615f5ec2be..5d3c809e8ac06d38c53eb2169c25a5bfa5ecbff9 100644 (file)
@@ -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) {