summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-16 20:24:23 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-16 20:24:23 -0400
commit6855c6e752e4e4f2f37702477a3b461a51bbc614 (patch)
treeea3b8ea8f872139515009564a64afdee401441c0 /std
parent970a379d5ee3e8a585a3138a64411ce80f31c8b7 (diff)
made new and del functions
Diffstat (limited to 'std')
-rw-r--r--std/mem.toc23
1 files changed, 23 insertions, 0 deletions
diff --git a/std/mem.toc b/std/mem.toc
new file mode 100644
index 0000000..06890b5
--- /dev/null
+++ b/std/mem.toc
@@ -0,0 +1,23 @@
+// TODO: check for failed malloc
+malloc ::= #foreign("malloc", "libc.so.6") fn(#C size_t) #C &"void";
+free ::= #foreign("free", "libc.so.6") fn(#C &"void");
+
+new ::= fn(t :: Type) &t {
+ malloc((sizeof t) as u64)
+}
+
+news ::= fn(t :: Type, n :: int) []t {
+ s: []t;
+ s.data = malloc((n * 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