Skip to content

Commit 56dbdf8

Browse files
committed
Bigger demo + quickfix for PSeq
1 parent 6528bdf commit 56dbdf8

File tree

6 files changed

+220
-5
lines changed

6 files changed

+220
-5
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CoqMakefile.conf
1717
.direnv
1818
result
1919

20-
test/*.txt
21-
test/*.v
22-
test/*.glob
20+
*.txt
21+
*.ast
22+
*.v
23+
*.glob

agda2lambox.agda-lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
name: agda2lambox
2+
depend: standard-library
23
include: test
34
flags: --no-projection-like

src/Agda2Lambox/Compile/Term.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import Agda.Syntax.Builtin ( builtinNat, builtinZero, builtinSuc )
1919
import Agda.Syntax.Common ( Erased(..) )
2020
import Agda.Syntax.Common.Pretty
2121
import Agda.Syntax.Literal
22-
import Agda.Syntax.Treeless ( TTerm(..), TAlt(..), CaseInfo(..), CaseType(..) )
22+
import Agda.Syntax.Treeless
23+
( TTerm(..), TAlt(..), CaseInfo(..), CaseType(..), TPrim(..) )
2324
import Agda.TypeChecking.Datatypes ( getConstructorData, getConstructors )
2425
import Agda.TypeChecking.Monad.Base ( TCM , liftTCM, MonadTCEnv, MonadTCM )
2526
import Agda.TypeChecking.Monad.Builtin ( getBuiltinName_ )
@@ -89,7 +90,7 @@ compileTermC = \case
8990
if n < bound then pure $ LRel n
9091
else pure $ LBox -- a type variable
9192

92-
TPrim p -> genericError "primitives not supported"
93+
TPrim p -> genericError $ "primitives not supported: " <> show p
9394

9495
-- NOTE(flupe):
9596
-- Assumption:
@@ -108,6 +109,9 @@ compileTermC = \case
108109
lift $ requireDef q
109110
liftTCM $ toConApp q []
110111

112+
-- TODO: maybe not ignore seq? (c.f. issue #12)
113+
TApp (TPrim PSeq) args -> compileTermC (last args)
114+
111115
TApp (TCon q) args -> do
112116
lift $ requireDef q
113117
traverse compileTermC args

test/BigDemo.agda

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
module _ where
2+
3+
-- - decision procedure (barebones)
4+
module BAREBONES where
5+
open import Agda.Primitive using (Level)
6+
open import Agda.Builtin.Bool using (Bool; true; false)
7+
open import Agda.Builtin.Nat using (Nat; zero; suc)
8+
open import Agda.Builtin.Equality using (_≡_; refl)
9+
10+
private variable
11+
: Level
12+
A B : Set
13+
x y : Nat
14+
15+
data ⊥ : Set where
16+
17+
¬_ : Set Set
18+
¬ A = A
19+
20+
data Dec (A : Set) : Set where
21+
yes : A Dec A
22+
no : ¬ A Dec A
23+
24+
isYes : Dec A Bool
25+
isYes = λ where
26+
(yes _) true
27+
(no _) false
28+
29+
record HasDec (A : Set) : Set where
30+
field dec : Dec A
31+
open HasDec ⦃...⦄
32+
33+
cong : (f : A B) {x y} x ≡ y f x ≡ f y
34+
cong _ refl = refl
35+
36+
instance
37+
HasDecEq-Nat : HasDec (x ≡ y)
38+
HasDecEq-Nat {x}{y} .dec with x | y
39+
... | zero | zero = yes refl
40+
... | zero | suc n = no λ ()
41+
... | suc m | zero = no λ ()
42+
... | suc m | suc n with dec
43+
... | yes eq = yes (cong suc eq)
44+
... | no m≢n = no λ where refl m≢n refl
45+
46+
test : Bool
47+
test = isYes (dec {A = 4242})
48+
-- {-# COMPILE AGDA2LAMBOX test #-}
49+
50+
-- - decision procedure (importing stdlib)
51+
module STDLIB where
52+
open import Relation.Nullary using (isYes)
53+
54+
open import Data.Bool using (Bool; true; false)
55+
open import Data.Bool.Properties using (_≟_)
56+
test : Bool
57+
test = isYes (true ≟ false)
58+
-- {-# COMPILE AGDA2LAMBOX test #-}
59+
60+
-- open import Data.Bool using (Bool)
61+
-- open import Data.Nat.Properties using (_≟_)
62+
-- test : Bool
63+
-- test = isYes (42 ≟ 42)
64+
-- {-# COMPILE AGDA2LAMBOX test #-}
65+
66+
-- - sort
67+
module SORT where
68+
open import Data.List.Base using (List; _∷_; [])
69+
70+
open import Data.Bool.Properties using (≤-decTotalOrder)
71+
open import Data.Bool using (Bool; true; false)
72+
open import Data.List.Sort ≤-decTotalOrder using (sort)
73+
test : List Bool
74+
test = sort (true ∷ false ∷ true ∷ false ∷ [])
75+
{-# COMPILE AGDA2LAMBOX test #-}
76+
77+
-- open import Data.Nat.Properties using (≤-decTotalOrder)
78+
-- open import Data.Bool using (Bool; true; false)
79+
-- open import Data.List.Base using (List; _∷_; [])
80+
-- open import Data.List.Sort ≤-decTotalOrder using (sort)
81+
-- test : List Bool
82+
-- test = sort (42 ∷ 0 ∷ 5 ∷ 3 ∷ [])
83+
-- {-# COMPILE AGDA2LAMBOX test #-}

test/Equality.agda

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
open import Agda.Primitive using (Level; lzero)
2+
open import Agda.Builtin.Nat using (Nat; zero; suc)
3+
4+
infix 4 _≡_
5+
data _≡_ {A : Set} (x : A) : A Set where
6+
instance refl : x ≡ x
7+
8+
private variable : Level
9+
10+
eqzero : 00
11+
eqzero = refl
12+
13+
private variable A B C : Set
14+
15+
cong : {a b : A} (f : A B) a ≡ b f a ≡ f b
16+
cong f refl = refl
17+
18+
EqNat = _≡_ {A = Nat}
19+
20+
eqOne : EqNat 1 1
21+
eqOne = cong suc eqzero
22+
23+
sym : {a b : A} a ≡ b b ≡ a
24+
sym refl = refl
25+
26+
infixr 9 _∘_
27+
infixr -1 _$_
28+
29+
_∘_ : (B C) (A B) (A C)
30+
(f ∘ g) x = f (g x)
31+
32+
_$_ : (A B) A B
33+
f $ x = f x
34+
35+
eqTwo : EqNat 2 2
36+
eqTwo = sym $ cong (suc ∘ suc) eqzero
37+
38+
trans : {a b c : A} a ≡ b b ≡ c a ≡ c
39+
trans refl refl = refl
40+
41+
subst : {P : A Set} {a b : A} a ≡ b P a P b
42+
subst refl p = p
43+
44+
add : Nat Nat Nat
45+
add zero y = y
46+
add (suc x) y = suc (add x y)
47+
48+
add-left-id : (a : Nat) EqNat (add zero a) a
49+
add-left-id zero = refl
50+
add-left-id (suc a) = cong suc $ add-left-id a
51+
52+
suc-left-add : (a b : Nat) add (suc a) b ≡ suc (add a b)
53+
suc-left-add a zero = refl
54+
suc-left-add a (suc b) = refl
55+
56+
eqLevel : lzero ≡ lzero
57+
eqLevel = refl
58+
59+
toNat : {x y : Nat} x ≡ y Nat
60+
toNat {x = x} {y = .x} refl = x
61+
62+
test : Nat
63+
test = toNat $ suc-left-add 1 0
64+
{-# COMPILE AGDA2LAMBOX test #-}

test/Levels.agda

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
-- {-# OPTIONS --level-universe #-}
2+
open import Agda.Builtin.Nat using (Nat; suc)
3+
4+
open import Agda.Primitive
5+
6+
-- ** level definitions should be ignored
7+
0ℓ : Level
8+
0ℓ = lzero
9+
10+
mkLevel : Nat Level
11+
mkLevel 0 = 0ℓ
12+
mkLevel (suc n) = lsuc (mkLevel n)
13+
14+
-- ** level function arguments should be erased
15+
testLevel : Level Nat
16+
testLevel _ = 42
17+
18+
-- ** level application arguments should be erased
19+
testMkLevel : Nat
20+
testMkLevel = testLevel (mkLevel 42)
21+
{-# COMPILE AGDA2LAMBOX testMkLevel #-}
22+
23+
-- ** level record fields should be erased
24+
record SomeLvl : Set where
25+
constructor this
26+
field ℓ : Level
27+
open SomeLvl public
28+
29+
someLvl : SomeLvl
30+
someLvl = this 0ℓ
31+
32+
lvlToNat : Level Nat
33+
lvlToNat _ = 42
34+
35+
testSomeLvl : Nat
36+
testSomeLvl = lvlToNat (someLvl .ℓ)
37+
{-# COMPILE AGDA2LAMBOX testSomeLvl #-}
38+
39+
constLvl : {A : Set} A Level A
40+
constLvl x _ = x
41+
42+
testConstLvl : Nat
43+
testConstLvl = constLvl 42 (someLvl .ℓ)
44+
{-# COMPILE AGDA2LAMBOX testConstLvl #-}
45+
46+
const : {A B : Set} A B A
47+
const x _ = x
48+
49+
testConst : Nat
50+
testConst = const 42 0
51+
{-# COMPILE AGDA2LAMBOX testConst #-}
52+
53+
testConstLvl2 : Nat
54+
testConstLvl2 = const 42 (someLvl .ℓ)
55+
{-# COMPILE AGDA2LAMBOX testConstLvl2 #-}
56+
57+
testWhere : Nat
58+
testWhere = toNat (someLvl .ℓ)
59+
where
60+
toNat : Level Nat
61+
toNat _ = 42
62+
{-# COMPILE AGDA2LAMBOX testWhere #-}

0 commit comments

Comments
 (0)