bugfix with assigning to struct parameters
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 21 Feb 2021 22:37:13 +0000 (16:37 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 21 Feb 2021 22:37:13 +0000 (16:37 -0600)
bin/onyx
core/conv.onyx
core/string.onyx
src/onyxwasm.c

index 5e1cdfbdabef1ba7329d30c99de57b87c8a7a6f5..59479302495ca59672677e3844d068955436e761 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index a389df6aa27a7679f9071e65e9124cabaf09c7ae..6bfab2afa101803080d75871c555d458de35983f 100644 (file)
@@ -1,5 +1,28 @@
 package core.conv
 
+str_to_i64 :: (s: str) -> i64 {
+    use package core
+
+    value: i64 = 0;
+    mul := 1;
+
+    if s[0] == #char "-" {
+        mul = -1;
+        s = string.advance(s, 1);
+    }
+
+    for c: s do switch c {
+        case #char "0" .. #char "9" {
+            value *= 10;
+            value += ~~(c - #char "0");
+        }
+
+        case #default do break break;
+    }
+
+    return value * ~~mul;
+}
+
 i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0) -> str {
     is_neg := false;
     if n < 0 && base == 10 {
index d8976b83a8bbc515924f789d19354f9c143682a8..ab8949d59f74945a6f82e8df7da69c54e7e0210d 100644 (file)
@@ -1,5 +1,7 @@
 package core.string
 
+use package core
+
 make :: (s: cstr) -> str {
     len := length(s);
 
@@ -143,6 +145,26 @@ strip_trailing_whitespace :: (s: ^str) {
     }
 }
 
+advance :: proc {
+    // Inplace version
+    (s: ^str, chars := 1) {
+        chars = math.min(chars, s.count);
+
+        s.data += chars;
+        s.count -= chars;
+    },
+
+    // Out of place version
+    (s: str, chars := 1) -> str {
+        chars = math.min(chars, s.count);
+        out := s;
+
+        out.data += chars;
+        out.count -= chars;
+
+        return out;
+    }
+}
 
 read_u32 :: (s: ^str, out: ^u32) {
     n := 0;
index a9742e80f4a66d6756e57b785207d1570cea62b9..7b533f837ee2a8d62a9dcb34418a2697e5ea9a38 100644 (file)
@@ -402,7 +402,14 @@ EMIT_FUNC(assignment, AstBinaryOp* assign) {
             emit_expression(mod, &code, assign->right);
 
             u64 localidx = bh_imap_get(&mod->local_map, (u64) lval);
-            WIL(WI_LOCAL_SET, localidx);
+
+            if (lval->kind == Ast_Kind_Param && type_is_structlike_strict(lval->type)) {
+                u32 mem_count = type_structlike_mem_count(lval->type);
+                fori (i, 0, mem_count) WIL(WI_LOCAL_SET, localidx + i);
+
+            } else {
+                WIL(WI_LOCAL_SET, localidx);
+            }
 
             *pcode = code;
             return;