@@ -11,6 +11,7 @@ inductive SPattern
1111 | ref : Global → Array Local → SPattern
1212 | tuple : Array Local → SPattern
1313 | array : Array Local → SPattern
14+ | pointer : Local → SPattern
1415 deriving BEq, Hashable, Inhabited
1516
1617structure Clause where
@@ -76,6 +77,12 @@ def dnfProd (branches: List $ Pattern × UniqTerm) (body : ExtTerm) : CompilerM
7677 let (vars, guards) ← flattenArgs args.toArray
7778 let clause := ⟨.ref global vars, guards, term⟩
7879 aux renames (clauses.push clause) rest body
80+ | (.pointer arg, term) :: rest => do
81+ let id ← newId
82+ let var := .idx id
83+ let guards := #[(arg, (id, .var var))]
84+ let clause := ⟨.pointer var, guards, term⟩
85+ aux renames (clauses.push clause) rest body
7986 aux Array.empty Array.empty branches body
8087where
8188 flattenArgs args := do
@@ -98,6 +105,7 @@ def patTypeLength (decls : Decls) : SPattern → Nat
98105 | .tuple _ => 1
99106 | .array _ => 1
100107 | .ref global _ => typeLookup global |>.constructors.length
108+ | .pointer _ => 1
101109where
102110 typeLookup (global : Global) :=
103111 match global.popNamespace with
@@ -200,6 +208,8 @@ def spatternToPattern : SPattern → Pattern
200208 | .ref global vars => .ref global (vars.map .var).toList
201209 | .tuple vars => .tuple (vars.map .var)
202210 | .array vars => .array (vars.map .var)
211+ -- pointer patterns are unique and will be converted into a load operation before this function is called
212+ | .pointer _ => unreachable!
203213
204214mutual
205215
@@ -214,6 +224,9 @@ partial def branchesToTerm (branches : List (SPattern × Decision)) (dec : Decis
214224partial def decisionToTerm : Decision → Option Term
215225 | .success ⟨renames, value⟩ =>
216226 some $ renames.foldr (init := value) fun (x, y) acc => .let (.var x) y acc
227+ | .switch ptr [(.pointer val, body)] _ => do
228+ let body' ← decisionToTerm body
229+ some $ .let (.var val) (.load (.var ptr)) body'
217230 | .switch var branches dec => some $ .match (.var var) (branchesToTerm branches dec)
218231 | .let var term body => do
219232 let body' ← decisionToTerm body
0 commit comments