diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-02 17:21:54 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-02 17:21:54 -0500 |
commit | 153001dd24eece3aa38b57ae2dced25fc0856d0c (patch) | |
tree | 75ed3689b283f093e6f02a5dbac6f1498ea3801b /test.toc | |
parent | e12efeebae81d524f96eea33813f57d4b90020bc (diff) |
started #if
Diffstat (limited to 'test.toc')
-rw-r--r-- | test.toc | 71 |
1 files changed, 5 insertions, 66 deletions
@@ -1,70 +1,9 @@ -puti ::= fn(x: int) { -//tcc's giving me "incompatible types for redefinition of 'printf'" for some reason (even though the declarations have the exact same type) - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%ld\\n\", (long)x);"); -}; -putf ::= fn(x: float) { - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%f\\n\", (double)x);"); -}; - -// 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; - } -}; - -arr_add ::= fn(t :: Type, a : &Arr(t), x : t) { - if a.len >= a.cap { - a.cap = a.cap * 2 + 2; - new_data := new(t, a.cap); - for i := 0..a.len-1 { - new_data[i] = a.data[i]; - } - a.data = new_data; - } - a.data[a.len] = x; - a.len += 1; -}; - -square ::= fn(t :: Type, x : t) t { - a : Arr(t); - for i := 1,2..2*x-1 { - arr_add(t, &a, i); - }; - sum := 0 as t; - for i := 0..a.len-1 { - sum += a.data[i]; - }; - sum -}; - - -ArrInt ::= Arr(int); - -inc ::= fn(t :: Type, x : t) t { - x + 1 -}; +#include "std/io.toc", io; main ::= fn() { - arr : ArrInt; - farr : Arr(float); - for i := 1..100 { - arr_add(int, &arr, inc(int, square(int, i))); - arr_add(float, &farr, inc(float, square(float, i as float))); - } - for i := 0..arr.len - 1 { - puti(arr.data[i]); - } - for i := 0..farr.len - 1 { - putf(farr.data[i]); + #if 3 > 5 { + io.puts("3 > 5"); + } else { + io.puts("5 >= 3"); } }; |