summaryrefslogtreecommitdiff
path: root/test.toc
diff options
context:
space:
mode:
Diffstat (limited to 'test.toc')
-rw-r--r--test.toc49
1 files changed, 15 insertions, 34 deletions
diff --git a/test.toc b/test.toc
index e030af4..8d884fd 100644
--- a/test.toc
+++ b/test.toc
@@ -1,37 +1,18 @@
-printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int;
-
-
-// NOTE: this doesn't work (e.g. "%%%")
-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;
- }
- }
+#include "std/mem.toc", mem;
+#include "std/io.toc", io;
+main ::= fn() {
+ i := mem.new(int);
+ *i = 3;
+ io.puti(*i);
+ ns := mem.news(int, 10);
+ for n, i := &ns {
+ *n = i;
}
- count == nargs
-};
-
-
-tprintf ::= fn(fmt :: []char, args: ..) {
- #if !tprintf_valid(fmt, args.len) {
- #error "Invalid printf format";
+ for n := ns {
+ io.puti(n);
}
- f := fmt;
- printf(&f[0], args);
-};
+ mem.del(i);
+ mem.dels(ns);
+}
+main();
-main ::= fn() {
- tprintf("%d %d%%\n\0", 3, 4);
- tprintf("%d %d %d%%\n\0", 3, 4, 5);
- tprintf("Hello!\n\0");
-};