|
@ -38,8 +38,6 @@ import Syntax |
|
|
import System.IO.Unsafe |
|
|
import System.IO.Unsafe |
|
|
|
|
|
|
|
|
import {-# SOURCE #-} Elab.WiredIn |
|
|
import {-# SOURCE #-} Elab.WiredIn |
|
|
import Control.Arrow (second) |
|
|
|
|
|
import Debug.Trace |
|
|
|
|
|
|
|
|
|
|
|
eval :: HasCallStack => Term -> ElabM Value |
|
|
eval :: HasCallStack => Term -> ElabM Value |
|
|
eval t = asks (flip eval' t) |
|
|
eval t = asks (flip eval' t) |
|
@ -179,12 +177,16 @@ eval' e (GlueTy a phi tys f) = glueType (eval' e a) (eval' e phi) (eval' e tys) |
|
|
eval' e (Glue a phi tys eqvs t x) = glueElem (eval' e a) (eval' e phi) (eval' e tys) (eval' e eqvs) (eval' e t) (eval' e x) |
|
|
eval' e (Glue a phi tys eqvs t x) = glueElem (eval' e a) (eval' e phi) (eval' e tys) (eval' e eqvs) (eval' e t) (eval' e x) |
|
|
eval' e (Unglue a phi tys f x) = unglue (eval' e a) (eval' e phi) (eval' e tys) (eval' e f) (eval' e x) |
|
|
eval' e (Unglue a phi tys f x) = unglue (eval' e a) (eval' e phi) (eval' e tys) (eval' e f) (eval' e x) |
|
|
eval' e (Let ns x) = |
|
|
eval' e (Let ns x) = |
|
|
let env' = foldl (\newe (n, ty, x) -> newe { getEnv = Map.insert n (eval' newe ty, eval' newe x) (getEnv newe) }) e ns |
|
|
|
|
|
|
|
|
let env' = foldl (\newe (n, ty, x) -> |
|
|
|
|
|
let nft = eval' newe ty |
|
|
|
|
|
in newe { getEnv = Map.insert n (nft, evalFix' newe n nft x) (getEnv newe) }) |
|
|
|
|
|
e |
|
|
|
|
|
ns |
|
|
in eval' env' x |
|
|
in eval' env' x |
|
|
|
|
|
|
|
|
eval' e (Case range sc xs) = evalCase e (eval' e range @@) (force (eval' e sc)) xs |
|
|
eval' e (Case range sc xs) = evalCase e (eval' e range @@) (force (eval' e sc)) xs |
|
|
|
|
|
|
|
|
evalCase :: ElabEnv -> (Value -> Value) -> Value -> [(Term, Term)] -> Value |
|
|
|
|
|
|
|
|
evalCase :: ElabEnv -> (Value -> Value) -> Value -> [(Term, Int, Term)] -> Value |
|
|
evalCase _ _ sc [] = error $ "unmatched pattern for value: " ++ show (prettyTm (quote sc)) |
|
|
evalCase _ _ sc [] = error $ "unmatched pattern for value: " ++ show (prettyTm (quote sc)) |
|
|
|
|
|
|
|
|
evalCase env rng (VSystem fs) cases = VSystem (fmap (flip (evalCase env rng) cases) fs) |
|
|
evalCase env rng (VSystem fs) cases = VSystem (fmap (flip (evalCase env rng) cases) fs) |
|
@ -195,18 +197,25 @@ evalCase env rng (VHComp a phi u a0) cases = |
|
|
where |
|
|
where |
|
|
v = Elab.WiredIn.fill (fun (const a)) phi u a0 |
|
|
v = Elab.WiredIn.fill (fun (const a)) phi u a0 |
|
|
|
|
|
|
|
|
evalCase env _ sc ((Ref _, k):_) = eval' env k @@ sc |
|
|
|
|
|
|
|
|
evalCase env _ sc ((Ref _, _, k):_) = eval' env k @@ sc |
|
|
|
|
|
|
|
|
evalCase env rng (val@(VNe (HCon _ x) sp)) ((Con x', k):xs) |
|
|
|
|
|
|
|
|
evalCase env rng (val@(VNe (HCon _ x) sp)) ((Con x', _, k):xs) |
|
|
| x == x' = foldl applProj (eval' env k) sp |
|
|
| x == x' = foldl applProj (eval' env k) sp |
|
|
| otherwise = evalCase env rng val xs |
|
|
| otherwise = evalCase env rng val xs |
|
|
|
|
|
|
|
|
evalCase env rng (val@(VNe (HPCon _ _ x) sp)) ((Con x', k):xs) |
|
|
|
|
|
|
|
|
evalCase env rng (val@(VNe (HPCon _ _ x) sp)) ((Con x', _, k):xs) |
|
|
| x == x' = foldl applProj (eval' env k) sp |
|
|
| x == x' = foldl applProj (eval' env k) sp |
|
|
| otherwise = evalCase env rng val xs |
|
|
| otherwise = evalCase env rng val xs |
|
|
|
|
|
|
|
|
evalCase env rng sc xs = VCase (getEnv env) (fun rng) sc xs |
|
|
evalCase env rng sc xs = VCase (getEnv env) (fun rng) sc xs |
|
|
|
|
|
|
|
|
|
|
|
evalFix' :: ElabEnv -> Name -> NFType -> Term -> Value |
|
|
|
|
|
evalFix' env name nft term = fix $ \val -> eval' env{ getEnv = Map.insert name (nft, val) (getEnv env) } term |
|
|
|
|
|
|
|
|
|
|
|
evalFix :: Name -> NFType -> Term -> ElabM Value |
|
|
|
|
|
evalFix name nft term = do |
|
|
|
|
|
t <- ask |
|
|
|
|
|
pure (evalFix' t name nft term) |
|
|
|
|
|
|
|
|
data NotEqual = NotEqual Value Value |
|
|
data NotEqual = NotEqual Value Value |
|
|
deriving (Show, Typeable, Exception) |
|
|
deriving (Show, Typeable, Exception) |
|
@ -294,8 +303,8 @@ unify' topa topb = join $ go <$> forceIO topa <*> forceIO topb where |
|
|
|
|
|
|
|
|
go (VCase _ _ a b) (VCase _ _ a' b') = do |
|
|
go (VCase _ _ a b) (VCase _ _ a' b') = do |
|
|
unify' a a' |
|
|
unify' a a' |
|
|
let go a b = join $ unify' <$> eval (snd a) <*> eval (snd b) |
|
|
|
|
|
zipWithM_ go (sortOn fst b) (sortOn fst b') |
|
|
|
|
|
|
|
|
let go (_, _, a) (_, _, b) = join $ unify' <$> eval a <*> eval b |
|
|
|
|
|
zipWithM_ go (sortOn (\(x, _, _) -> x) b) (sortOn (\(x, _, _) -> x) b') |
|
|
|
|
|
|
|
|
go x y |
|
|
go x y |
|
|
| x == y = pure () |
|
|
| x == y = pure () |
|
@ -596,7 +605,7 @@ vApp p (VSystem fs) arg = VSystem (fmap (flip (vApp p) arg) fs) |
|
|
vApp p (VInc (VPi _ _ (Closure _ r)) phi f) arg = VInc (r (vApp p f arg)) phi (vApp p f arg) |
|
|
vApp p (VInc (VPi _ _ (Closure _ r)) phi f) arg = VInc (r (vApp p f arg)) phi (vApp p f arg) |
|
|
vApp p (VCase env rng sc branches) arg = |
|
|
vApp p (VCase env rng sc branches) arg = |
|
|
VCase env (fun \x -> let VPi _ _ (Closure _ r) = rng @@ x in r arg) sc |
|
|
VCase env (fun \x -> let VPi _ _ (Closure _ r) = rng @@ x in r arg) sc |
|
|
(map (second (projIntoCase (flip (App p) (quote arg)))) branches) |
|
|
|
|
|
|
|
|
(map (projIntoCase (flip (App p) (quote arg))) branches) |
|
|
vApp _ x _ = error $ "can't apply " ++ show (prettyTm (quote x)) |
|
|
vApp _ x _ = error $ "can't apply " ++ show (prettyTm (quote x)) |
|
|
|
|
|
|
|
|
(@@) :: HasCallStack => Value -> Value -> Value |
|
|
(@@) :: HasCallStack => Value -> Value -> Value |
|
@ -610,7 +619,7 @@ vProj1 (GluedVl h sp vl) = GluedVl h (sp Seq.:|> PProj1) (vProj1 vl) |
|
|
vProj1 (VSystem fs) = VSystem (fmap vProj1 fs) |
|
|
vProj1 (VSystem fs) = VSystem (fmap vProj1 fs) |
|
|
vProj1 (VInc (VSigma a _) b c) = VInc a b (vProj1 c) |
|
|
vProj1 (VInc (VSigma a _) b c) = VInc a b (vProj1 c) |
|
|
vProj1 (VCase env rng sc branches) = |
|
|
vProj1 (VCase env rng sc branches) = |
|
|
VCase env (fun \x -> let VSigma a _ = rng @@ x in a) sc (map (second (projIntoCase Proj1)) branches) |
|
|
|
|
|
|
|
|
VCase env rng sc (map (projIntoCase Proj1) branches) |
|
|
vProj1 x = error $ "can't proj1 " ++ show (prettyTm (quote x)) |
|
|
vProj1 x = error $ "can't proj1 " ++ show (prettyTm (quote x)) |
|
|
|
|
|
|
|
|
vProj2 :: HasCallStack => Value -> Value |
|
|
vProj2 :: HasCallStack => Value -> Value |
|
@ -620,10 +629,12 @@ vProj2 (GluedVl h sp vl) = GluedVl h (sp Seq.:|> PProj2) (vProj2 vl) |
|
|
vProj2 (VSystem fs) = VSystem (fmap vProj2 fs) |
|
|
vProj2 (VSystem fs) = VSystem (fmap vProj2 fs) |
|
|
vProj2 (VInc (VSigma _ (Closure _ r)) b c) = VInc (r (vProj1 c)) b (vProj2 c) |
|
|
vProj2 (VInc (VSigma _ (Closure _ r)) b c) = VInc (r (vProj1 c)) b (vProj2 c) |
|
|
vProj2 (VCase env rng sc branches) = |
|
|
vProj2 (VCase env rng sc branches) = |
|
|
VCase env (fun \x -> let VSigma _ (Closure _ r) = rng @@ x in r (vProj1 x)) sc (map (second (projIntoCase Proj2)) branches) |
|
|
|
|
|
|
|
|
VCase env rng sc (map (projIntoCase Proj2) branches) |
|
|
vProj2 x = error $ "can't proj2 " ++ show (prettyTm (quote x)) |
|
|
vProj2 x = error $ "can't proj2 " ++ show (prettyTm (quote x)) |
|
|
|
|
|
|
|
|
projIntoCase :: (Term -> Term) -> Term -> Term |
|
|
|
|
|
projIntoCase f (Lam p x r) = Lam p x (projIntoCase f r) |
|
|
|
|
|
projIntoCase f (PathIntro l a b r) = PathIntro l a b (projIntoCase f r) |
|
|
|
|
|
projIntoCase f x = f x |
|
|
|
|
|
|
|
|
projIntoCase :: (Term -> Term) -> (Term, Int, Term) -> (Term, Int, Term) |
|
|
|
|
|
projIntoCase fun (pat, nLams, term) = (pat, nLams, go nLams term) where |
|
|
|
|
|
go 0 x = fun x |
|
|
|
|
|
go n (Lam p x r) = Lam p x (go (n - 1) r) |
|
|
|
|
|
go n (PathIntro l a b r) = PathIntro l a b (go (n - 1) r) |
|
|
|
|
|
go _ x = x |