From 7bb5ac5863bdb4bc7af04ee18e81657a85aa97f2 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 13 Mar 2020 15:32:12 -0400 Subject: added where conditions for functions, discovered bug with eval returning --- tests/where.toc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/where.toc (limited to 'tests/where.toc') diff --git a/tests/where.toc b/tests/where.toc new file mode 100644 index 0000000..4223656 --- /dev/null +++ b/tests/where.toc @@ -0,0 +1,30 @@ +printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; + +tprintf_valid ::= fn(fmt :: []char, nargs: int) bool { + if fmt[fmt.len-1] != '\0' { + return false; + } + count := 0; + for x, i := fmt { + if x == '%' { + if i == fmt.len-1 { + count += 1; + } elif fmt[i+1] != '%' { + count += 1; + } else { + count -= 1; + } + } + } + count == nargs +}; + + +tprintf ::= fn(fmt :: []char, args: ..) where tprintf_valid(fmt, args.len) { + f := fmt; + printf(&f[0], args); +}; + +main ::= fn() { + tprintf("%d %d%%\n\0", 3, 4); +}; -- cgit v1.2.3