// 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))
+ if (!type_is_structlike(elem_type))
WIL(WI_LOCAL_GET, lptr_local);
if (bh_arr_last(code).type == WI_LOCAL_SET && bh_arr_last(code).data.l == rptr_local)
WIL(WI_LOCAL_GET, rptr_local);
emit_load_instruction(mod, &code, elem_type, i * elem_size);
- if (!type_is_structlike(rtype)) {
+ if (!type_is_structlike(elem_type)) {
emit_store_instruction(mod, &code, elem_type, i * elem_size);
} else {
WIL(WI_LOCAL_GET, lptr_local);
--- /dev/null
+Array of structs on the stack.
+Vec2(4039, 7782)
+Array of structs from function call.
+Vec2(0, 0)
+Vec2(1, 1)
+Vec2(4, 8)
+Vec2(9, 27)
+Array of structs on a struct.
+Vec2(3, 9)
+Vec2(3, 27)
+Array of structs on a struct from function call.
+Vec2(25, 125)
+Vec2(100, 1000)
+Array of u32.
+63001
--- /dev/null
+#include_file "core/std/js"
+
+use package core
+
+Vec2 :: struct { x: i32; y: i32; }
+
+// Overload print() to print Vec2's.
+proc (use v: Vec2) #add_overload print {
+ printf("Vec2(%i, %i)", x, y);
+}
+
+EntityStore :: struct {
+ positions : [4] Vec2;
+ velocities : [4] Vec2;
+}
+
+calc_vecs :: proc (n := 0) -> [4] Vec2 {
+ vecs : [4] Vec2;
+
+ i := n;
+ for ^v: vecs {
+ v.x = i * i;
+ v.y = i * i * i;
+ i += 1;
+ }
+
+ return vecs;
+}
+
+main :: proc (args: [] cstr) #export "MAIN" {
+ // Array of structs on stack
+ {
+ println("Array of structs on the stack.");
+ vecs : [8] Vec2;
+ for ^v: vecs {
+ v.x = 4039;
+ v.y = 7782;
+ }
+
+ println(vecs[3]);
+ }
+
+ // Array of structs from function call
+ {
+ println("Array of structs from function call.");
+ vecs := calc_vecs();
+ for ^v: vecs do println(*v);
+ }
+
+ // Array of structs on a struct
+ {
+ println("Array of structs on a struct.");
+
+ es : EntityStore;
+ es.positions = Vec2.[
+ Vec2.{ 0, 0 },
+ Vec2.{ 1, 1 },
+ Vec2.{ 2, 4 },
+ Vec2.{ 3, 9 },
+ ];
+
+ es.velocities = Vec2.[
+ Vec2.{ 0, 0 },
+ Vec2.{ 1, 1 },
+ Vec2.{ 2, 8 },
+ Vec2.{ 3, 27 },
+ ];
+
+ println(es.positions[3]);
+ println(es.velocities[3]);
+ }
+
+ // Array of structs on a struct from function call
+ {
+ println("Array of structs on a struct from function call.");
+
+ es : EntityStore;
+ es.positions = calc_vecs(5);
+ es.velocities = calc_vecs(10);
+
+ println(es.positions[0]);
+ println(es.velocities[0]);
+ }
+
+ // Array of u32
+ {
+ println("Array of u32.");
+
+ nums : [100] u32;
+ i := 1;
+ for ^n: nums {
+ *n = i * i;
+ i += 5;
+ }
+
+ println(nums[50]);
+ }
+}
\ No newline at end of file