diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-23 14:01:20 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-04-23 14:01:20 -0400 |
commit | f7bfb9492ab546e886fd40bda1a0ab25fcb05247 (patch) | |
tree | 1ec694390050cc3eb21009963d40dc6655c0a5fa /tests | |
parent | 4062e5c965bc04ec9654d82526e5e785f7f45d03 (diff) |
fixed error printing problem, added new test: use
Diffstat (limited to 'tests')
-rw-r--r-- | tests/io.toc | 16 | ||||
-rwxr-xr-x | tests/test.sh | 1 | ||||
-rw-r--r-- | tests/use.toc | 45 | ||||
-rw-r--r-- | tests/use_expected | 6 |
4 files changed, 64 insertions, 4 deletions
diff --git a/tests/io.toc b/tests/io.toc index d3ce467..2c82dc9 100644 --- a/tests/io.toc +++ b/tests/io.toc @@ -2,16 +2,19 @@ putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; toc_putchar ::= fn(x: char) { putchar(x as #C int); } +printf ::= #foreign("printf", "libc.so.6") fn(#C &"char const", #C ..) #C int; +writes ::= fn(x: []char) { + printf_strfmt := "%s\0"; + printf(&printf_strfmt[0], &x[0]); +} puts ::= fn(x: []char) { - for c := x { - toc_putchar(c); - } + writes(x); toc_putchar('\n'); } -puti ::= fn(x: int) { +writei ::= fn(x: int) { if x < 0 { toc_putchar('-'); // NOTE: don't do x = -x; here to make sure I64_MIN works @@ -31,5 +34,10 @@ puti ::= fn(x: int) { scan_digit /= 10; } } +} + +puti ::= fn(x: int) { + writei(x); toc_putchar('\n'); } + diff --git a/tests/test.sh b/tests/test.sh index a603767..e6e8fe5 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -13,6 +13,7 @@ params nms varargs printf +use misc' STARTPWD=$(pwd) diff --git a/tests/use.toc b/tests/use.toc new file mode 100644 index 0000000..f1228f6 --- /dev/null +++ b/tests/use.toc @@ -0,0 +1,45 @@ +#include "io.toc", io; +#include "mem.toc", mem; + +use mem; + +Point ::= struct { + x: int; + y: int; + a ::= 3; +} + +make_point ::= fn (x_: int, y_: int) use p: Point { + x = x_+a; + y = y_+a; +} + +main ::= fn() { + + use io; + + { + use p: Point; + use io; + x = 5; + puti(x); + } + + + + ps := news(Point, 5); + for p := &ps { + *p = make_point(3, 5); + } + for use p, i := &ps { + x += i; + y += 2*i; + } + for use p := ps { + writei(x); + writes(" "); + writei(y); + puts(""); + } + dels(ps); +} diff --git a/tests/use_expected b/tests/use_expected new file mode 100644 index 0000000..d47a933 --- /dev/null +++ b/tests/use_expected @@ -0,0 +1,6 @@ +5 +6 8 +7 10 +8 12 +9 14 +10 16 |