stack pointers and separate stack allocation in the linear memory for each
of the threads.
- [ ] Array literals
+ [X] Array literals
[ ] transmute
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
}
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 {
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);