@@ -18,6 +18,7 @@ import Idris.Core.Typecheck (check, recheck)
1818import Idris.ErrReverse (errReverse)
1919import Idris.ElabQuasiquote (extractUnquotes)
2020import Idris.Elab.Utils
21+import Idris.Reflection
2122import qualified Util.Pretty as U
2223
2324import Control.Applicative ((<$>))
@@ -36,6 +37,32 @@ import Debug.Trace
3637data ElabMode = ETyDecl | ELHS | ERHS
3738 deriving Eq
3839
40+data ElabResult =
41+ ElabResult { resultTerm :: Term -- ^ The term resulting from elaboration
42+ , resultMetavars :: [(Name, (Int, Maybe Name, Type))]
43+ -- ^ Information about new metavariables
44+ , resultCaseDecls :: [PDecl]
45+ -- ^ Deferred declarations as the meaning of case blocks
46+ , resultContext :: Context
47+ -- ^ The potentially extended context from new definitions
48+ , resultTyDecls :: [(Name, FC, [PArg], Type)]
49+ -- ^ Meta-info about the new type declarations
50+ }
51+
52+processTacticDecls :: [(Name, FC, [PArg], Type)] -> Idris ()
53+processTacticDecls info =
54+ forM_ info $ \(n, fc, impls, ty) ->
55+ do logLvl 3 $ "Declaration from tactics: " ++ show n ++ " : " ++ show ty
56+ logLvl 3 $ " It has impls " ++ show impls
57+ updateIState $ \i -> i { idris_implicits =
58+ addDef n impls (idris_implicits i) }
59+ addIBC (IBCImp n)
60+ ds <- checkDef fc iderr [(n, (-1, Nothing, ty))]
61+ addIBC (IBCDef n)
62+ let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
63+ addDeferred ds'
64+
65+
3966-- Using the elaborator, convert a term in raw syntax to a fully
4067-- elaborated, typechecked term.
4168--
@@ -45,7 +72,7 @@ data ElabMode = ETyDecl | ELHS | ERHS
4572-- Also find deferred names in the term and their types
4673
4774build :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
48− ElabD (Term, [(Name, (Int, Maybe Name, Type))], [PDecl])
75+ ElabD ElabResult
4976build ist info emode opts fn tm
5077 = do elab ist info emode opts fn tm
5178 let tmIn = tm
@@ -64,7 +91,7 @@ build ist info emode opts fn tm
6491 mapM_ (\n -> when (n `elem` hs) $
6592 do focus n
6693 g <- goal
67− try (resolveTC True 7 g fn ist)
94+ try (resolveTC True False 7 g fn ist)
6895 (movelast n)) ivs
6996 ivs <- get_instances
7097 hs <- get_holes
@@ -72,7 +99,8 @@ build ist info emode opts fn tm
7299 mapM_ (\n -> when (n `elem` hs) $
73100 do focus n
74101 g <- goal
75− resolveTC True 7 g fn ist) ivs
102+ ptm <- get_term
103+ resolveTC True True 7 g fn ist) ivs
76104 tm <- get_term
77105 ctxt <- get_context
78106 probs <- get_probs
@@ -94,12 +122,13 @@ build ist info emode opts fn tm
94122 when tydecl (do update_term orderPats
95123 mkPat)
96124-- update_term liftPats)
97− EState is _ <- getAux
125+ EState is _ impls <- getAux
98126 tt <- get_term
99127 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
100128 log <- getLog
101− if (log /= "") then trace log $ return (tm, ds, is)
102− else return (tm, ds, is)
129+ ctxt <- get_context
130+ if (log /= "") then trace log $ return (ElabResult tm ds is ctxt impls)
131+ else return (ElabResult tm ds is ctxt impls)
103132 where pattern = emode == ELHS
104133 tydecl = emode == ETyDecl
105134
@@ -114,7 +143,7 @@ build ist info emode opts fn tm
114143-- know about yet on the LHS of a pattern def)
115144
116145buildTC :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
117− ElabD (Term, [(Name, (Int, Maybe Name, Type))], [PDecl])
146+ ElabD ElabResult
118147buildTC ist info emode opts fn tm
119148 = do -- set name supply to begin after highest index in tm
120149 let ns = allNamesIn tm
@@ -135,12 +164,13 @@ buildTC ist info emode opts fn tm
135164 -- unification
136165 when (not (null dots)) $
137166 lift (Error (CantMatch (getInferTerm tm)))
138− EState is _ <- getAux
167+ EState is _ impls <- getAux
139168 tt <- get_term
140169 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
141170 log <- getLog
142− if (log /= "") then trace log $ return (tm, ds, is)
143− else return (tm, ds, is)
171+ ctxt <- get_context
172+ if (log /= "") then trace log $ return (ElabResult tm ds is ctxt impls)
173+ else return (ElabResult tm ds is ctxt impls)
144174 where pattern = emode == ELHS
145175
146176-- return whether arguments of the given constructor name can be
@@ -183,9 +213,9 @@ goal_polymorphic =
183213 _ -> return True
184214 _ -> return False
185215
186−-- Returns the set of declarations we need to add to complete the definition
187−-- (most likely case blocks to elaborate)
188−
216+-- | Returns the set of declarations we need to add to complete the
217+-- definition (most likely case blocks to elaborate) as well as
218+-- declarations resulting from user tactic scripts (%runTactics)
189219elab :: IState -> ElabInfo -> ElabMode -> FnOpts -> Name -> PTerm ->
190220 ElabD ()
191221elab ist info emode opts fn tm
@@ -321,7 +351,7 @@ elab ist info emode opts fn tm
321351 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
322352 _ -> elab' ina (Just fc) (PRef fc unitCon)
323353 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
324− = do g <- goal; resolveTC False 5 g fn ist
354+ = do g <- goal; resolveTC False False 5 g fn ist
325355 elab' ina fc (PResolveTC fc')
326356 = do c <- getNameFrom (sMN 0 "class")
327357 instanceArg c
@@ -540,7 +570,7 @@ elab ist info emode opts fn tm
540570 g <- goal
541571 hs <- get_holes
542572 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
543− then try (resolveTC True 7 g fn ist)
573+ then try (resolveTC True False 7 g fn ist)
544574 (movelast n)
545575 else movelast n)
546576 (ivs' \\ ivs)
@@ -700,7 +730,7 @@ elab ist info emode opts fn tm
700730 env <- get_env
701731 hs <- get_holes
702732 if all (\n -> not (n `elem` hs)) (freeNames g)
703− then try (resolveTC False 7 g fn ist)
733+ then try (resolveTC False False 7 g fn ist)
704734 (movelast n)
705735 else movelast n)
706736 (ivs' \\ ivs)
@@ -965,17 +995,14 @@ elab ist info emode opts fn tm
965995 elab' ina fc (PUnifyLog t) = do unifyLog True
966996 elab' ina fc t
967997 unifyLog False
968− elab' ina fc (PQuasiquote t goal)
998+ elab' ina fc (PQuasiquote t goalt)
969999 = do -- First extract the unquoted subterms, replacing them with fresh
9701000 -- names in the quasiquoted term. Claim their reflections to be
9711001 -- an inferred type (to support polytypic quasiquotes).
1002+ finalTy <- goal
9721003 (t, unq) <- extractUnquotes 0 t
9731004 let unquoteNames = map fst unq
974− mapM_ (\uqn -> do uqh <- getNameFrom (sMN 0 "uqh")
975− claim uqh RType
976− movelast uqh
977− claim uqn (Var uqh)) unquoteNames
978−
1005+ mapM_ (\uqn -> claim uqn (forget finalTy)) unquoteNames
9791006
9801007 -- Save the old state - we need a fresh proof state to avoid
9811008 -- capturing lexically available variables in the quoted term.
@@ -1010,7 +1037,7 @@ elab ist info emode opts fn tm
10101037 letbind nTm (Var qTy) (Var qTm)
10111038
10121039 -- Fill out the goal type, if relevant
1013− case goal of
1040+ case goalt of
10141041 Nothing -> return ()
10151042 Just gTy -> do focus qTy
10161043 elabE (ina { e_qq = True }) fc gTy
@@ -1025,18 +1052,20 @@ elab ist info emode opts fn tm
10251052 env <- get_env
10261053 loadState
10271054 let quoted = fmap (explicitNames . binderVal) $ lookup nTm env
1028−
1055+ isRaw = case unApply (normaliseAll ctxt env finalTy) of
1056+ (P _ n _, []) | n == reflm "Raw" -> True
1057+ _ -> False
10291058 case quoted of
10301059 Just q -> do ctxt <- get_context
10311060 (q', _, _) <- lift $ recheck ctxt [(uq, Lam Erased) | uq <- unquoteNames] (forget q) q
10321061 if pattern
1033− then do try' (reflectTTQuotePattern unquoteNames q')
1034− (reflectRawQuotePattern unquoteNames (forget q'))
1035− True
1036− else do try' (fill $ reflectTTQuote unquoteNames q')
1037− -- we forget q' instead of using q to ensure rechecking
1038− (fill $ reflectRawQuote unquoteNames (forget q'))
1039− True -- ignore errors like proof search does
1062+ then if isRaw
1063+ then reflectRawQuotePattern unquoteNames (forget q')
1064+ else reflectTTQuotePattern unquoteNames q'
1065+ else do if isRaw
1066+ then -- we forget q' instead of using q to ensure rechecking
1067+ fill $ reflectRawQuote unquoteNames (forget q')
1068+ else fill $ reflectTTQuote unquoteNames q'
10401069 solve
10411070
10421071 Nothing -> lift . tfail . Msg $ "Broken elaboration of quasiquote"
@@ -1077,8 +1106,8 @@ elab ist info emode opts fn tm
10771106 focus n
10781107 elab' ina (Just fc') tm
10791108 env <- get_env
1080− ctxt <- get_context
1081− runTactical (maybe fc' id fc) ctxt env (P Bound n' Erased)
1109+ runTactical (maybe fc' id fc) env (P Bound n' Erased)
1110+ EState _ _ todo <- getAux
10821111 solve
10831112 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
10841113
@@ -1346,9 +1375,12 @@ findInstances :: IState -> Term -> [Name]
13461375findInstances ist t
13471376 | (P _ n _, _) <- unApply t
13481377 = case lookupCtxt n (idris_classes ist) of
1349− [CI _ _ _ _ _ ins] -> ins
1378+ [CI _ _ _ _ _ ins _] -> filter accessible ins
13501379 _ -> []
13511380 | otherwise = []
1381+ where accessible n = case lookupDefAccExact n False (tt_ctxt ist) of
1382+ Just (_, Hidden) -> False
1383+ _ -> True
13521384
13531385-- Try again to solve auto implicits
13541386solveAuto :: IState -> Name -> Bool -> Name -> ElabD ()
@@ -1376,14 +1408,26 @@ proofSearch' ist rec ambigok depth prv top n hints
13761408-- Resolve type classes. This will only pick up 'normal' instances, never
13771409-- named instances (hence using 'tcname' to check it's a generated instance
13781410-- name).
1379−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1380−resolveTC = resTC' []
1381−
1382−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1383−resTC' tcs def 1 topg fn ist = try' (trivial' ist) (resolveTC def 0 topg fn ist) True
1384−resTC' tcs defaultOn depth topg fn ist
1385− = do compute
1386− g <- goal
1411+resolveTC :: Bool -- using default Int
1412+ -> Bool -- allow metavariables in the goal
1413+ -> Int -- depth
1414+ -> Term -- top level goal
1415+ -> Name -- top level function name
1416+ -> IState -> ElabD ()
1417+resolveTC def mvok depth top fn ist
1418+ = do hs <- get_holes
1419+ resTC' [] def hs depth top fn ist
1420+
1421+resTC' tcs def topholes 0 topg fn ist = fail $ "Can't resolve type class"
1422+resTC' tcs def topholes 1 topg fn ist = try' (trivial' ist) (resolveTC def False 0 topg fn ist) True
1423+resTC' tcs defaultOn topholes depth topg fn ist
1424+ = do compute
1425+ g <- goal
1426+ let argsok = tcArgsOK g topholes
1427+-- trace (show (g,hs,argsok,topholes)) $
1428+ if not argsok -- && not mvok)
1429+ then lift $ tfail $ CantResolve True topg
1430+ else do
13871431 ptm <- get_term
13881432 ulog <- getUnifyLog
13891433 hs <- get_holes
@@ -1400,6 +1444,31 @@ resTC' tcs defaultOn depth topg fn ist
14001444 let depth' = if scopeOnly then 2 else depth
14011445 blunderbuss t depth' stk (stk ++ insts)) True
14021446 where
1447+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1448+ = True
1449+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1450+ = let (f, as) = unApply ty in
1451+ case f of
1452+ P _ cn _ -> case lookupCtxtExact cn (idris_classes ist) of
1453+ Just ci -> tcDetArgsOK 0 (class_determiners ci) hs as
1454+ Nothing -> not $ any (isMeta hs) as
1455+ _ -> not $ any (isMeta hs) as
1456+
1457+ tcDetArgsOK i ds hs (x : xs)
1458+ | i `elem` ds = not (isMeta hs x) && tcDetArgsOK (i + 1) ds hs xs
1459+ | otherwise = tcDetArgsOK (i + 1) ds hs xs
1460+ tcDetArgsOK _ _ _ [] = True
1461+
1462+ isMeta :: [Name] -> Term -> Bool
1463+ isMeta ns (P _ n _) = n `elem` ns
1464+ isMeta _ _ = False
1465+
1466+ notHole hs (P _ n _, c)
1467+ | (P _ cn _, _) <- unApply c,
1468+ n `elem` hs && isConName cn (tt_ctxt ist) = False
1469+ | Constant _ <- c = not (n `elem` hs)
1470+ notHole _ _ = True
1471+
14031472 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
14041473 | otherwise = (fail "Can't resolve", show n)
14051474
@@ -1427,10 +1496,13 @@ resTC' tcs defaultOn depth topg fn ist
14271496
14281497 blunderbuss t d stk [] = do -- c <- get_env
14291498 -- ps <- get_probs
1430− lift $ tfail $ CantResolve topg
1499+ lift $ tfail $ CantResolve False topg
14311500 blunderbuss t d stk (n:ns)
14321501 | n /= fn && (n `elem` stk || tcname n)
1433− = try' (resolve n d) (blunderbuss t d stk ns) True
1502+ = tryCatch (resolve n d)
1503+ (\e -> case e of
1504+ CantResolve True _ -> lift $ tfail e
1505+ _ -> blunderbuss t d stk ns)
14341506 | otherwise = blunderbuss t d stk ns
14351507
14361508 resolve n depth
@@ -1459,7 +1531,7 @@ resTC' tcs defaultOn depth topg fn ist
14591531 let got = fst (unApply t)
14601532 let depth' = if tc' `elem` tcs
14611533 then depth - 1 else depth
1462− resTC' (got : tcs) defaultOn depth' topg fn ist)
1534+ resTC' (got : tcs) defaultOn topholes depth' topg fn ist)
14631535 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
14641536 -- if there's any arguments left, we've failed to resolve
14651537 hs <- get_holes
@@ -1505,11 +1577,17 @@ case_ ind autoSolve ist fn tm = do
15051577 else casetac (forget val)
15061578 when autoSolve solveAll
15071579
1508−runTactical :: FC -> Context -> Env -> Term -> ElabD ()
1509−runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
1580+tacN :: String -> Name
1581+tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1582+
1583+runTactical :: FC -> Env -> Term -> ElabD ()
1584+runTactical fc env tm = do tm' <- eval tm
1585+ runTacTm tm'
1586+ return ()
15101587 where
1511− eval = normaliseAll ctxt env . finalise
1512− tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1588+ eval tm = do ctxt <- get_context
1589+ return $ normaliseAll ctxt env (finalise tm)
1590+
15131591 returnUnit = fmap fst $ get_type_val (Var unitCon)
15141592
15151593 -- | Do a step in the reflected elaborator monad. The input is the
@@ -1547,26 +1625,31 @@ runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
15471625 = do env <- get_env
15481626 fmap fst . get_type_val $ reflectEnv env
15491627 | n == tacN "prim__Fail", [_a, errs] <- args
1550− = do parts <- reifyReportParts (eval errs)
1628+ = do errs' <- eval errs
1629+ parts <- reifyReportParts errs'
15511630 lift . tfail $ ReflectionError [parts] (Msg "")
15521631 | n == tacN "prim__PureTactical", [_a, tm] <- args
15531632 = return tm
15541633 | n == tacN "prim__BindTactical", [_a, _b, first, andThen] <- args
1555− = do let first' = eval first
1634+ = do first' <- eval first
15561635 res <- runTacTm first'
1557− let next = eval (App andThen res)
1636+ next <- eval (App andThen res)
15581637 runTacTm next
15591638 | n == tacN "prim__Try", [_a, first, alt] <- args
1560− = do let first' = eval first
1561− let alt' = eval alt
1639+ = do first' <- eval first
1640+ alt' <- eval alt
15621641 try' (runTacTm first') (runTacTm alt') True
15631642 | n == tacN "prim__Fill", [raw] <- args
15641643 = do raw' <- reifyRaw raw
15651644 apply raw' []
15661645 returnUnit
1567− | n == tacN "prim__Gensym", [eval -> Constant (Str hint)] <- args
1568− = do n <- getNameFrom (sMN 0 hint)
1569− fmap fst $ get_type_val (reflectName n)
1646+ | n == tacN "prim__Gensym", [hint] <- args
1647+ = do hintStr <- eval hint
1648+ case hintStr of
1649+ Constant (Str h) -> do
1650+ n <- getNameFrom (sMN 0 h)
1651+ fmap fst $ get_type_val (reflectName n)
1652+ _ -> fail "no hint"
15701653 | n == tacN "prim__Claim", [n, ty] <- args
15711654 = do n' <- reifyTTName n
15721655 ty' <- reifyRaw ty
@@ -1596,6 +1679,29 @@ runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
15961679 Just name -> fmap Just $ reifyTTName name
15971680 intro n
15981681 returnUnit
1682+ | n == tacN "prim__DeclareType", [decl] <- args
1683+ = do (RDeclare n args res) <- reifyTyDecl decl
1684+ ctxt <- get_context
1685+ let mkPi arg res = RBind (argName arg)
1686+ (Pi Nothing (argTy arg) (RUType AllTypes))
1687+ res
1688+ rty = foldr mkPi res args
1689+ (checked, ty') <- lift $ check ctxt [] rty
1690+ case normaliseAll ctxt [] (finalise ty') of
1691+ TType _ -> lift . tfail . InternalMsg $
1692+ show checked ++ " is not a type: it's " ++ show ty'
1693+ _ -> return ()
1694+ case lookupDefExact n ctxt of
1695+ Just _ -> lift . tfail . InternalMsg $
1696+ show n ++ " is already defined."
1697+ Nothing -> return ()
1698+ let decl = TyDecl Ref checked
1699+ ctxt' = addCtxtDef n decl ctxt
1700+ set_context ctxt'
1701+ updateAux $ \e -> e { new_tyDecls = (n, fc, map rArgToPArg args, checked) :
1702+ new_tyDecls e }
1703+ aux <- getAux
1704+ returnUnit
15991705 | n == tacN "prim__Debug", [ty, msg] <- args
16001706 = do let msg' = fromTTMaybe msg
16011707 case msg' of
@@ -1850,6 +1956,7 @@ runTac autoSolve ist perhapsFC fn tac
18501956 Just fc ->
18511957 do fill $ reflectFC fc
18521958 solve
1959+ runT Qed = lift . tfail $ Msg "The qed command is only valid in the interactive prover"
18531960 runT x = fail $ "Not implemented " ++ show x
18541961
18551962 runReflected t = do t' <- reify ist t
@@ -2361,7 +2468,7 @@ reflectTTQuote unq (P nt n t)
23612468reflectTTQuote unq (V n)
23622469 = reflCall "V" [RConstant (I n)]
23632470reflectTTQuote unq (Bind n b x)
2364− = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote unq b, reflectTTQuote unq x]
2471+ = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote (reflm "TT") unq b, reflectTTQuote unq x]
23652472reflectTTQuote unq (App f x)
23662473 = reflCall "App" [reflectTTQuote unq f, reflectTTQuote unq x]
23672474reflectTTQuote unq (Constant c)
@@ -2378,7 +2485,7 @@ reflectRawQuote unq (Var n)
23782485 | n `elem` unq = Var n
23792486 | otherwise = reflCall "Var" [reflectName n]
23802487reflectRawQuote unq (RBind n b r) =
2381− reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote unq b, reflectRawQuote unq r]
2488+ reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote (reflm "Raw") unq b, reflectRawQuote unq r]
23822489reflectRawQuote unq (RApp f x) =
23832490 reflCall "RApp" [reflectRawQuote unq f, reflectRawQuote unq x]
23842491reflectRawQuote unq RType = Var (reflm "RType")
@@ -2436,27 +2543,27 @@ reflectNameQuotePattern _ -- for all other names, match any
24362543 solve
24372544
24382545reflectBinder :: Binder Term -> Raw
2439−reflectBinder = reflectBinderQuote reflectTTQuote []
2440−
2441−reflectBinderQuote :: ([Name] -> a -> Raw) -> [Name] -> Binder a -> Raw
2442−reflectBinderQuote q unq (Lam t)
2443− = reflCall "Lam" [Var (reflm "TT"), q unq t]
2444−reflectBinderQuote q unq (Pi _ t k)
2445− = reflCall "Pi" [Var (reflm "TT"), q unq t, q unq k]
2446−reflectBinderQuote q unq (Let x y)
2447− = reflCall "Let" [Var (reflm "TT"), q unq x, q unq y]
2448−reflectBinderQuote q unq (NLet x y)
2449− = reflCall "NLet" [Var (reflm "TT"), q unq x, q unq y]
2450−reflectBinderQuote q unq (Hole t)
2451− = reflCall "Hole" [Var (reflm "TT"), q unq t]
2452−reflectBinderQuote q unq (GHole _ t)
2453− = reflCall "GHole" [Var (reflm "TT"), q unq t]
2454−reflectBinderQuote q unq (Guess x y)
2455− = reflCall "Guess" [Var (reflm "TT"), q unq x, q unq y]
2456−reflectBinderQuote q unq (PVar t)
2457− = reflCall "PVar" [Var (reflm "TT"), q unq t]
2458−reflectBinderQuote q unq (PVTy t)
2459− = reflCall "PVTy" [Var (reflm "TT"), q unq t]
2546+reflectBinder = reflectBinderQuote reflectTTQuote (reflm "TT") []
2547+
2548+reflectBinderQuote :: ([Name] -> a -> Raw) -> Name -> [Name] -> Binder a -> Raw
2549+reflectBinderQuote q ty unq (Lam t)
2550+ = reflCall "Lam" [Var ty, q unq t]
2551+reflectBinderQuote q ty unq (Pi _ t k)
2552+ = reflCall "Pi" [Var ty, q unq t, q unq k]
2553+reflectBinderQuote q ty unq (Let x y)
2554+ = reflCall "Let" [Var ty, q unq x, q unq y]
2555+reflectBinderQuote q ty unq (NLet x y)
2556+ = reflCall "NLet" [Var ty, q unq x, q unq y]
2557+reflectBinderQuote q ty unq (Hole t)
2558+ = reflCall "Hole" [Var ty, q unq t]
2559+reflectBinderQuote q ty unq (GHole _ t)
2560+ = reflCall "GHole" [Var ty, q unq t]
2561+reflectBinderQuote q ty unq (Guess x y)
2562+ = reflCall "Guess" [Var ty, q unq x, q unq y]
2563+reflectBinderQuote q ty unq (PVar t)
2564+ = reflCall "PVar" [Var ty, q unq t]
2565+reflectBinderQuote q ty unq (PVTy t)
2566+ = reflCall "PVTy" [Var ty, q unq t]
24602567
24612568mkList :: Raw -> [Raw] -> Raw
24622569mkList ty [] = RApp (Var (sNS (sUN "Nil") ["List", "Prelude"])) ty
@@ -2603,11 +2710,15 @@ reflectErr (NotInjective t1 t2 t3) =
26032710 , reflect t2
26042711 , reflect t3
26052712 ]
2606−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2713+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2714+reflectErr (InvalidTCArg n t) = raw_apply (Var $ reflErrName "InvalidTCArg") [reflectName n, reflect t]
26072715reflectErr (CantResolveAlts ss) =
26082716 raw_apply (Var $ reflErrName "CantResolveAlts")
26092717 [rawList (Var $ reflm "TTName") (map reflectName ss)]
26102718reflectErr (IncompleteTerm t) = raw_apply (Var $ reflErrName "IncompleteTerm") [reflect t]
2719+reflectErr (NoEliminator str t)
2720+ = raw_apply (Var $ reflErrName "NoEliminator") [RConstant (Str str),
2721+ reflect t]
26112722reflectErr UniverseError = Var $ reflErrName "UniverseError"
26122723reflectErr ProgramLineComment = Var $ reflErrName "ProgramLineComment"
26132724reflectErr (Inaccessible n) = raw_apply (Var $ reflErrName "Inaccessible") [reflectName n]
@@ -2748,6 +2859,28 @@ reifyReportPart (App (P (DCon _ _ _) n _) tm)
27482859 Nothing -> Left . InternalMsg $ "could not reify subreport " ++ show tm
27492860reifyReportPart x = Left . InternalMsg $ "could not reify " ++ show x
27502861
2862+reifyTyDecl :: Term -> ElabD RTyDecl
2863+reifyTyDecl (App (App (App (P (DCon _ _ _) n _) tyN) args) ret)
2864+ | n == tacN "Declare" =
2865+ do tyN' <- reifyTTName tyN
2866+ args' <- case unList args of
2867+ Nothing -> fail $ "Couldn't reify " ++ show args ++ " as an arglist."
2868+ Just xs -> mapM reifyRArg xs
2869+ ret' <- reifyRaw ret
2870+ return $ RDeclare tyN' args' ret'
2871+ where reifyRArg :: Term -> ElabD RArg
2872+ reifyRArg (App (App (P (DCon _ _ _) n _) argN) argTy)
2873+ | n == tacN "Explicit" = liftM2 RExplicit
2874+ (reifyTTName argN)
2875+ (reifyRaw argTy)
2876+ | n == tacN "Implicit" = liftM2 RImplicit
2877+ (reifyTTName argN)
2878+ (reifyRaw argTy) | n == tacN "Constraint" = liftM2 RConstraint
2879+ (reifyTTName argN)
2880+ (reifyRaw argTy)
2881+ reifyRArg aTm = fail $ "Couldn't reify " ++ show aTm ++ " as an RArg."
2882+reifyTyDecl tm = fail $ "Couldn't reify " ++ show tm ++ " as a type declaration."
2883+
27512884envTupleType :: Raw
27522885envTupleType
27532886 = raw_apply (Var pairTy) [ (Var $ reflm "TTName")