updating documentation
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 17 Dec 2020 16:46:59 +0000 (10:46 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 17 Dec 2020 16:46:59 +0000 (10:46 -0600)
docs/plan
docs/todo
progs/odin_example.onyx
src/onyxwasm.c

index fb823d7ca47b894ea01b5544299ad51aba740090..9988ef7a040cfceb4eaa80f57cf52cebad6e8fd5 100644 (file)
--- a/docs/plan
+++ b/docs/plan
@@ -53,7 +53,7 @@ HOW:
                 stack pointers and separate stack allocation in the linear memory for each
                 of the threads.
 
-        [ ] Array literals
+        [X] Array literals
 
         [ ] transmute
 
index d642885b9be435ef7c588e9601c106c2e30200ae..310ccc5375e8990853edbe2ef8bc0c49218d329e 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -50,6 +50,10 @@ Language Cohesion:
         constant data (such as MD5 hash vectors) would be useful.
 
         Array literals work only for static constant data outside of procedures.
+        Array literals also now work in expressions.
+        I changed the semantics of assignment for array types. Instead of just
+        copying the pointer to the array, ALL elements of the source array are
+        copied into the destination array.
 
     [X] Struct literals can only have 1 level of package before the struct
         name. This is because packages were not able to be nested, so having
index 3f89c1c61b9cffd124c9d9226dde17e949fd8f49..f13b3e9af854f30f936c7932bc71855f720d7502 100644 (file)
@@ -57,15 +57,16 @@ make_bar :: proc () -> Bar {
 }
 
 f :: proc () -> [5] [2] u32 #export "IAMTHEFUNCTION" {
-    mem := cast(^u32) calloc(sizeof [5] [2] u32);
-    for i: 0 .. 10 do mem[i] = 1234 + i;
-    return ~~mem;
+    // This method of returning an array will leak memory, since this is never freed.
+    // mem := cast(^u32) calloc(sizeof [5] [2] u32);
+    // for i: 0 .. 10 do mem[i] = 1234 + i;
+    // return ~~mem;
 
 
     // This is safe ONLY when the value is used without calling another function.
-    // mem : [5] u32;
-    // for ^m: mem do *m = 4567;
-    // return mem;
+    mem : [5] [2] u32;
+    for ^m2: mem do for ^m: *m2 do *m = 4567;
+    return mem;
 }
 
 compress :: proc (arr: [5] $T, f : proc (T, T) -> T) -> T {
index 676926c0695b2fde939af952c5eb2a15fc0eda15..935281912ff258e005f75bd4a89bbb650e13da4a 100644 (file)
@@ -514,6 +514,10 @@ EMIT_FUNC(assignment, AstBinaryOp* assign) {
         emit_expression(mod, &code, assign->right);
         WIL(WI_LOCAL_SET, rptr_local);
 
+        // NOTE: Currently, we inline the copying of the array; But if the array has
+        // many elements, this could result in a LOT of instructions. Maybe for lengths
+        // greater than like 16 we output a loop that copies them?
+        //                                               - brendanfh 2020/12/16
         fori (i, 0, elem_count) {
             if (!type_is_structlike(rtype))
                 WIL(WI_LOCAL_GET, lptr_local);