From 4ce27094d6c9b2cc946c32884a610692753f05e5 Mon Sep 17 00:00:00 2001 From: Moshe Zadka Date: Sat, 21 Feb 2026 05:06:01 +0000 Subject: [PATCH] Implement timer package with promise-based timers and process exit Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/check.yml | 43 +++++++++++++++++++++++++++++++++++++ .gitignore | 10 +++++++-- README.md | 4 ---- src/lib.bats | 25 +++++++++++++++++++-- 4 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..9188746 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,43 @@ +name: check + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install ATS2 + run: | + curl -sL "https://raw.githubusercontent.com/ats-lang/ats-lang.github.io/master/FROZEN000/ATS-Postiats/ATS2-Postiats-int-0.4.2.tgz" -o /tmp/ats2.tgz + mkdir -p ~/.ats2 + tar -xzf /tmp/ats2.tgz -C ~/.ats2 + cd ~/.ats2/ATS2-Postiats-int-0.4.2 + make -j$(nproc) -C src/CBOOT patsopt + mkdir -p bin + cp src/CBOOT/patsopt bin/patsopt + + - name: Cache bats toolchain + id: cache-bats + uses: actions/cache@v4 + with: + path: ~/bats-toolchain + key: bats-${{ runner.os }}-${{ hashFiles('.github/workflows/check.yml') }} + + - name: Build bats + if: steps.cache-bats.outputs.cache-hit != 'true' + run: | + git clone https://github.com/bats-lang/bats.git ~/bats-toolchain + cd ~/bats-toolchain + cargo build --release + + - name: bats check + run: | + git clone https://github.com/bats-lang/repository-prototype.git ~/repository + ~/bats-toolchain/target/release/bats lock --repository ~/repository + ~/bats-toolchain/target/release/bats check --repository ~/repository diff --git a/.gitignore b/.gitignore index 5da69c6..ad2d364 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ -build/ -dist/ +*.sats +*.dats +*_dats.c +*.o +debug/ +release/ +_bats_* bats_modules/ +bats.lock diff --git a/README.md b/README.md index 5c87e8d..f0e4878 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,3 @@ $T.exit() : void `set` returns a promise that resolves when the host fires the timer. The resolved value is an integer status (typically 0). - -## Dependencies - -- **promise** diff --git a/src/lib.bats b/src/lib.bats index 272cecb..e0aa00b 100644 --- a/src/lib.bats +++ b/src/lib.bats @@ -1,3 +1,24 @@ -#pub fun hello(): void +(* timer -- promise-based timers and process control *) -implement hello () = println! ("hello from library") +#include "share/atspre_staload.hats" + +#use promise as P +#use wasm.bats-packages.dev/bridge as B + +#pub fun set + (delay_ms: int): $P.promise(int, $P.Pending) + +#pub fun exit(): void + +implement set(delay_ms) = let + val @(p, r) = $P.create() + val id = $P.stash(r) + val () = $B.timer_set(delay_ms, id) +in p end + +implement exit() = $B.exit() + +fn _test_set(): void = let + val p = set(100) + val () = $P.discard(p) +in () end