diff options
Diffstat (limited to 'test.toc')
-rw-r--r-- | test.toc | 41 |
1 files changed, 34 insertions, 7 deletions
@@ -1,14 +1,41 @@ io ::= nms { - #include "std/io.toc"; +#include "std/io.toc"; }; -Arr ::= struct(x::Type) { - data: []x; +LinkedList ::= struct(t::Type) { + head : t; + tail : &LinkedList(t); +}; + +arr_to_ll ::= fn(t::Type, data: []t) l : LinkedList(t) { + if data.len == 1 { + l.head = data[0]; + l.tail = 0 as &LinkedList(t); + } else { + l.head = data[0]; + l.tail = new(LinkedList(t)); + *l.tail = arr_to_ll(t, data[1:]); + } +}; + +do_thing ::= fn() int { + + a := new(int, 3); + a[0] = 10; + a[1] = 20; + a[2] = 30; + x := arr_to_ll(int, a); + p := &x; + i := 0; + while p { + io.puti(p.head); + p = p.tail; + i += 1; + } + i }; main ::= fn() { - x:Arr(int); - x.data = new(int, 10); - x.data[0] = 17; - io.puti(x.data[0]); + x ::= do_thing(); + do_thing(); };
\ No newline at end of file |