summaryrefslogtreecommitdiff
path: root/tests/varargs.toc
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-12 19:31:28 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-12 19:32:00 -0400
commit65c9211b961c0c5d2c48b37533825852013687b5 (patch)
treef00d0eaa5f844e35f05712e33e738679e992c5a4 /tests/varargs.toc
parent1338c083d649ab15d4dee63a6f6d49e891f9cdfa (diff)
added varargs test, showed that somethings wrong
Diffstat (limited to 'tests/varargs.toc')
-rw-r--r--tests/varargs.toc37
1 files changed, 37 insertions, 0 deletions
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);
+};