diff options
| -rwxr-xr-x | build.sh | 2 | ||||
| -rwxr-xr-x | cgol | bin | 22096 -> 17184 bytes | |||
| -rw-r--r-- | examples/cgol.sloth | 2 | ||||
| -rw-r--r-- | std/stdlib.c | 23 | ||||
| -rw-r--r-- | std/stdlib.sloth | 2 |
5 files changed, 23 insertions, 6 deletions
@@ -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 Binary files differdiff --git a/examples/cgol.sloth b/examples/cgol.sloth index a5b761f..c4d9537 100644 --- a/examples/cgol.sloth +++ b/examples/cgol.sloth @@ -104,7 +104,7 @@ fn main() Int { update(life, new); display(new); life = new; - wait(1.0); + wait(100); } return 0; } diff --git a/std/stdlib.c b/std/stdlib.c index b70f5b7..dcb7ec3 100644 --- a/std/stdlib.c +++ b/std/stdlib.c @@ -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) { diff --git a/std/stdlib.sloth b/std/stdlib.sloth index eb6000d..ea57e45 100644 --- a/std/stdlib.sloth +++ b/std/stdlib.sloth @@ -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; |
