aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/extern.sloth5
-rw-r--r--std/stdmem.c20
-rw-r--r--std/stdmem.sloth0
3 files changed, 25 insertions, 0 deletions
diff --git a/std/extern.sloth b/std/extern.sloth
index c970541..e99a6cc 100644
--- a/std/extern.sloth
+++ b/std/extern.sloth
@@ -26,3 +26,8 @@ foreign fn clientsock(port: Int, addr: String) Int;
foreign fn closesock(soc: Int, server:Bool);
foreign fn sendsock(msg: String, soc: Int);
foreign fn recvsock(soc: Int) String;
+
+#stdmem
+foreign fn memalloc(size: Int) Int;
+foreign fn drefi(loc: Int) Int;
+foreign fn assignrefi(loc: Int, num: Int);
diff --git a/std/stdmem.c b/std/stdmem.c
new file mode 100644
index 0000000..c3d0300
--- /dev/null
+++ b/std/stdmem.c
@@ -0,0 +1,20 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+char *heap[100000];
+int heaploc = 0;
+
+int memalloc(int size) {
+ const int chunk = heaploc;
+ heap[heaploc++] = malloc(size);
+ printf("MEMALLOC: heap[%d]\n", chunk);
+ return chunk;
+}
+int drefi(int loc) {
+ printf("DREF: *heap[%d] = %d\n", loc, *heap[loc]);
+ return *heap[loc];
+}
+void assignrefi(int loc, int num) {
+ *heap[loc] = num;
+ printf("ASSREF: *heap[%d] = %d\n", loc, *heap[loc]);
+}
diff --git a/std/stdmem.sloth b/std/stdmem.sloth
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/std/stdmem.sloth