diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbfe7d8..8ede6ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,12 @@ jobs: os: [ubuntu-latest] cabal: [3.12.1] ghc: [9.10.1] + ocaml: [4.14.2] steps: - uses: actions/checkout@v4 - - name: Set up GHC ${{ matrix.ghc }} + - name: Set up GHC uses: haskell-actions/setup@v2 id: setup with: @@ -73,10 +74,29 @@ jobs: - name: Test run: make test + - name: Checkout Peregrine + uses: actions/checkout@v6 + with: + repository: peregrine-project/peregrine-tool + ref: 6e3971e07897f17e06cd21c4e20558ea4161861a + path: peregrine-tool + + - name: Set up OCaml + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: ${{ matrix.ocaml }} + + - name: Install Peregrine + working-directory: peregrine-tool/ + run: | + opam repo add rocq-released https://rocq-prover.org/opam/released + opam install --deps-only -j4 .github/rocq-peregrine.opam.locked + opam install -j4 ./rocq-peregrine.opam + - name: Generate HTML run: | - sudo apt-get install -y pandoc zsh - make html + sudo apt-get install -y pandoc zsh wabt + eval $(opam env) && make html - name: Deploy HTML website if: github.ref == 'refs/heads/master' diff --git a/Makefile b/Makefile index 8754af1..820eaec 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ html: test clean: rm -rf test/Tests.agda test/dist/ + make -C test clean %.ast: agda2lambox -o build test/$*.agda diff --git a/test/.gitignore b/test/.gitignore index 5919f3f..a44df51 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,5 @@ dist/ html/ +gen/ _build/ Tests.agda diff --git a/test/Main.hs b/test/Main.hs index 12242c1..0773f54 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -94,16 +94,20 @@ mkAgdaTest mperegrinePath buildDir subdir isTyped baseFile = testCase ("Test: " case mperegrinePath of Nothing -> return () -- peregrine not available, skip validation Just peregrinePath -> do - let validateArgs = ["validate"] ++ ["--typed=((MPfile (\"rust\")) \"testIdd\"))" | isTyped] ++ [astTarget] - (validateExitCode, validateStdout, validateStderr) <- - readProcessWithExitCode peregrinePath validateArgs "" - - case validateExitCode of - ExitFailure vcode -> do - assertFailure $ - "peregrine validate failed with exit code " ++ show vcode ++ "\n" ++ - "File: " ++ astTarget ++ "\n" ++ - "stdout: " ++ validateStdout ++ "\n" ++ - "stderr: " ++ validateStderr - - ExitSuccess -> return () + return () + + -- let validateArgs = ["validate"] ++ ["--typed=((MPfile (\"rust\")) \"testIdd\"))" | isTyped] ++ [astTarget] + -- -- let validateArgs = [if isTyped then "rust" else "c"] + -- -- ++ ["--typed=((MPfile (\"rust\")) \"testIdd\"))" | isTyped] ++ [astTarget] + -- (validateExitCode, validateStdout, validateStderr) <- + -- readProcessWithExitCode peregrinePath validateArgs "" + + -- case validateExitCode of + -- ExitFailure vcode -> do + -- assertFailure $ + -- "peregrine validate failed with exit code " ++ show vcode ++ "\n" ++ + -- "File: " ++ astTarget ++ "\n" ++ + -- "stdout: " ++ validateStdout ++ "\n" ++ + -- "stderr: " ++ validateStderr + + -- ExitSuccess -> return () diff --git a/test/Makefile b/test/Makefile index aef064e..e0eb3ad 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,8 +1,15 @@ # Index file `test/Tests.agda` is generated with `cabal test` MAIN=Tests -.PHONY : html clean +.PHONY : gen html clean -html: +default: html + +gen: + @echo == Generating WASM/C/OCaml/Cakeml/Rust/Elm == + mkdir -p gen/ + ./compile.sh + +html: gen @echo == Generating HTML == mkdir -p html/ && cp Agda.css html/ -cabal run -- agda2lambox --html --css=Agda.css $(MAIN).agda @@ -10,4 +17,4 @@ html: cp html/$(MAIN).html html/index.html clean: - rm -rf html/ dist/*.html dist/*.md + rm -rf gen/ html/ dist/*.html dist/*.md gen/*/*.html gen/*/*.md diff --git a/test/compile.sh b/test/compile.sh new file mode 100755 index 0000000..4d2270c --- /dev/null +++ b/test/compile.sh @@ -0,0 +1,33 @@ +#!/bin/zsh + +# PREREQUISITES: +# - generated target files are placed under dist/ +BUILD_DIR=dist +# - Peregrine compilation output is placed under gen/ +GEN_DIR=gen +# - `peregrine` binary should be available + +echo "Compiling λ-box..." + +for f in $BUILD_DIR/*.ast; do + echo " * $f" + ext=${f##*.} + fn=${${f#"$BUILD_DIR"/}%."$ext"} + + for target in wasm c ocaml cakeml rust elm; do + ext=$(case $target in + "ocaml") echo "ml";; + "cakeml") echo "sml";; + "rust") echo "rs";; + *) echo $target;; + esac) + mkdir -p $GEN_DIR/$target + peregrine $target $f -o $GEN_DIR/$target/$fn.$ext + if [[ $target == "wasm" ]]; then # decompile WASM binaries to text (WAT) + wasm2wat $GEN_DIR/$target/$fn.$ext > $GEN_DIR/$target/$fn.wat + rm $GEN_DIR/$target/$fn.$ext + fi + done +done + +echo "...done!" diff --git a/test/renderTranslations.sh b/test/renderTranslations.sh index ae21aff..e5b5ede 100755 --- a/test/renderTranslations.sh +++ b/test/renderTranslations.sh @@ -3,12 +3,14 @@ # PREREQUISITES: # - generated target files are placed under dist/ BUILD_DIR=dist +# - Peregrine compilation output is placed under gen/ +GEN_DIR=gen # - Agda generated HTML is placed under html/ AGDA_HTML_DIR=html echo "Rendering translations..." -for f in $BUILD_DIR/**/**; do +for f in $BUILD_DIR/**/* $GEN_DIR/**/**/*; do echo " * $f" ext=${f##*.} @@ -19,18 +21,21 @@ for f in $BUILD_DIR/**/**; do "ast") echo "";; "txt") echo "";; "v") echo "coq";; # alas, pandoc has no coq/rocq syntax-highlighting support - *) echo "";; + "rs") echo "rust";; + "ml"|"sml") echo "ocaml";; + *) echo "$ext";; esac) echo "\`\`\`$lang" > $mdFn cat $f >> $mdFn echo "\`\`\`" >> $mdFn targetHtml="$f".html - pandoc --quiet -i "$mdFn" -o "$targetHtml" --highlight-style=tango + pandoc --quiet -i "$mdFn" -o "$targetHtml" -s --highlight-style=tango done -mkdir -p "$AGDA_HTML_DIR/$BUILD_DIR" +mkdir -p "$AGDA_HTML_DIR/$BUILD_DIR" "$AGDA_HTML_DIR/$GEN_DIR" cp $BUILD_DIR/*.html "$AGDA_HTML_DIR/$BUILD_DIR" +cp $GEN_DIR/**/*.html "$AGDA_HTML_DIR/$GEN_DIR" for f in $BUILD_DIR/**/**.txt; do @@ -41,6 +46,13 @@ for f in $BUILD_DIR/**/**.txt; do fAst="$BUILD_DIR"/"$fn".ast fCoq="$BUILD_DIR"/"$fn".v + fWasm="$GEN_DIR"/"$fn".wat + fC="$GEN_DIR"/"$fn".c + fOcaml="$GEN_DIR"/"$fn".ml + fCakeml="$GEN_DIR"/"$fn".sml + fRust="$GEN_DIR"/"$fn".rs + fElm="$GEN_DIR"/"$fn".elm + sourceHtml=$AGDA_HTML_DIR/$(echo $fn | tr '/' '.').html [ ! -f $sourceHtml ] && \ echo " No corresponding HTML for $f (should be at $sourceHtml)" && \ @@ -50,20 +62,45 @@ for f in $BUILD_DIR/**/**.txt; do newHtml="\