diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 15:01:47 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-25 15:01:47 -0400 |
commit | 7ee5fc2721e40471f01f9377dd901ded4b969a33 (patch) | |
tree | 4b7326e96e89607b86b37d38fd0a8754144f370a /tests | |
parent | 7aa21a12d1b5505ba6258f2a74ce8716e72387c3 (diff) |
fixed problems with using future types
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test.sh | 1 | ||||
-rw-r--r-- | tests/types.toc | 48 | ||||
-rw-r--r-- | tests/types_expected | 13 |
3 files changed, 62 insertions, 0 deletions
diff --git a/tests/test.sh b/tests/test.sh index e6e8fe5..1168e5b 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -2,6 +2,7 @@ tests='bf control_flow +types defer sizeof new diff --git a/tests/types.toc b/tests/types.toc new file mode 100644 index 0000000..4ef55e8 --- /dev/null +++ b/tests/types.toc @@ -0,0 +1,48 @@ +#include "io.toc", io; +#include "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; + } + 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:]); + } +} + +LinkedList ::= struct (of :: Type) { + head: of; + tail: &LinkedList(of); +} + +Foo ::= struct { + k: int; + b: &Bar; +} + +Bar ::= struct { + f: Foo; +} diff --git a/tests/types_expected b/tests/types_expected new file mode 100644 index 0000000..eef051c --- /dev/null +++ b/tests/types_expected @@ -0,0 +1,13 @@ +0 +1 +4 +9 +16 +25 +36 +49 +64 +81 +-173 +0 +9 |