From 1380b802dce45956df02de8c088dc20b81959be6 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 17 Dec 2020 16:02:08 -0600 Subject: [PATCH] added test case for array/struct robustness; small bugfix --- onyx | Bin 516732 -> 516732 bytes src/onyxwasm.c | 4 +- tests/array_struct_robustness | 15 +++++ tests/array_struct_robustness.onyx | 98 +++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 tests/array_struct_robustness create mode 100644 tests/array_struct_robustness.onyx diff --git a/onyx b/onyx index adabd591f2cd54e4de49bf3bd92029a5c46ff051..7e4f8e784411ae235b607d6681ccdd2a0420641a 100755 GIT binary patch delta 154 zcmV;L0A>ID#2@^`AAp1bv;rOb0l2pw`vQLh0l2rG{sK-40a&-~2m_wh0R*><-vb~& z0k?;(9t5|o9tEjz0a>?Kj|EH`0mZkZsRe}u0qD0Xt_3Io0rQtruLbY{1-C@71y%|H zI+vTe1z-U@xBR*Vn;HSBx0uxhV=@7SxBLeNB{c!=mm)m|(gF6j^*shG5&=htB2Wgm IB2WiflC-uu>;M1& delta 154 zcmV;L0A>ID#2@^`AAp1bv;rOb0l>E&`vQLh0l>GO{sK-40aUl`2m_wh0RXp*-vb~& z0kem#9t5|o9tEjz0adqGj|EH`0l~MVsRe}u0pzzTt_3Io0q>VnuLbY{0k=f31y%|H zHkX^a1z-U [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 -- 2.25.1