1
+ {-# OPTIONS --safe --without-K #-}
1
2
------------------------------------------------------------------------
2
3
-- Meta-programming utilities
3
4
------------------------------------------------------------------------
@@ -7,7 +8,7 @@ open import Level hiding (suc)
7
8
open import Function
8
9
9
10
open import Reflection hiding (visibility)
10
- open import Reflection.Term
11
+ open import Reflection.Term hiding (getName)
11
12
import Reflection.Name as Name
12
13
open import Reflection.Pattern
13
14
import Reflection.Abstraction as Abs
@@ -30,8 +31,6 @@ open import Relation.Nullary using (Dec)
30
31
open import Relation.Nullary.Decidable using (⌊_⌋)
31
32
open import Relation.Binary.PropositionalEquality hiding ([_])
32
33
33
- open import Category.Applicative
34
-
35
34
private variable
36
35
ℓ : Level
37
36
A B : Set ℓ
@@ -68,6 +67,9 @@ pattern ⟦_⦅_⦆⇒_⟧ x tel k = clause tel (vArg x ∷ []) k
68
67
pattern ⟦_∣_⇒_⟧ x y k = clause [] (vArg x ∷ vArg y ∷ []) k
69
68
pattern ⟦_∣_⦅_⦆⇒_⟧ x y tel k = clause tel (vArg x ∷ vArg y ∷ []) k
70
69
70
+ pattern ⟦_∣_∣_⇒_⟧ x y z k = Clause.clause [] (vArg x ∷ vArg y ∷ vArg z ∷ []) k
71
+ pattern ⟦_∣_∣_⦅_⦆⇒_⟧ x y z tel k = Clause.clause tel (vArg x ∷ vArg y ∷ vArg z ∷ []) k
72
+
71
73
-- lambdas
72
74
pattern `λ_⇒_ x k = lam visible (abs x k)
73
75
pattern `λ⟦_∣_⇒_⟧ x y k = `λ x ⇒ `λ y ⇒ k
@@ -90,6 +92,7 @@ pattern _∙ n = def n []
90
92
pattern _∙⟦_⟧ n x = def n (vArg x ∷ [])
91
93
pattern _∙⟦_∣_⟧ n x y = def n (vArg x ∷ vArg y ∷ [])
92
94
pattern _∙⟦_∣_∣_⟧ n x y z = def n (vArg x ∷ vArg y ∷ vArg z ∷ [])
95
+ pattern _∙⟦_∣_∣_∣_⟧ n x y z w = def n (vArg x ∷ vArg y ∷ vArg z ∷ vArg w ∷ [])
93
96
94
97
pattern _◆ n = con n []
95
98
pattern _◆⟦_⟧ n x = con n (vArg x ∷ [])
@@ -102,13 +105,51 @@ pattern _◇⟦_∣_⟧ n x y = Pattern.con n (vArg x ∷ vArg y ∷ [])
102
105
-------------------------------------------------
103
106
-- ** Other utilities
104
107
108
+ getName : Abs A → String
109
+ getName (abs s x) = s
110
+
111
+ getVisibility : ∀ {a} {A : Set a} → Arg A → Visibility
112
+ getVisibility (arg (arg-info v _) _) = v
113
+
114
+ findMetas : Term → List Term
115
+ findMetas' : List (Arg Term) → List Term
116
+ findMetasCl : List Clause → List Term
117
+
118
+ findMetas (var x args) = findMetas' args
119
+ findMetas (con c args) = findMetas' args
120
+ findMetas (def f args) = findMetas' args
121
+ findMetas (lam v (abs _ x)) = findMetas x
122
+ findMetas (pat-lam cs args) = findMetasCl cs Data.List.++ findMetas' args
123
+ findMetas (pi (arg _ a) (abs _ b)) = findMetas a Data.List.++ findMetas b
124
+ findMetas (agda-sort s) = []
125
+ findMetas (lit l) = []
126
+ findMetas m@(meta x args) = m ∷ findMetas' args
127
+ findMetas unknown = []
128
+
129
+ findMetas' [] = []
130
+ findMetas' ((arg _ t) ∷ ts) = findMetas t Data.List.++ findMetas' ts
131
+
132
+ findMetasCl [] = []
133
+ findMetasCl (Clause.clause tel ps t ∷ c) = findMetas t Data.List.++ findMetasCl c
134
+ findMetasCl (Clause.absurd-clause tel ps ∷ c) = findMetasCl c
135
+
136
+ isMeta : Term → Bool
137
+ isMeta (meta _ _) = true
138
+ isMeta _ = false
139
+
140
+ UnquoteDecl : Set
141
+ UnquoteDecl = TC ⊤
142
+
105
143
unArgs : Args A → List A
106
144
unArgs = map unArg
107
145
108
- {-# TERMINATING #-}
109
146
mapVariables : (ℕ → ℕ) → (Pattern → Pattern)
110
147
mapVariables f (Pattern.var n) = Pattern.var (f n)
111
- mapVariables f (Pattern.con c args) = Pattern.con c $ map (λ { (arg i p) → arg i (mapVariables f p) }) args
148
+ mapVariables f (Pattern.con c args) = Pattern.con c $ mapVariables′ args
149
+ where
150
+ mapVariables′ : List (Arg Pattern) → List (Arg Pattern)
151
+ mapVariables′ [] = []
152
+ mapVariables′ (arg i p ∷ l) = arg i (mapVariables f p) ∷ mapVariables′ l
112
153
mapVariables _ p = p
113
154
114
155
-- alternative view of function types as a pair of a list of arguments and a return type
0 commit comments