|
@ -1,7 +1,9 @@ |
|
|
|
|
|
{-# LANGUAGE BlockArguments #-} |
|
|
{-# LANGUAGE LambdaCase #-} |
|
|
{-# LANGUAGE LambdaCase #-} |
|
|
{-# LANGUAGE DeriveAnyClass #-} |
|
|
{-# LANGUAGE DeriveAnyClass #-} |
|
|
{-# LANGUAGE ScopedTypeVariables #-} |
|
|
{-# LANGUAGE ScopedTypeVariables #-} |
|
|
{-# LANGUAGE ViewPatterns #-} |
|
|
{-# LANGUAGE ViewPatterns #-} |
|
|
|
|
|
{-# LANGUAGE TupleSections #-} |
|
|
module Elab.Eval where |
|
|
module Elab.Eval where |
|
|
|
|
|
|
|
|
import Control.Monad.Reader |
|
|
import Control.Monad.Reader |
|
@ -39,7 +41,7 @@ eval :: Term -> ElabM Value |
|
|
eval t = asks (flip eval' t) |
|
|
eval t = asks (flip eval' t) |
|
|
|
|
|
|
|
|
forceIO :: MonadIO m => Value -> m Value |
|
|
forceIO :: MonadIO m => Value -> m Value |
|
|
forceIO mv@(VNe (HMeta (MV _ cell)) args) = do |
|
|
|
|
|
|
|
|
forceIO mv@(VNe (HMeta (mvCell -> cell)) args) = do |
|
|
solved <- liftIO $ readIORef cell |
|
|
solved <- liftIO $ readIORef cell |
|
|
case solved of |
|
|
case solved of |
|
|
Just vl -> forceIO $ foldl applProj vl args |
|
|
Just vl -> forceIO $ foldl applProj vl args |
|
@ -66,7 +68,7 @@ zonkIO :: Value -> IO Value |
|
|
zonkIO (VNe hd sp) = do |
|
|
zonkIO (VNe hd sp) = do |
|
|
sp' <- traverse zonkSp sp |
|
|
sp' <- traverse zonkSp sp |
|
|
case hd of |
|
|
case hd of |
|
|
HMeta (MV _ cell) -> do |
|
|
|
|
|
|
|
|
HMeta (mvCell -> cell) -> do |
|
|
solved <- liftIO $ readIORef cell |
|
|
solved <- liftIO $ readIORef cell |
|
|
case solved of |
|
|
case solved of |
|
|
Just vl -> zonkIO $ foldl applProj vl sp' |
|
|
Just vl -> zonkIO $ foldl applProj vl sp' |
|
@ -366,10 +368,12 @@ isConvertibleTo a b = isConvertibleTo (force a) (force b) where |
|
|
pure id |
|
|
pure id |
|
|
|
|
|
|
|
|
newMeta :: Value -> ElabM Value |
|
|
newMeta :: Value -> ElabM Value |
|
|
newMeta _dom = do |
|
|
|
|
|
|
|
|
newMeta dom = do |
|
|
|
|
|
loc <- liftM2 (,) <$> asks currentFile <*> asks currentSpan |
|
|
n <- newName |
|
|
n <- newName |
|
|
c <- liftIO $ newIORef Nothing |
|
|
c <- liftIO $ newIORef Nothing |
|
|
let m = MV (getNameText n) c |
|
|
|
|
|
|
|
|
let m = MV (getNameText n) c dom (flatten <$> loc) |
|
|
|
|
|
flatten (x, (y, z)) = (x, y, z) |
|
|
|
|
|
|
|
|
env <- asks getEnv |
|
|
env <- asks getEnv |
|
|
|
|
|
|
|
@ -390,16 +394,23 @@ _nameCounter = unsafePerformIO $ newIORef 0 |
|
|
{-# NOINLINE _nameCounter #-} |
|
|
{-# NOINLINE _nameCounter #-} |
|
|
|
|
|
|
|
|
solveMeta :: MV -> Seq Projection -> Value -> ElabM () |
|
|
solveMeta :: MV -> Seq Projection -> Value -> ElabM () |
|
|
solveMeta m@(MV _ cell) sp rhs = do |
|
|
|
|
|
|
|
|
solveMeta m@(mvCell -> cell) sp rhs = do |
|
|
env <- ask |
|
|
env <- ask |
|
|
names <- checkSpine Set.empty sp |
|
|
|
|
|
checkScope (Set.fromList names) rhs |
|
|
|
|
|
`withNote` hsep [prettyTm (quote (VNe (HMeta m) sp)), pretty '≡', prettyTm (quote rhs)] |
|
|
|
|
|
let tm = quote rhs |
|
|
|
|
|
lam = eval' env $ foldr (Lam Ex) tm names |
|
|
|
|
|
liftIO . atomicModifyIORef' cell $ \case |
|
|
|
|
|
Just _ -> error "filled cell in solvedMeta" |
|
|
|
|
|
Nothing -> (Just lam, ()) |
|
|
|
|
|
|
|
|
names <- tryElab $ checkSpine Set.empty sp |
|
|
|
|
|
case names of |
|
|
|
|
|
Right names -> do |
|
|
|
|
|
checkScope (Set.fromList names) rhs |
|
|
|
|
|
`withNote` hsep [prettyTm (quote (VNe (HMeta m) sp)), pretty '≡', prettyTm (quote rhs)] |
|
|
|
|
|
let tm = quote rhs |
|
|
|
|
|
lam = eval' env $ foldr (Lam Ex) tm names |
|
|
|
|
|
liftIO . atomicModifyIORef' cell $ \case |
|
|
|
|
|
Just _ -> error "filled cell in solvedMeta" |
|
|
|
|
|
Nothing -> (Just lam, ()) |
|
|
|
|
|
Left (_ :: SpineProjection) -> do |
|
|
|
|
|
liftIO . atomicModifyIORef' (unsolvedMetas env) $ \x -> (, ()) $ |
|
|
|
|
|
case Map.lookup m x of |
|
|
|
|
|
Just qs -> Map.insert m ((sp, rhs):qs) x |
|
|
|
|
|
Nothing -> Map.insert m [(sp, rhs)] x |
|
|
|
|
|
|
|
|
checkScope :: Set Name -> Value -> ElabM () |
|
|
checkScope :: Set Name -> Value -> ElabM () |
|
|
checkScope scope (VNe h sp) = |
|
|
checkScope scope (VNe h sp) = |
|
|