Skip to content

Commit

Permalink
Fixed wait
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-gaffney committed Jun 27, 2023
1 parent 2cf498f commit 2c347aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build Sloth
cargo build
cargo build --features=llvm-sys/prefer-dynamic
FILENAME="$1"
# Compile standard library
./target/debug/sloth std/stdio.sloth std/stdlib.sloth std/stdmath.sloth $FILENAME
Expand Down
Binary file modified cgol
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/cgol.sloth
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn main() Int {
update(life, new);
display(new);
life = new;
wait(1.0);
wait(100);
}
return 0;
}
23 changes: 20 additions & 3 deletions std/stdlib.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

void wait(float x) {
sleep(x);
int wait(int msec) {
struct timespec ts;
int res;

if (msec < 0)
{
errno = EINVAL;
return -1;
}

ts.tv_sec = msec / 1000;
ts.tv_nsec = (msec % 1000) * 1000000;

do {
res = nanosleep(&ts, &ts);
} while (res && errno == EINTR);

return res;
}

int slen(char *str) {
Expand Down
2 changes: 1 addition & 1 deletion std/stdlib.sloth
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
foreign fn wait(x: Float) Void;
foreign fn wait(x: Int) Int;
foreign fn print(str: String) Void;
foreign fn slen(str: String) Int;
# foreign fn charAt(str: String) Char;
Expand Down

0 comments on commit 2c347aa

Please sign in to comment.