diff --git a/README.md b/README.md index cad6f99..c3b9931 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ When using the `-c` flag, the input program will be translated into C code. The If the `-a` flag is additionally specified, the output program will use `getchar` and `putchar` for the `GTC` and `PTC` opcodes respectively. Otherwise, the output program will convert between UTF-8 and UTF-32 the same way the interpreter does. -Compiled programs cannot use multiple threads, and at this time cannot use the `RND`, `GTM`, and `GDT` opcodes. +Compiled programs cannot use multiple threads, and at this time cannot use the `RND` opcode. ## Sample programs diff --git a/src/compiler/lightweight_stack.h b/src/compiler/lightweight_stack.h index 08488bd..d096273 100644 --- a/src/compiler/lightweight_stack.h +++ b/src/compiler/lightweight_stack.h @@ -117,9 +117,9 @@ static const time_t SECS_PER_DAY = 86400; static inline int32_t get_time() { struct timespec ts; timespec_get(&ts, TIME_UTC); - const float UNITS_PER_NSEC = 9.709036e-8F; - const float UNITS_PER_SEC = 97.09036F; - float value = UNITS_PER_SEC * (float)(ts.tv_sec % SECS_PER_DAY) + UNITS_PER_NSEC * (float)ts.tv_nsec; + const double UNITS_PER_NSEC = 9.709037037036571e-8; + const double UNITS_PER_SEC = 97.0903703703657; + double value = UNITS_PER_SEC * (double)(ts.tv_sec % SECS_PER_DAY) + UNITS_PER_NSEC * (double)ts.tv_nsec; return (int32_t)value; } diff --git a/tests/cli/invalid_flags/index.sh b/tests/cli/invalid_flags/index.sh index 271819d..7ec3e5a 100755 --- a/tests/cli/invalid_flags/index.sh +++ b/tests/cli/invalid_flags/index.sh @@ -2,7 +2,7 @@ set -u -errors="$($TRILANGLE - 2>&1 1<&-)" +errors=$($TRILANGLE - 2>&1 1<&-) result=$? set -e test 0 -ne $result diff --git a/tests/cli/time/date.trg b/tests/cli/time/date.trg new file mode 100644 index 0000000..8cb3778 --- /dev/null +++ b/tests/cli/time/date.trg @@ -0,0 +1,2 @@ + D +! @ diff --git a/tests/cli/time/index.sh b/tests/cli/time/index.sh new file mode 100755 index 0000000..65e560b --- /dev/null +++ b/tests/cli/time/index.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -eu + +folder=$(dirname "$0") + +time=$($TRILANGLE "${folder}/time.trg") + +# This could be better. +test 0 -le "$time" +test $((0x7fffff)) -ge "$time" + +# To avoid any possible confusion by the reported dates differing, wait if we're close to UTC midnight +if [ 23:59 = "$(date -u +%H:%M)" ] && [ 59 -le "$(date -u +%S)" ] +then + sleep 2 +fi + +test $(($(date -u +%s) / (24 * 60 * 60))) = "$($TRILANGLE "${folder}/date.trg")" diff --git a/tests/cli/time/time.trg b/tests/cli/time/time.trg new file mode 100644 index 0000000..f35fe1b --- /dev/null +++ b/tests/cli/time/time.trg @@ -0,0 +1,2 @@ + T +! @ diff --git a/tests/compiler/time b/tests/compiler/time new file mode 120000 index 0000000..71ef1b8 --- /dev/null +++ b/tests/compiler/time @@ -0,0 +1 @@ +../cli/time \ No newline at end of file