aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornic-gaffney <gaffney_nic@protonmail.com>2023-06-25 19:41:03 -0500
committernic-gaffney <gaffney_nic@protonmail.com>2023-06-25 19:41:03 -0500
commit28ab9c8ba094d86dbcb9abb853dddd83dca028cc (patch)
treeb30f3ff0218555270cde4c99c89fa866a4ad324a
parentbf647e430e3a3642c8199dc81a411d5e1586cabb (diff)
downloadsloth-28ab9c8ba094d86dbcb9abb853dddd83dca028cc.tar.gz
Standard library updated and llvm-sys added to cargo.toml
-rw-r--r--Cargo.lock1
-rw-r--r--examples/mergesort.sloth4
-rw-r--r--sloth/Cargo.toml1
-rw-r--r--std/stdlib.c8
-rw-r--r--std/stdlib.sloth2
-rw-r--r--std/stdmath.c11
-rw-r--r--std/stdmath.sloth2
7 files changed, 28 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1d886a8..8652bed 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -254,6 +254,7 @@ version = "0.1.0"
dependencies = [
"inkwell",
"itertools",
+ "llvm-sys",
"rand",
"thiserror",
]
diff --git a/examples/mergesort.sloth b/examples/mergesort.sloth
new file mode 100644
index 0000000..f1e5901
--- /dev/null
+++ b/examples/mergesort.sloth
@@ -0,0 +1,4 @@
+fn merge_sort(list: List<Int>) {
+ print(list);
+
+}
diff --git a/sloth/Cargo.toml b/sloth/Cargo.toml
index 1146e8e..f58f40e 100644
--- a/sloth/Cargo.toml
+++ b/sloth/Cargo.toml
@@ -6,6 +6,7 @@ version.workspace = true
edition.workspace = true
[dependencies]
+llvm-sys = "150"
inkwell = { version = "0.2.0", features = ["llvm15-0"] }
itertools = "0.10.5"
rand = "0.8.5"
diff --git a/std/stdlib.c b/std/stdlib.c
index b50c0c5..f8df9e8 100644
--- a/std/stdlib.c
+++ b/std/stdlib.c
@@ -3,3 +3,11 @@
void wait(long long x) {
sleep(x);
}
+
+int len(char *str) {
+ return strlen(str);
+}
+
+char charAt(char *str, int) {
+ return str[int];
+}
diff --git a/std/stdlib.sloth b/std/stdlib.sloth
index 7b6e2f9..36f3879 100644
--- a/std/stdlib.sloth
+++ b/std/stdlib.sloth
@@ -1,5 +1,7 @@
foreign fn wait(x: Int) Void;
foreign fn print(str: String) Void;
+foreign fn len(str: String) Int;
+foreign fn charAt(str: String) Char;
fn termpos(x: int, y: int) Void {
print("\x1b[");
diff --git a/std/stdmath.c b/std/stdmath.c
new file mode 100644
index 0000000..c9a91c3
--- /dev/null
+++ b/std/stdmath.c
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+int randGen(int min, int max) {
+ time_t t;
+
+ srand((unsigned) time(&t));
+
+ return rand() % (max - min + 1) + min;
+}
diff --git a/std/stdmath.sloth b/std/stdmath.sloth
index ebf9a7c..0f967eb 100644
--- a/std/stdmath.sloth
+++ b/std/stdmath.sloth
@@ -1,4 +1,4 @@
-foreign fn rand() Int;
+foreign fn randGen(min: Int, max: Int) Int;
fn abs(x: Int) Int {
if x < 0 {