diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 17:43:13 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 17:43:13 -0400 |
commit | 1cceedc5ca053b018bc98e96a7dd77d17dde1ada (patch) | |
tree | 8295bb9dce0f70e533e8a98bc978490b6c2fa742 /tests | |
parent | a161b75a01eee7249f989c3a85d92b69c1818370 (diff) |
consistently handling indexing pointer to array/slice
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arrs_slices.toc | 47 | ||||
-rw-r--r-- | tests/arrs_slices_expected | 2 | ||||
-rwxr-xr-x | tests/test.sh | 1 |
3 files changed, 50 insertions, 0 deletions
diff --git a/tests/arrs_slices.toc b/tests/arrs_slices.toc new file mode 100644 index 0000000..dc7526d --- /dev/null +++ b/tests/arrs_slices.toc @@ -0,0 +1,47 @@ +#include "std/mem.toc", mem; +#include "std/io.toc", io; +use mem; + +fill_array ::= fn(n ::=, a : &[n]int) { + for i := 0..n-1 { + a[i] = i*i; + } + a[0] = 17; +} + +sum_array ::= fn(n ::=, a : &[n]int) total := 0 { + for i := 0..n-1 { + total += a[i]; + } +} + +fill_slice ::= fn(a: &[]int) { + *a = mem.news(int, 3); + a[0] = 1; + a[1] = 48; + a[2] = 136; +} + +sum_slice ::= fn(a : &[]int) total := 0 { + for i := 0..a.len-1 { + total += a[i]; + } +} + +thing ::= fn() int { + foo : [5]int; + fill_array(&foo); + a := sum_array(&foo); + bar : []int; + defer dels(bar); + fill_slice(&bar); + b := sum_slice(&bar); + a+b +} + +main ::= fn() { + a := thing(); + b ::= thing(); + io.puti(a); + io.puti(b); +} diff --git a/tests/arrs_slices_expected b/tests/arrs_slices_expected new file mode 100644 index 0000000..d41c8a7 --- /dev/null +++ b/tests/arrs_slices_expected @@ -0,0 +1,2 @@ +232 +232 diff --git a/tests/test.sh b/tests/test.sh index 1168e5b..75697ef 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -3,6 +3,7 @@ tests='bf control_flow types +arrs_slices defer sizeof new |