diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test.sh | 1 | ||||
-rw-r--r-- | tests/varargs.toc | 37 | ||||
-rw-r--r-- | tests/varargs_expected | 9 |
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/test.sh b/tests/test.sh index b0b27e1..ac195bc 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,6 +1,7 @@ #!/bin/bash tests='bf +varargs arr arr2 arr3 diff --git a/tests/varargs.toc b/tests/varargs.toc new file mode 100644 index 0000000..7ffb758 --- /dev/null +++ b/tests/varargs.toc @@ -0,0 +1,37 @@ +printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int; + +tprintf ::= fn(fmt: []char, args: ..) { + printf(&fmt[0], args); +}; + +sum ::= fn(x: ..) int { + total := 0; + n := 0; + for a, i := x { + total += a + i / i; + n += 1; + } + total - n +}; + +sumc ::= fn(x:: ..) int { + total := 0; + n := 0; + for a, i := x { + total += a + i / i; + n += 1; + } + total - n +}; + +do_printing ::= fn(x::..) { + tprintf("%ld\n",sum(x)); + tprintf("%ld\n",sumc(x)); +}; + +main ::= fn() { + do_printing(); + do_printing(1,2,3); + do_printing(4); + do_printing(1,10,100,1000,10000); +}; diff --git a/tests/varargs_expected b/tests/varargs_expected new file mode 100644 index 0000000..5436134 --- /dev/null +++ b/tests/varargs_expected @@ -0,0 +1,9 @@ +0 +0 +6 +6 +4 +4 +11111 +11111 + |