summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/arr.toc2
-rw-r--r--tests/arr2.toc2
-rw-r--r--tests/arr3.toc4
-rw-r--r--tests/bf.toc73
-rw-r--r--tests/control_flow.toc4
-rw-r--r--tests/defer.toc2
-rw-r--r--tests/foreign.toc2
-rw-r--r--tests/misc.toc2
-rw-r--r--tests/new.toc4
-rw-r--r--tests/nms.toc2
-rw-r--r--tests/sizeof.toc4
-rw-r--r--tests/std/io.toc (renamed from tests/io.toc)0
-rw-r--r--tests/std/mem.toc (renamed from tests/mem.toc)0
-rw-r--r--tests/types.toc5
-rw-r--r--tests/use.toc4
15 files changed, 58 insertions, 52 deletions
diff --git a/tests/arr.toc b/tests/arr.toc
index 5fb8328..3af9edd 100644
--- a/tests/arr.toc
+++ b/tests/arr.toc
@@ -1,4 +1,4 @@
-#include "mem.toc";
+#include "std/mem.toc";
puti ::= fn(x: int) {
//tcc's giving me "incompatible types for redefinition of 'printf'" for some reason (even though the declarations have the exact same type)
#C("#ifndef __TINYC__
diff --git a/tests/arr2.toc b/tests/arr2.toc
index 9d6aa34..189512a 100644
--- a/tests/arr2.toc
+++ b/tests/arr2.toc
@@ -1,4 +1,4 @@
-#include "mem.toc";
+#include "std/mem.toc";
puti ::= fn(x: int) {
#C("#ifndef __TINYC__
extern int printf(const char *fmt, ...);
diff --git a/tests/arr3.toc b/tests/arr3.toc
index 4310d64..25c5554 100644
--- a/tests/arr3.toc
+++ b/tests/arr3.toc
@@ -1,5 +1,5 @@
-#include "io.toc";
-#include "mem.toc";
+#include "std/io.toc";
+#include "std/mem.toc";
arr_add ::= fn(t ::=, a : &Arr(t), x : t) {
diff --git a/tests/bf.toc b/tests/bf.toc
index d300bc9..166601b 100644
--- a/tests/bf.toc
+++ b/tests/bf.toc
@@ -1,43 +1,50 @@
-#include "mem.toc";
+#include "std/mem.toc";
+
readfile ::= fn(filename: []char) []char {
#C("extern void *fopen(char *name, char const *mode); extern char *fgets(char *buf, size_t sz, void *f);");
- fp : &u8 = #C("fopen(&(((char *)filename.data)[0]), \"r\")");
- contents := news(char, 1);
- contents_sz : int;
- contents_len : int;
- buffer : [1024]char;
- while #C("fgets(buffer, 1024, fp)") {
- buffer_len : int;
- while buffer[buffer_len] {
- buffer_len = buffer_len + 1;
- }
- if contents_sz < contents_len + buffer_len {
- old_contents := contents;
- contents_sz = 2*contents_sz + 1024;
- contents = news(char, contents_sz);
- i := 0;
- while i < contents_len {
- contents[i] = old_contents[i];
- i = i + 1;
- }
- dels(old_contents);
- }
- i := 0;
- while i < buffer_len {
- contents[contents_len] = buffer[i];
- contents_len = contents_len + 1;
- i = i + 1;
- }
- }
- contents[contents_len] = 0 as char;
- contents
+#C("
+extern int printf(const char *fmt, ...);
+extern void exit(int);
+");
+ fp : &u8 = #C("(u8 *)fopen(&(((char *)filename.data)[0]), \"r\")");
+ if !fp {
+ #C("printf(\"Couldn't open file\\n\"); exit(-1);");
+ }
+ contents := news(char, 1);
+ contents_sz : int;
+ contents_len : int;
+ buffer : [1024]char;
+ while #C("fgets(buffer, 1024, fp)") {
+ buffer_len : int;
+ while buffer[buffer_len] {
+ buffer_len = buffer_len + 1;
+ }
+ if contents_sz < contents_len + buffer_len {
+ old_contents := contents;
+ contents_sz = 2*contents_sz + 1024;
+ contents = news(char, contents_sz);
+ i := 0;
+ while i < contents_len {
+ contents[i] = old_contents[i];
+ i = i + 1;
+ }
+ dels(old_contents);
+ }
+ i := 0;
+ while i < buffer_len {
+ contents[contents_len] = buffer[i];
+ contents_len = contents_len + 1;
+ i = i + 1;
+ }
+ }
+ contents[contents_len] = 0 as char;
+ contents
};
puti ::= fn(x: int) {
- #C("#ifndef __TINYC__
+ #C("
extern int printf(const char *fmt, ...);
-#endif
");
#C("printf(\"%ld\\n\", x);");
};
diff --git a/tests/control_flow.toc b/tests/control_flow.toc
index 923a40b..043d4b7 100644
--- a/tests/control_flow.toc
+++ b/tests/control_flow.toc
@@ -1,4 +1,4 @@
-#include "io.toc", io;
+#include "std/io.toc", io;
f ::= fn() int {
total := 0;
@@ -28,4 +28,4 @@ main ::= fn() {
x ::= f();
io.puti(x);
io.puti(f());
-} \ No newline at end of file
+}
diff --git a/tests/defer.toc b/tests/defer.toc
index 578668d..ec06a19 100644
--- a/tests/defer.toc
+++ b/tests/defer.toc
@@ -1,4 +1,4 @@
-#include "io.toc", io;
+#include "std/io.toc", io;
plusone ::= fn(n : int) x := n {
defer x += 1;
diff --git a/tests/foreign.toc b/tests/foreign.toc
index d88a223..92038d9 100644
--- a/tests/foreign.toc
+++ b/tests/foreign.toc
@@ -22,4 +22,4 @@ hw ::= fn() int {
main ::= fn() {
hw();
x ::= hw();
-}; \ No newline at end of file
+};
diff --git a/tests/misc.toc b/tests/misc.toc
index 26ecf3e..5dcd1eb 100644
--- a/tests/misc.toc
+++ b/tests/misc.toc
@@ -1,4 +1,4 @@
-#include "io.toc", io;
+#include "std/io.toc", io;
main ::= fn() {
x ::= 3;
diff --git a/tests/new.toc b/tests/new.toc
index bb6a5fa..790a115 100644
--- a/tests/new.toc
+++ b/tests/new.toc
@@ -1,5 +1,5 @@
-#include "mem.toc", mem;
-#include "io.toc", io;
+#include "std/mem.toc", mem;
+#include "std/io.toc", io;
calculation ::= fn() int {
total := 0;
diff --git a/tests/nms.toc b/tests/nms.toc
index 413da8d..32c2955 100644
--- a/tests/nms.toc
+++ b/tests/nms.toc
@@ -1,5 +1,5 @@
io ::= nms {
- #include "io.toc";
+ #include "std/io.toc";
};
n ::= nms {
diff --git a/tests/sizeof.toc b/tests/sizeof.toc
index 0bc806b..5a97985 100644
--- a/tests/sizeof.toc
+++ b/tests/sizeof.toc
@@ -1,4 +1,4 @@
-#include "io.toc", io;
+#include "std/io.toc", io;
Point3D ::= struct {
x, y, z: f32;
@@ -14,4 +14,4 @@ main ::= fn() {
x ::= calculation();
io.puti(x);
io.puti(calculation());
-} \ No newline at end of file
+}
diff --git a/tests/io.toc b/tests/std/io.toc
index 2c82dc9..2c82dc9 100644
--- a/tests/io.toc
+++ b/tests/std/io.toc
diff --git a/tests/mem.toc b/tests/std/mem.toc
index 6d16895..6d16895 100644
--- a/tests/mem.toc
+++ b/tests/std/mem.toc
diff --git a/tests/types.toc b/tests/types.toc
index 4ef55e8..7262637 100644
--- a/tests/types.toc
+++ b/tests/types.toc
@@ -1,6 +1,5 @@
-#include "io.toc", io;
-#include "mem.toc";
-
+#include "std/io.toc", io;
+#include "std/mem.toc";
main ::= fn() {
nums := news(int, 10);
diff --git a/tests/use.toc b/tests/use.toc
index f1228f6..98e9221 100644
--- a/tests/use.toc
+++ b/tests/use.toc
@@ -1,5 +1,5 @@
-#include "io.toc", io;
-#include "mem.toc", mem;
+#include "std/io.toc", io;
+#include "std/mem.toc", mem;
use mem;