Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ html: test

clean:
rm -rf test/Tests.agda test/dist/
make -C test clean

%.ast:
agda2lambox -o build test/$*.agda
Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
html/
gen/
_build/
Tests.agda
30 changes: 17 additions & 13 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
13 changes: 10 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# 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
./renderTranslations.sh
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
33 changes: 33 additions & 0 deletions test/compile.sh
Original file line number Diff line number Diff line change
@@ -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!"
57 changes: 47 additions & 10 deletions test/renderTranslations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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##*.}
Expand All @@ -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

Expand All @@ -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)" && \
Expand All @@ -50,20 +62,45 @@ for f in $BUILD_DIR/**/**.txt; do
newHtml="\
<div class=\"split right\">\
<div class=\"tabs\">\
<span data-tab-value=\"#tab_1\">Debug</span>\
<span data-tab-value=\"#tab_2\">λ\&\#9744;</span>\
<span data-tab-value=\"#tab_3\">Rocq</span>\
<span data-tab-value=\"#in_1\">Debug</span>\
<span data-tab-value=\"#in_2\">λ\&\#9744;</span>\
<span data-tab-value=\"#in_3\">Rocq</span>\
<div style=\"font-size:50px;\">\&nbsp; ↪ \&nbsp;</div>\
<span data-tab-value=\"#out_1\">WASM</span>\
<span data-tab-value=\"#out_2\">C</span>\
<span data-tab-value=\"#out_3\">OCaml</span>\
<span data-tab-value=\"#out_4\">CakeML</span>\
<span data-tab-value=\"#out_5\">Rust</span>\
<span data-tab-value=\"#out_6\">Elm</span>\
</div>\
<div class=\"tab-content\">\
<div class=\"tabs__tab active\" id=\"tab_1\" data-tab-info>\
<div class=\"tabs__tab active\" id=\"in_1\" data-tab-info>\
<embed src=\"$fTxt.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"tab_2\" data-tab-info>\
<div class=\"tabs__tab\" id=\"in_2\" data-tab-info>\
<embed src=\"$fAst.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"tab_3\" data-tab-info>\
<div class=\"tabs__tab\" id=\"in_3\" data-tab-info>\
<embed src=\"$fCoq.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_1\" data-tab-info>\
<embed src=\"$fWasm.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_2\" data-tab-info>\
<embed src=\"$fC.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_3\" data-tab-info>\
<embed src=\"$fOcaml.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_4\" data-tab-info>\
<embed src=\"$fCakeml.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_5\" data-tab-info>\
<embed src=\"$fRust.html\"/>\
</div>\
<div class=\"tabs__tab\" id=\"out_6\" data-tab-info>\
<embed src=\"$fElm.html\"/>\
</div>\
</div>\
</div>\
<script type="text/javascript">\
Expand Down
10 changes: 10 additions & 0 deletions test/typed/Scheme.agda
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ Vec A n = [ xs ∈ List A ∣ Eq (length xs) n ]
Bad : Bool → Set
Bad false = Nat
Bad true = Bool

testVec : Vec Nat 1
testVec = (42 ∷ []) , rfl

head : ∀ {A n} → Vec A (suc n) → A
head ((x ∷ _) , _) = x

test : Bad false
test = head testVec
{-# COMPILE AGDA2LAMBOX test #-}
7 changes: 7 additions & 0 deletions test/typed/Test.agda
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ fromMaybe def = λ where
nothing → def
(just a) → a

open import Agda.Builtin.Nat

test : Nat
test = fromMaybe 0 (just 42)
{-# COMPILE AGDA2LAMBOX test #-}


{-
open import Agda.Builtin.Nat using (Nat; _+_; _*_)

Expand Down
26 changes: 19 additions & 7 deletions test/typed/Types.agda
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
open import Agda.Builtin.Nat
open import Agda.Builtin.List

record sig (A : Set) (P : A → Prop) : Set where
constructor exist
field
fst : A
snd : P fst

listrect
: {A : Set} (P : List A → Set)
: {A : Set} (P : List A → Set)
→ P []
→ (∀ x xs → P xs → P (x ∷ xs))
→ ∀ xs → P xs
Expand All @@ -21,3 +15,21 @@ listrect P pnil pcons (x ∷ xs) = pcons x xs (listrect P pnil pcons xs)

map : {A B : Set} → (A → B) → List A → List B
map f = listrect _ [] λ x _ ys → f x ∷ ys

head : List Nat → Nat
head [] = 0
head (n ∷ _) = n

record sig (A : Set) (P : A → Prop) : Set where
constructor exist
field
fst : A
snd : P fst

data Top : Prop where
tt : Top

test : Nat
test = head (map (λ (x : sig Nat (λ _ → Top)) → suc (x .sig.fst))
(exist 41 tt ∷ exist 0 tt ∷ []))
{-# COMPILE AGDA2LAMBOX test #-}
6 changes: 3 additions & 3 deletions test/untyped/Exports.agda
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ record Exports : Set where
efour : Nat → Nat → Nat
open Exports

main : Exports
main = record
test : Exports
test = record
{ eone = one
; etwo = two
; ethree = three
; efour = four
}
{-# COMPILE AGDA2LAMBOX main #-}
{-# COMPILE AGDA2LAMBOX test #-}
6 changes: 3 additions & 3 deletions test/untyped/Hello.agda
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ open import Agda.Builtin.List
String : Set
String = List Nat

hello : String
hello = 72 ∷ 101 ∷ 108 ∷ 108 ∷ 111 ∷ 33 ∷ []
{-# COMPILE AGDA2LAMBOX hello #-}
test : String
test = 72 ∷ 101 ∷ 108 ∷ 108 ∷ 111 ∷ 33 ∷ []
{-# COMPILE AGDA2LAMBOX test #-}
9 changes: 3 additions & 6 deletions test/untyped/Imports.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Nat

test : List Bool
test = true ∷ false ∷ []

map : {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs

test2 : List Nat
test2 = map (5 +_) (1 ∷ [])
{-# COMPILE AGDA2LAMBOX test2 #-}
test : List Nat
test = map (5 +_) (1 ∷ [])
{-# COMPILE AGDA2LAMBOX test #-}
7 changes: 3 additions & 4 deletions test/untyped/Input.agda
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ record Export : Set where
nt : Bool → Bool
open Export public

main : Export
main = record
test : Export
test = record
{ ad = and
; nt = not
}
{-# COMPILE AGDA2LAMBOX main #-}

{-# COMPILE AGDA2LAMBOX test #-}
6 changes: 3 additions & 3 deletions test/untyped/Irr.agda
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ map f (x ∷ xs) = f x ∷ map f xs
xs : Vec Nat 2
xs = 1 ∷ 0 ∷ []

ys : Vec Nat 2
ys = map suc xs
{-# COMPILE AGDA2LAMBOX ys #-}
test : Vec Nat 2
test = map suc xs
{-# COMPILE AGDA2LAMBOX test #-}
Loading