summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-05-08 13:58:17 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-05-08 13:58:17 -0400
commit8b4a6f6298fadf92a4f9a5d9879225ba7d27270d (patch)
treefa640c60c6b8be226da1a8797c319218d3ef31d1 /tests
parent38d57cdce42115fac4eb48bb441ac31f0fd81a7a (diff)
got double include to work
Diffstat (limited to 'tests')
l---------tests/std1
-rw-r--r--tests/std/arr.toc29
-rw-r--r--tests/std/base.toc23
-rw-r--r--tests/std/io.toc65
-rw-r--r--tests/std/mem.toc25
5 files changed, 1 insertions, 142 deletions
diff --git a/tests/std b/tests/std
new file mode 120000
index 0000000..6ef7545
--- /dev/null
+++ b/tests/std
@@ -0,0 +1 @@
+../std \ No newline at end of file
diff --git a/tests/std/arr.toc b/tests/std/arr.toc
deleted file mode 100644
index a2d202b..0000000
--- a/tests/std/arr.toc
+++ /dev/null
@@ -1,29 +0,0 @@
-// this could be made quite a bit faster with realloc
-
-Arr ::= struct (t :: Type) {
- data : []t;
- cap : int;
-};
-
-resv ::= fn(t ::=, a : &Arr(t), n: int) {
- if a.cap >= n {
- return;
- }
- a.cap = n;
- new_data := new(t, a.cap);
- new_data.len = a.data.len;
- for x, i := &new_data {
- *x = a.data[i];
- }
- a.data = new_data;
-};
-
-add ::= fn(t ::=, a : &Arr(t), x : t) {
- if a.data.len >= a.cap {
- resv(a, a.cap * 2 + 2);
- }
- a.data.len += 1;
- a.data[a.data.len-1] = x;
-};
-
-len ::= fn(t ::=, a : Arr(t)) int { a.data.len };
diff --git a/tests/std/base.toc b/tests/std/base.toc
deleted file mode 100644
index bdb91e0..0000000
--- a/tests/std/base.toc
+++ /dev/null
@@ -1,23 +0,0 @@
-PLATFORM_OTHER ::= 0;
-PLATFORM_LINUX ::= 1;
-PLATFORM_WINDOWS ::= 2;
-PLATFORM_OSX ::= 3;
-PLATFORM_FREEBSD ::= 4;
-PLATFORM_OPENBSD ::= 5;
-PLATFORM_MISC_UNIX ::= 6;
-
-PLATFORM ::= #builtin("platform");
-#if PLATFORM == PLATFORM_LINUX {
- libc ::= "libc.so.6";
-} elif PLATFORM == PLATFORM_WINDOWS {
- libc ::= "msvcrt.dll";
-} elif PLATFORM == PLATFORM_OSX {
- libc ::= "libc.dylib";
-} elif PLATFORM == PLATFORM_FREEBSD || PLATFORM == PLATFORM_OPENBSD {
- libc ::= "libc.so";
-} else {
- /* maybe it's non-linux gnu? */
- libc ::= "libc.so.6";
-}
-
-
diff --git a/tests/std/io.toc b/tests/std/io.toc
deleted file mode 100644
index 994cd2a..0000000
--- a/tests/std/io.toc
+++ /dev/null
@@ -1,65 +0,0 @@
-/* @TODO: use write / WriteFile */
-
-#include "std/base.toc";
-
-putchar ::= #foreign("putchar", libc) fn(#C int) #C int;
-toc_putchar ::= fn(x: char) {
- putchar(x as #C int);
-}
-
-/*
-unfortunately, we can't use fwrite because MSVC doesn't like it when you
-use a file handle that's not from the DLL. (i.e. you can't pass your stdout
-to the imported version of fwrite)
-*/
-
-writes ::= fn(x: []char) {
- for c := x {
- toc_putchar(c);
- }
-}
-
-puts ::= fn(x: []char) {
- writes(x);
- toc_putchar('\n');
-}
-
-writei ::= fn(x: int) {
- if x < 0 {
- toc_putchar('-');
- // NOTE: don't do x = -x; here to make sure I64_MIN works
- }
- if x == 0 {
- toc_putchar('0');
- } else {
- abs ::= fn(x: int) int { if x < 0 { -x } else { x } };
- scan_digit := 1000000000000000000;
- started := false;
- while scan_digit > 0 {
- digit := abs((x / scan_digit) % 10);
- if digit > 0 { started = true; }
- if started {
- toc_putchar((('0' as int) + digit) as char);
- }
- scan_digit /= 10;
- }
- }
-}
-
-puti ::= fn(x: int) {
- writei(x);
- toc_putchar('\n');
-}
-
-/* @TODO: write your own version of this */
-printf ::= #foreign("printf", libc) fn(#C &"const char", #C ..) #C int;
-writef ::= fn(x: float) {
- fmt := "%f\0";
- printf(&fmt[0], x as f64);
-};
-putf ::= fn(x: float) {
- writef(x);
- toc_putchar('\n');
-}
-
-
diff --git a/tests/std/mem.toc b/tests/std/mem.toc
deleted file mode 100644
index e283364..0000000
--- a/tests/std/mem.toc
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "std/base.toc";
-
-// TODO: check for failed calloc
-calloc ::= #foreign("calloc", libc) fn(#C size_t, #C size_t) #C &"void";
-free ::= #foreign("free", libc) fn(#C &"void");
-
-new ::= fn(t :: Type) &t {
- calloc(1, (sizeof t) as #C size_t)
-}
-
-news ::= fn(t :: Type, n : int) []t {
- s: []t;
- s.data = calloc(n as #C size_t, (sizeof t) as #C size_t);
- s.len = n;
- s
-}
-
-// TODO(eventually): use type information to make this just one function
-del ::= fn(t::=, x: &t) {
- free(x);
-}
-
-dels ::= fn(t::=, x: []t) {
- free(x.data);
-}