diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 16:10:45 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 16:10:45 -0400 |
commit | a161b75a01eee7249f989c3a85d92b69c1818370 (patch) | |
tree | fb65753b6e84b102787523a8948bc5507400f3b3 /test.toc | |
parent | 7ee5fc2721e40471f01f9377dd901ded4b969a33 (diff) |
stop copying whole fn body unless necessary when generating an instance
Diffstat (limited to 'test.toc')
-rw-r--r-- | test.toc | 61 |
1 files changed, 20 insertions, 41 deletions
@@ -1,48 +1,27 @@ +#include "std/mem.toc", mem; #include "std/io.toc", io; -#include "std/mem.toc"; - -main ::= fn() { - nums := news(int, 10); - for x, i := &nums { - *x = i*i; - } - l := slice_to_ll(nums); - p := &l; - while p { - io.puti(p.head); - p = p.tail; +calculation ::= fn() int { + total := 0; + i := mem.new(int); + *i = 3; + ns := mem.news(int, 10); + for n, i := &ns { + if i % 2 == 0 { + *n = i; + } } - f: Foo; - f.k = -173; - f.b = new(Bar); - f.b.f.b = new(Bar); - f.b.f.b.f.k = 9; - io.puti(f.k); - io.puti(f.b.f.k); - io.puti(f.b.f.b.f.k); -} - -slice_to_ll ::= fn(t::=, slice: []t) use ll: LinkedList(t) { - head = slice[0]; - if slice.len == 1 { - tail = 0 as &LinkedList(t); - } else { - tail = new(LinkedList(t)); - *tail = slice_to_ll(slice[1:]); + for n := ns { + total += n; } + total += *i; + mem.del(i); + mem.dels(ns); + total } -LinkedList ::= struct (of :: Type) { - head: of; - tail: &LinkedList(of); -} - -Foo ::= struct { - k: int; - b: &Bar; -} - -Bar ::= struct { - f: Foo; +main ::= fn() { + io.puti(calculation()); + x ::= calculation(); + io.puti(x); } |