From 28ab9c8ba094d86dbcb9abb853dddd83dca028cc Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Sun, 25 Jun 2023 19:41:03 -0500 Subject: Standard library updated and llvm-sys added to cargo.toml --- std/stdlib.c | 8 ++++++++ std/stdlib.sloth | 2 ++ std/stdmath.c | 11 +++++++++++ std/stdmath.sloth | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 std/stdmath.c (limited to 'std') 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 +#include +#include + +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 { -- cgit v1.2.3