aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh2
-rw-r--r--examples/cgol.sloth2
-rw-r--r--examples/mem.sloth9
-rw-r--r--sloth/src/codegen/mod.rs1
-rw-r--r--std/extern.sloth5
-rw-r--r--std/stdmem.c20
-rw-r--r--std/stdmem.sloth0
7 files changed, 37 insertions, 2 deletions
diff --git a/build.sh b/build.sh
index a53fb29..760f2ab 100755
--- a/build.sh
+++ b/build.sh
@@ -5,7 +5,7 @@ FILENAME="$1"
./target/release/sloth std/extern.sloth std/stdmath.sloth std/stdio.sloth $FILENAME
# Generate binary
-clang -lm output.o std/stdsocket.c std/stdio.c std/stdlib.c std/stdmath.c -o "${FILENAME%.sloth}"
+clang -lm output.o std/stdsocket.c std/stdio.c std/stdlib.c std/stdmath.c std/stdmem.c -o "${FILENAME%.sloth}"
# Move file
mv "${FILENAME%.sloth}" out/
diff --git a/examples/cgol.sloth b/examples/cgol.sloth
index fafe440..db578f9 100644
--- a/examples/cgol.sloth
+++ b/examples/cgol.sloth
@@ -1,7 +1,7 @@
fn populate() [Int]
{
# Initialize life vector
- var life: [Int] = [1];
+ var life: [Int] = ["Hello World"];
vpopi(life);
# Fill the vector with random values
diff --git a/examples/mem.sloth b/examples/mem.sloth
new file mode 100644
index 0000000..cb52191
--- /dev/null
+++ b/examples/mem.sloth
@@ -0,0 +1,9 @@
+fn main() {
+ var intpointer: Int = memalloc(64);
+ println("We vibin");
+ assignrefi(intpointer, 10);
+ println("Still vibin");
+ var derefd: Int = drefi(intpointer);
+ print("Val of drefd: ");
+ println(istr(derefd));
+}
diff --git a/sloth/src/codegen/mod.rs b/sloth/src/codegen/mod.rs
index 7ac1011..abad70d 100644
--- a/sloth/src/codegen/mod.rs
+++ b/sloth/src/codegen/mod.rs
@@ -556,6 +556,7 @@ impl<'ctx> Codegen<'ctx> {
"",
)
};
+
self.builder.build_store(value_ptr, value);
}
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