From: Brendan Hansen Date: Thu, 17 Dec 2020 16:46:59 +0000 (-0600) Subject: updating documentation X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=529ffa2c221e7676095986458f51c61d2213007a;p=onyx.git updating documentation --- diff --git a/docs/plan b/docs/plan index fb823d7c..9988ef7a 100644 --- 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 diff --git a/docs/todo b/docs/todo index d642885b..310ccc53 100644 --- 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 diff --git a/progs/odin_example.onyx b/progs/odin_example.onyx index 3f89c1c6..f13b3e9a 100644 --- a/progs/odin_example.onyx +++ b/progs/odin_example.onyx @@ -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 { diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 676926c0..93528191 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -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);