diff options
Diffstat (limited to 'tests/arr2.toc')
-rw-r--r-- | tests/arr2.toc | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/tests/arr2.toc b/tests/arr2.toc index 4d8ca82..7e29a95 100644 --- a/tests/arr2.toc +++ b/tests/arr2.toc @@ -3,55 +3,55 @@ // it would be nice if Arr.data.len == Arr.len (: but this will require some C code... Arr ::= fn (t :: Type) Type { - struct { - data : []t; - len, cap : int; - } + return struct { + data : []t; + len, cap : int; + }; }; arr_add ::= fn(t ::=, a : &Arr(t), x : t) { - if a.len >= a.cap { - a.cap = a.cap * 2 + 2; - new_data := news(t, a.cap); - for i := 0..a.len-1 { - new_data[i] = a.data[i]; - } - a.data = new_data; + if a.len >= a.cap { + a.cap = a.cap * 2 + 2; + new_data := news(t, a.cap); + for i := 0..a.len-1 { + new_data[i] = a.data[i]; } - a.data[a.len] = x; - a.len += 1; + a.data = new_data; + } + a.data[a.len] = x; + a.len += 1; }; square ::= fn(t ::=, x : t) t { - a : Arr(t); - for i := 1,2..2*x-1 { - arr_add(&a, i); - }; - sum := 0 as t; - for i := 0..a.len-1 { - sum += a.data[i]; - }; - sum + a : Arr(t); + for i := 1,2..2*x-1 { + arr_add(&a, i); + }; + sum := 0 as t; + for i := 0..a.len-1 { + sum += a.data[i]; + }; + return sum; }; // ArrInt ::= Arr(int); inc ::= fn(t ::=, x : t) t { - x + 1 + return x + 1; }; main ::= fn() { - arr : Arr(int); - farr : Arr(float); - for i := 1..100 { - arr_add(&arr, inc(square(i))); - arr_add(&farr, inc(square(i as float))); - } - for i := 0..arr.len - 1 { - puti(arr.data[i]); - } - for i := 0..farr.len - 1 { - putf(farr.data[i]); - } + arr : Arr(int); + farr : Arr(float); + for i := 1..100 { + arr_add(&arr, inc(square(i))); + arr_add(&farr, inc(square(i as float))); + } + for i := 0..arr.len - 1 { + puti(arr.data[i]); + } + for i := 0..farr.len - 1 { + putf(farr.data[i]); + } }; |