Skip to content

Commit

Permalink
Standard library updated and llvm-sys added to cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Jun 26, 2023
1 parent bf647e4 commit 28ab9c8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/mergesort.sloth
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn merge_sort(list: List<Int>) {
print(list);

}
1 change: 1 addition & 0 deletions sloth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions std/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
2 changes: 2 additions & 0 deletions std/stdlib.sloth
Original file line number Diff line number Diff line change
@@ -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[");
Expand Down
11 changes: 11 additions & 0 deletions std/stdmath.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion std/stdmath.sloth
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
foreign fn rand() Int;
foreign fn randGen(min: Int, max: Int) Int;

fn abs(x: Int) Int {
if x < 0 {
Expand Down

0 comments on commit 28ab9c8

Please sign in to comment.