summaryrefslogtreecommitdiff
path: root/tests/mem.toc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mem.toc')
-rw-r--r--tests/mem.toc23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/mem.toc b/tests/mem.toc
new file mode 100644
index 0000000..5e8c5fa
--- /dev/null
+++ b/tests/mem.toc
@@ -0,0 +1,23 @@
+// TODO: check for failed calloc
+calloc ::= #foreign("calloc", "libc.so.6") fn(#C size_t, #C size_t) #C &"void";
+free ::= #foreign("free", "libc.so.6") fn(#C &"void");
+
+new ::= fn(t :: Type) &t {
+ calloc(1, (sizeof t) as u64)
+}
+
+news ::= fn(t :: Type, n : int) []t {
+ s: []t;
+ s.data = calloc(n as u64, (sizeof t) as u64);
+ 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);
+} \ No newline at end of file