diff --git a/.gitignore b/.gitignore index deaa35b..f75b1c0 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ sync_report*.txt # Allow the brand shim binary (a shell script, not a compiled artefact) !bin/ !bin/* + +# Pinned AffineScript compiler (scripts/install-affinescript.sh) +/.affinescript/ diff --git a/Justfile b/Justfile index 78547e2..1fc55e5 100644 --- a/Justfile +++ b/Justfile @@ -584,16 +584,25 @@ verify: # BUILD & COMPILE # ═══════════════════════════════════════════════════════════════════════════════ -# Build the project (debug mode) +# Build the pinned AffineScript compiler into .affinescript/ (once) +setup-compiler: + scripts/install-affinescript.sh + +# Compile every PseudoScript example to typed-wasm under out/ build *args: - @echo "Building {{project}} (debug)..." - # TODO: Replace with your build command - # Examples: - # cargo build {{args}} # Rust - # mix compile {{args}} # Elixir - # zig build {{args}} # Zig - # deno task build {{args}} # Deno/ReScript - @echo "Build complete" + #!/usr/bin/env bash + set -euo pipefail + shopt -s nullglob + files=(examples/*.affine) + [ ${#files[@]} -gt 0 ] || { echo "no examples/*.affine to build" >&2; exit 1; } + mkdir -p out + for f in "${files[@]}"; do + scripts/affinescript.sh compile --face pseudo "$f" -o "out/$(basename "$f" .affine).wasm" "$@" + done + +# Compile one file to typed-wasm +build-file FILE OUT="out.wasm": + scripts/affinescript.sh compile --face pseudo {{quote(FILE)}} -o {{quote(OUT)}} # Build in release mode with optimizations build-release *args: @@ -628,16 +637,26 @@ clean-all: clean # TEST & QUALITY # ═══════════════════════════════════════════════════════════════════════════════ -# Run all tests +# Type-check every PseudoScript example, then build them all test *args: - @echo "Running tests..." - # TODO: Replace with your test command - # Examples: - # cargo test {{args}} - # mix test {{args}} - # zig build test {{args}} - # deno test {{args}} - @echo "Tests passed!" + #!/usr/bin/env bash + set -euo pipefail + shopt -s nullglob + files=(examples/*.affine) + [ ${#files[@]} -gt 0 ] || { echo "no examples/*.affine to test" >&2; exit 1; } + for f in "${files[@]}"; do + scripts/affinescript.sh check --face pseudo "$f" "$@" + done + just build + echo "${#files[@]} example(s) checked and built" + +# Type-check one file +check FILE: + scripts/affinescript.sh check --face pseudo {{quote(FILE)}} + +# Show the canonical lowering of a file (debug) +preview FILE: + scripts/affinescript.sh preview-pseudocode {{quote(FILE)}} # Run tests with verbose output test-verbose: @@ -748,22 +767,19 @@ fmt-check: # gleam format --check # Run linter +# Lint every PseudoScript example lint: - @echo "Linting source files..." - # TODO: Replace with your linter - # Examples: - # cargo clippy -- -D warnings - # mix credo --strict - # gleam check + #!/usr/bin/env bash + set -euo pipefail + for f in examples/*.affine; do scripts/affinescript.sh lint --face pseudo "$f"; done # ═══════════════════════════════════════════════════════════════════════════════ # RUN & EXECUTE # ═══════════════════════════════════════════════════════════════════════════════ -# Run the application -run *args: build - # TODO: Replace with your run command - echo "Run not configured yet" +# Evaluate a file with the interpreter +run FILE: + scripts/affinescript.sh eval --face pseudo {{quote(FILE)}} # Run with verbose output run-verbose *args: build diff --git a/justfile b/justfile deleted file mode 100644 index eca5c03..0000000 --- a/justfile +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: MPL-2.0 -# SPDX-FileCopyrightText: 2024-2026 Jonathan D.A. Jewell (hyperpolymath) -# justfile — PseudoScript task runner - -default: - @just --list - -# Type-check a file -check FILE: - affinescript check --face pseudo {{FILE}} - -# Evaluate a file with the interpreter -run FILE: - affinescript eval --face pseudo {{FILE}} - -# Compile to typed-wasm -build FILE OUT="out.wasm": - affinescript compile --face pseudo {{FILE}} -o {{OUT}} - -# Show the canonical lowering of a file (debug) -preview FILE: - affinescript preview-pseudocode {{FILE}} - -# Lint a file -lint FILE: - affinescript lint --face pseudo {{FILE}} - -# Smoke-test the hello example -hello: (run "examples/hello.affine") diff --git a/scripts/affinescript.sh b/scripts/affinescript.sh new file mode 100755 index 0000000..404de4e --- /dev/null +++ b/scripts/affinescript.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# +# Run the AffineScript compiler. +# Compiler: $AFFINESCRIPT if set, else the pinned build from +# scripts/install-affinescript.sh, else `affinescript` on PATH. +set -euo pipefail + +root=$(cd "$(dirname "$0")/.." && pwd) +pinned="$root/.affinescript/compiler" + +compiler="" +if [ -z "${AFFINESCRIPT:-}" ]; then + if [ -x "$pinned/_build/default/bin/main.exe" ]; then + compiler="$pinned/_build/default/bin/main.exe" + elif command -v affinescript >/dev/null 2>&1; then + compiler=affinescript + else + echo "affinescript not found. Run 'just setup-compiler' (scripts/install-affinescript.sh) first." >&2 + exit 127 + fi +fi +if [ -z "${AFFINESCRIPT_STDLIB:-}" ] && [ -d "$pinned/stdlib" ]; then + export AFFINESCRIPT_STDLIB="$pinned/stdlib" +fi + +# A path chosen here is one word, even if the checkout path has spaces. +if [ -n "$compiler" ]; then + exec "$compiler" "$@" +fi +# shellcheck disable=SC2086 # a user-set AFFINESCRIPT may be a multi-word command +exec $AFFINESCRIPT "$@" diff --git a/scripts/install-affinescript.sh b/scripts/install-affinescript.sh new file mode 100755 index 0000000..a3e967a --- /dev/null +++ b/scripts/install-affinescript.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# +# Build the pinned AffineScript compiler into .affinescript/compiler. +# scripts/affinescript.sh finds it there; nothing is installed globally. +# +# Needs git, OCaml >= 4.14 and dune >= 3.14, plus the compiler's OCaml +# libraries (menhir, sedlex, ppx_deriving, ppx_sexp_conv, sexplib0, fmt, +# cmdliner, yojson, js_of_ocaml, js_of_ocaml-ppx). With opam on PATH the +# script installs those itself; otherwise they must come from the system +# (for example Debian/Ubuntu: ocaml-dune menhir libmenhir-ocaml-dev +# libsedlex-ocaml-dev libppx-deriving-ocaml-dev libppx-sexp-conv-ocaml-dev +# libsexplib0-ocaml-dev libfmt-ocaml-dev libcmdliner-ocaml-dev +# libyojson-ocaml-dev libjs-of-ocaml-dev js-of-ocaml). +set -euo pipefail + +# The only compiler pin. Keep it equal to TOOL_LANE_COMPILER_REF in +# any CI workflow that builds the compiler. +COMPILER_REPO="https://github.com/hyperpolymath/affinescript.git" +COMPILER_REF="4a55253703e13a96a768656a7ed548919c341261" + +root=$(cd "$(dirname "$0")/.." && pwd) +dir="$root/.affinescript/compiler" + +if [ ! -d "$dir/.git" ]; then + mkdir -p "$(dirname "$dir")" + git clone --quiet "$COMPILER_REPO" "$dir" +fi +git -C "$dir" fetch --quiet origin "$COMPILER_REF" 2>/dev/null || git -C "$dir" fetch --quiet origin +git -C "$dir" checkout --quiet --detach "$COMPILER_REF" + +cd "$dir" +if command -v opam >/dev/null 2>&1; then + opam install . --deps-only -y + opam exec -- dune build bin/main.exe +else + command -v dune >/dev/null 2>&1 || { + echo "dune not found: install opam, or the system OCaml packages listed at the top of $0" >&2 + exit 1 + } + dune build bin/main.exe +fi +"$dir/_build/default/bin/main.exe" --version +echo "AffineScript compiler ready at $dir (pin $COMPILER_REF)"