Skip to content

Commit

Permalink
improve time tests, kinda
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrk24 committed Nov 25, 2023
1 parent 09f64f3 commit 586162a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/lightweight_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/invalid_flags/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -u

errors="$($TRILANGLE - 2>&1 1<&-)"
errors=$($TRILANGLE - 2>&1 1<&-)
result=$?
set -e
test 0 -ne $result
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/time/date.trg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
D
! @
19 changes: 19 additions & 0 deletions tests/cli/time/index.sh
Original file line number Diff line number Diff line change
@@ -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")"
2 changes: 2 additions & 0 deletions tests/cli/time/time.trg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T
! @
1 change: 1 addition & 0 deletions tests/compiler/time

0 comments on commit 586162a

Please sign in to comment.