@@ -21,6 +21,10 @@ inductive SSAConst where
2121| loop (ty : SSABaseType) : SSAConst
2222| prod (α β : SSAType) : SSAConst
2323| ifthenelse (ty : SSAType) : SSAConst
24+ /-prop stuff-/
25+ | eq (ty : SSABaseType) : SSAConst
26+ | and : SSAConst
27+ | or: SSAConst
2428
2529inductive SSAExpr where
2630| const : SSAConst → SSAExpr
@@ -76,6 +80,9 @@ def SSAConst.inferType : SSAConst → SSAType
7680| loop ty => .fun (.ofBase ty) (.fun (.fun (.ofBase ty) (.prod (.ofBase ty) (.ofBase .int))) (.ofBase ty))-- ((x, 1) denotes break anything else denotes continue) todo :: adapt loop to use ForInStep and be inline with Lean.Loop
7781| prod α β => .fun α (.fun β (.prod α β))
7882| ifthenelse ty => .fun (.ofBase .int) (.fun ty (.fun ty ty))
83+ | eq ty => .fun (.ofBase ty) (.fun (.ofBase ty) (.ofBase .int))
84+ | and => .fun (.ofBase .int) (.fun (.ofBase .int) (.ofBase .int))
85+ | or => .fun (.ofBase .int) (.fun (.ofBase .int) (.ofBase .int))
7986
8087/-
8188 none is returned the input expr doesn't typecheck
@@ -130,6 +137,8 @@ theorem Array.find?_eq_getElem_findFinIdx? {α : Type u} (xs : Array α) (p : α
130137-- (a : α, true) means break (a : α, false) means continue
131138def SSA.loop {α : Type u} [Inhabited α] (init : α) (step : α → α × Bool) : α := sorry
132139
140+ instance (ty : SSABaseType) : DecidableEq (SSAType.ofBase ty).type := sorry
141+
133142private def SSABaseType.inhabit : (ty : SSABaseType) → ty.type
134143| int => (0 : Int)
135144| float => (0 : Float)
@@ -148,6 +157,9 @@ def SSAConst.interp : (e : SSAConst) → (e.inferType).type
148157| ifthenelse ty => fun c t e => if (cast (by simp [SSAType.type, SSABaseType.type]) c : Int) != 0 then t else e
149158| loop ty => fun init => fun step => SSA.loop (α := (SSAType.ofBase ty).type) init (fun x => let (a, b) := step x; (a, cast (β := Int) (by simp [SSAType.type, SSABaseType.type]) b == 1 ))
150159| prod α β => (@Prod.mk α.type β.type)
160+ | eq ty => fun t₁ t₂ => if t₁ = t₂ then (1 :Int) else (0 :Int)
161+ | or => fun x y => if x != (0 : Int) || y != (0 :Int) then (1 :Int) else (0 :Int)
162+ | and => fun x y => if x != (0 : Int) && y != (0 : Int) then (1 : Int) else (0 : Int)
151163
152164def SSAExpr.interp (vars : VarMap) : (e : SSAExpr) → (he : e.inferType vars |>.isSome) → DVector (Array.toList (vars.map (·.2 .type))) → (Option.get (e.inferType vars) he).type
153165| .const base, he, _ => base.interp
0 commit comments