@@ -1,5 +1,5 @@
1−{-# LANGUAGE PatternGuards #-}
1+{-# LANGUAGE PatternGuards, ViewPatterns #-}
2−
2+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
3module Idris.ElabTerm where
3module Idris.ElabTerm where
5import Idris.AbsSyntax
5import Idris.AbsSyntax
@@ -420,6 +420,7 @@ elab ist info emode opts fn tm
420 where -- if none work, take the error from the first
420 where -- if none work, take the error from the first
421 trySeq (x : xs) = let e1 = elab' ina fc x in
421 trySeq (x : xs) = let e1 = elab' ina fc x in
422 try' e1 (trySeq' e1 xs) True
422 try' e1 (trySeq' e1 xs) True
423+ trySeq [] = fail "Nothing to try in sequence"
423 trySeq' deferr [] = proofFail deferr
424 trySeq' deferr [] = proofFail deferr
424 trySeq' deferr (x : xs)
425 trySeq' deferr (x : xs)
425 = try' (do elab' ina fc x
426 = try' (do elab' ina fc x
@@ -546,7 +547,8 @@ elab ist info emode opts fn tm
546 -- HACK: If the name leaks into its type, it may leak out of
547 -- HACK: If the name leaks into its type, it may leak out of
547 -- scope outside, so substitute in the outer scope.
548 -- scope outside, so substitute in the outer scope.
548 expandLet n (case lookup n env of
549 expandLet n (case lookup n env of
549− Just (Let t v) -> v)
550+ Just (Let t v) -> v
551+ other -> error ("Value not a let binding: " ++ show other))
551 elab' ina _ (PGoal fc r n sc) = do
553 elab' ina _ (PGoal fc r n sc) = do
552 rty <- goal
554 rty <- goal
@@ -955,13 +957,16 @@ elab ist info emode opts fn tm
955 elab' ina fc (PUnifyLog t) = do unifyLog True
957 elab' ina fc (PUnifyLog t) = do unifyLog True
956 elab' ina fc t
958 elab' ina fc t
957 unifyLog False
959 unifyLog False
958− elab' ina fc (PQuasiquote t goal) -- TODO: goal type
960+ elab' ina fc (PQuasiquote t goal)
959 = do -- First extract the unquoted subterms, replacing them with fresh
961 = do -- First extract the unquoted subterms, replacing them with fresh
960 -- names in the quasiquoted term. Claim their reflections to be
962 -- names in the quasiquoted term. Claim their reflections to be
961− -- of type TT.
963+ -- an inferred type (to support polytypic quasiquotes).
962 (t, unq) <- extractUnquotes 0 t
964 (t, unq) <- extractUnquotes 0 t
963 let unquoteNames = map fst unq
965 let unquoteNames = map fst unq
966+ mapM_ (\uqn -> do uqh <- getNameFrom (sMN 0 "uqh")
964− mapM_ (flip claim (Var tt)) unquoteNames
969+ claim uqn (Var uqh)) unquoteNames
967 -- Save the old state - we need a fresh proof state to avoid
972 -- Save the old state - we need a fresh proof state to avoid
@@ -1017,9 +1022,14 @@ elab ist info emode opts fn tm
1017 Just q -> do ctxt <- get_context
1022 Just q -> do ctxt <- get_context
1018 (q', _, _) <- lift $ recheck ctxt [(uq, Lam Erased) | uq <- unquoteNames] (forget q) q
1023 (q', _, _) <- lift $ recheck ctxt [(uq, Lam Erased) | uq <- unquoteNames] (forget q) q
1019 if pattern
1024 if pattern
1020− then reflectQuotePattern unquoteNames q'
1025+ then reflectTTQuotePattern unquoteNames q'
1026+ -- TODO: support quasiquote patterns of Raw terms
1027+ else do try' (fill $ reflectTTQuote unquoteNames q')
1028+ -- we forget q' instead of using q to ensure rechecking
1021− else do fill $ reflectQuote unquoteNames q'
1029+ (fill $ reflectRawQuote unquoteNames (forget q'))
1030+ True -- ignore errors like proof search does
1023 Nothing -> lift . tfail . Msg $ "Broken elaboration of quasiquote"
1033 Nothing -> lift . tfail . Msg $ "Broken elaboration of quasiquote"
1025 -- Finally fill in the terms or patterns from the unquotes. This
1035 -- Finally fill in the terms or patterns from the unquotes. This
@@ -1049,6 +1059,20 @@ elab ist info emode opts fn tm
1049 delayElab $ do focus h
1059 delayElab $ do focus h
1051 elab' ina fc t
1061 elab' ina fc t
1062+ elab' ina _ (PRunTactics fc tm) =
1064+ n <- getNameFrom (sMN 0 "tacticScript")
1065+ n' <- getNameFrom (sMN 0 "tacticExpr")
1066+ let scriptTy = RApp (Var (sNS (sUN "Tactical") ["Tactical", "Reflection", "Language"])) (Var unitTy)
1069+ letbind n' scriptTy (Var n)
1071+ elab' ina (Just fc) tm
1073+ ctxt <- get_context
1074+ runTactical fc ctxt env (P Bound n' Erased)
1052 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
1076 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
1054 delayElab t = updateAux (\e -> e { delayed_elab = delayed_elab e ++ [t] })
1078 delayElab t = updateAux (\e -> e { delayed_elab = delayed_elab e ++ [t] })
@@ -1072,6 +1096,7 @@ elab ist info emode opts fn tm
1072 findScr [(n, (_, t))] = [(n, (True, t))]
1096 findScr [(n, (_, t))] = [(n, (True, t))]
1073 findScr (x : xs) = x : findScr xs
1097 findScr (x : xs) = x : findScr xs
1074 -- [] can't happen since scrutinee is in the environment!
1098 -- [] can't happen since scrutinee is in the environment!
1099+ findScr [] = error "The impossible happened - the scrutinee was not in the environment"
1076 -- To make sure top level pattern name remains in scope, put
1101 -- To make sure top level pattern name remains in scope, put
1077 -- it at the end of the environment
1102 -- it at the end of the environment
@@ -1233,7 +1258,8 @@ elab ist info emode opts fn tm
1233 lift (tfail (elaboratingArgErr while' e))
1258 lift (tfail (elaboratingArgErr while' e))
1234 put newState
1259 put newState
1235 return result
1260 return result
1236−
1261+ elabArgs _ _ _ _ _ _ (((arg, hole), _) : _) _ [] =
1262+ fail $ "Can't elaborate these args: " ++ show arg ++ " " ++ show hole
1238-- For every alternative, look at the function at the head. Automatically resolve
1264-- For every alternative, look at the function at the head. Automatically resolve
1239-- any nested alternatives where that function is also at the head
1265-- any nested alternatives where that function is also at the head
@@ -1411,6 +1437,7 @@ resTC' tcs defaultOn depth topg fn ist
1411 let imps = case lookupCtxtName n (idris_implicits ist) of
1437 let imps = case lookupCtxtName n (idris_implicits ist) of
1412 [] -> []
1438 [] -> []
1413 [args] -> map isImp (snd args) -- won't be overloaded!
1439 [args] -> map isImp (snd args) -- won't be overloaded!
1440+ xs -> error "The impossible happened - overloading is not expected here!"
1414 ps <- get_probs
1441 ps <- get_probs
1415 tm <- get_term
1442 tm <- get_term
1416 args <- map snd <$> try' (apply (Var n) imps)
1443 args <- map snd <$> try' (apply (Var n) imps)
@@ -1471,6 +1498,86 @@ case_ ind autoSolve ist fn tm = do
1471 else casetac (forget val)
1498 else casetac (forget val)
1472 when autoSolve solveAll
1499 when autoSolve solveAll
1501+runTactical :: FC -> Context -> Env -> Term -> ElabD ()
1502+runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
1504+ eval = normaliseAll ctxt env
1505+ tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1506+ returnUnit = fmap fst $ get_type_val (Var unitCon)
1508+ -- | Do a step in the reflected elaborator monad. The input is the
1509+ -- step, the output is the (reflected) term returned.
1510+ runTacTm :: Term -> ElabD Term
1511+ runTacTm (unApply -> tac@(P _ n _, args))
1512+ | n == tacN "prim__Solve", [] <- args
1515+ | n == tacN "prim__Goal", [] <- args
1516+ = do (h:_) <- get_holes
1518+ fmap fst . get_type_val $
1519+ rawPair (Var (reflm "TTName"), Var (reflm "TT"))
1520+ (reflectName h, reflect t)
1521+ | n == tacN "prim__Holes", [] <- args
1522+ = do hs <- get_holes
1523+ fmap fst . get_type_val $
1524+ mkList (Var $ reflm "TTName") (map reflectName hs)
1525+ | n == tacN "prim__Guess", [] <- args
1526+ = do ok <- is_guess
1528+ then do guess <- fmap forget get_guess
1529+ fmap fst . get_type_val $
1530+ RApp (RApp (Var (sNS (sUN "Just") ["Maybe", "Prelude"]))
1531+ (Var (reflm "TT")))
1533+ else fmap fst . get_type_val $
1534+ RApp (Var (sNS (sUN "Nothing") ["Maybe", "Prelude"]))
1536+ | n == tacN "prim__Env", [] <- args
1537+ = do env <- get_env
1538+ fmap fst . get_type_val $ reflectEnv env
1539+ | n == tacN "prim__Fail", [_a, errs] <- args
1540+ = do parts <- reifyReportParts (eval errs)
1541+ lift . tfail $ ReflectionError [parts] (Msg "")
1542+ | n == tacN "prim__PureTactical", [_a, tm] <- args
1544+ | n == tacN "prim__BindTactical", [_a, _b, first, andThen] <- args
1545+ = do let first' = eval first
1546+ res <- runTacTm first'
1547+ let next = eval (App andThen res)
1549+ | n == tacN "prim__Try", [_a, first, alt] <- args
1550+ = do let first' = eval first
1551+ let alt' = eval alt
1552+ try' (runTacTm first') (runTacTm alt') True
1553+ | n == tacN "prim__Fill", [raw] <- args
1554+ = do raw' <- reifyRaw raw
1557+ | n == tacN "prim__Gensym", [eval -> Constant (Str hint)] <- args
1558+ = do n <- getNameFrom (sMN 0 hint)
1559+ fmap fst $ get_type_val (reflectName n)
1560+ | n == tacN "prim__Claim", [n, ty] <- args
1561+ = do n' <- reifyTTName n
1565+ | n == tacN "prim__Forget", [tt] <- args
1566+ = do tt' <- reifyTT tt
1567+ fmap fst . get_type_val $ reflect tt'
1568+ | n == tacN "prim__Attack", [] <- args
1571+ | n == tacN "prim__Focus", [what] <- args
1572+ = do n' <- reifyTTName what
1575+ | n == tacN "prim__Unfocus", [what] <- args
1576+ = do n' <- reifyTTName what
1579+ runTacTm x = lift . tfail . InternalMsg $ "tactical is not implemented for " ++ show x
1474-- Running tactics directly
1581-- Running tactics directly
1475-- if a tactic adds unification problems, return an error
1582-- if a tactic adds unification problems, return an error
@@ -1796,16 +1903,20 @@ reifyApp ist t [n, tt', t']
1796 t'' <- reifyTT t'
1903 t'' <- reifyTT t'
1797 return $ LetTacTy n' (delab ist tt'') (delab ist t'')
1904 return $ LetTacTy n' (delab ist tt'') (delab ist t'')
1798reifyApp ist t [errs]
1905reifyApp ist t [errs]
1799− | t == reflm "Fail" = case unList errs of
1906+ | t == reflm "Fail" = fmap TFail (reifyReportParts errs)
1800− Nothing -> fail "Failed to reify errors"
1802− let parts = mapM reifyReportPart errs' in
1804− Left err -> fail $ "Couldn't reify \"Fail\" tactic - " ++ show err
1806− return $ TFail errs''
1807reifyApp _ f args = fail ("Unknown tactic " ++ show (f, args)) -- shouldn't happen
1907reifyApp _ f args = fail ("Unknown tactic " ++ show (f, args)) -- shouldn't happen
1909+reifyReportParts :: Term -> ElabD [ErrorReportPart]
1910+reifyReportParts errs =
1911+ case unList errs of
1912+ Nothing -> fail "Failed to reify errors"
1914+ let parts = mapM reifyReportPart errs' in
1916+ Left err -> fail $ "Couldn't reify \"Fail\" tactic - " ++ show err
1809-- | Reify terms from their reflected representation
1920-- | Reify terms from their reflected representation
1810reifyTT :: Term -> ElabD Term
1921reifyTT :: Term -> ElabD Term
1811reifyTT t@(App _ _)
1922reifyTT t@(App _ _)
@@ -1985,6 +2096,7 @@ reifyIntTy (P _ n _) | n == reflm "ITBig" = return ITBig
1985reifyIntTy (P _ n _) | n == reflm "ITChar" = return ITChar
2096reifyIntTy (P _ n _) | n == reflm "ITChar" = return ITChar
1986reifyIntTy (App (App (P _ n _) nt) (Constant (I i))) | n == reflm "ITVec" = fmap (flip ITVec i)
2097reifyIntTy (App (App (P _ n _) nt) (Constant (I i))) | n == reflm "ITVec" = fmap (flip ITVec i)
1987 (reifyNativeTy nt)
2098 (reifyNativeTy nt)
2099+reifyIntTy tm = fail $ "The term " ++ show tm ++ " is not a reflected IntTy"
1989reifyTTUExp :: Term -> ElabD UExp
2101reifyTTUExp :: Term -> ElabD UExp
1990reifyTTUExp t@(App _ _)
2102reifyTTUExp t@(App _ _)
@@ -2001,7 +2113,11 @@ reflCall funName args
2002-- | Lift a term into its Language.Reflection.TT representation
2114-- | Lift a term into its Language.Reflection.TT representation
2003reflect :: Term -> Raw
2115reflect :: Term -> Raw
2004−reflect = reflectQuote []
2116+reflect = reflectTTQuote []
2118+-- | Lift a term into its Language.Reflection.Raw representation
2119+reflectRaw :: Raw -> Raw
2120+reflectRaw = reflectRawQuote []
2006claimTT :: Name -> ElabD Name
2122claimTT :: Name -> ElabD Name
2007claimTT n = do n' <- getNameFrom n
2123claimTT n = do n' <- getNameFrom n
@@ -2012,8 +2128,8 @@ claimTT n = do n' <- getNameFrom n
2012-- In particular, the less-interesting bits are elaborated to _ patterns. This
2128-- In particular, the less-interesting bits are elaborated to _ patterns. This
2013-- happens to NameTypes, universe levels, names that are bound but not used,
2129-- happens to NameTypes, universe levels, names that are bound but not used,
2014-- and the type annotation field of the P constructor.
2130-- and the type annotation field of the P constructor.
2015−reflectQuotePattern :: [Name] -> Term -> ElabD ()
2131+reflectTTQuotePattern :: [Name] -> Term -> ElabD ()
2016−reflectQuotePattern unq (P _ n _)
2132+reflectTTQuotePattern unq (P _ n _)
2017 | n `elem` unq = -- the unquoted names have been claimed as TT already - just use them
2133 | n `elem` unq = -- the unquoted names have been claimed as TT already - just use them
2018 do fill (Var n) ; solve
2134 do fill (Var n) ; solve
2019 | otherwise =
2135 | otherwise =
@@ -2027,10 +2143,10 @@ reflectQuotePattern unq (P _ n _)
2027 fill $ reflCall "P" [Var nt, Var n', Var tyannot]
2143 fill $ reflCall "P" [Var nt, Var n', Var tyannot]
2029 focus n'; reflectNameQuotePattern n
2145 focus n'; reflectNameQuotePattern n
2030−reflectQuotePattern unq (V n)
2146+reflectTTQuotePattern unq (V n)
2031 = do fill $ reflCall "V" [RConstant (I n)]
2147 = do fill $ reflCall "V" [RConstant (I n)]
2033−reflectQuotePattern unq (Bind n b x)
2149+reflectTTQuotePattern unq (Bind n b x)
2034 = do x' <- claimTT (sMN 0 "sc")
2150 = do x' <- claimTT (sMN 0 "sc")
2035 movelast x'
2151 movelast x'
2036 b' <- getNameFrom (sMN 0 "binder")
2152 b' <- getNameFrom (sMN 0 "binder")
@@ -2050,7 +2166,7 @@ reflectQuotePattern unq (Bind n b x)
2053− focus x'; reflectQuotePattern unq x
2169+ focus x'; reflectTTQuotePattern unq x
2054 focus b'; reflectBinderQuotePattern unq b
2170 focus b'; reflectBinderQuotePattern unq b
@@ -2059,102 +2175,136 @@ reflectQuotePattern unq (Bind n b x)
2059 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2175 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2060 fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
2176 fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
2062− focus t'; reflectQuotePattern unq t
2178+ focus t'; reflectTTQuotePattern unq t
2063 reflectBinderQuotePattern unq (Pi _ t k)
2179 reflectBinderQuotePattern unq (Pi _ t k)
2064 = do t' <- claimTT (sMN 0 "ty") ; movelast t'
2180 = do t' <- claimTT (sMN 0 "ty") ; movelast t'
2065 k' <- claimTT (sMN 0 "k"); movelast k';
2181 k' <- claimTT (sMN 0 "k"); movelast k';
2066 fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
2182 fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
2068− focus t'; reflectQuotePattern unq t
2184+ focus t'; reflectTTQuotePattern unq t
2069 reflectBinderQuotePattern unq (Let x y)
2185 reflectBinderQuotePattern unq (Let x y)
2070 = do x' <- claimTT (sMN 0 "ty"); movelast x';
2186 = do x' <- claimTT (sMN 0 "ty"); movelast x';
2071 y' <- claimTT (sMN 0 "v"); movelast y';
2187 y' <- claimTT (sMN 0 "v"); movelast y';
2072 fill $ reflCall "Let" [Var (reflm "TT"), Var x', Var y']
2188 fill $ reflCall "Let" [Var (reflm "TT"), Var x', Var y']
2074− focus x'; reflectQuotePattern unq x
2190+ focus x'; reflectTTQuotePattern unq x
2075− focus y'; reflectQuotePattern unq y
2191+ focus y'; reflectTTQuotePattern unq y
2076 reflectBinderQuotePattern unq (NLet x y)
2192 reflectBinderQuotePattern unq (NLet x y)
2077 = do x' <- claimTT (sMN 0 "ty"); movelast x'
2193 = do x' <- claimTT (sMN 0 "ty"); movelast x'
2078 y' <- claimTT (sMN 0 "v"); movelast y'
2194 y' <- claimTT (sMN 0 "v"); movelast y'
2079 fill $ reflCall "NLet" [Var (reflm "TT"), Var x', Var y']
2195 fill $ reflCall "NLet" [Var (reflm "TT"), Var x', Var y']
2081− focus x'; reflectQuotePattern unq x
2197+ focus x'; reflectTTQuotePattern unq x
2082− focus y'; reflectQuotePattern unq y
2198+ focus y'; reflectTTQuotePattern unq y
2083 reflectBinderQuotePattern unq (Hole t)
2199 reflectBinderQuotePattern unq (Hole t)
2084 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2200 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2085 fill $ reflCall "Hole" [Var (reflm "TT"), Var t']
2201 fill $ reflCall "Hole" [Var (reflm "TT"), Var t']
2087− focus t'; reflectQuotePattern unq t
2203+ focus t'; reflectTTQuotePattern unq t
2088 reflectBinderQuotePattern unq (GHole _ t)
2204 reflectBinderQuotePattern unq (GHole _ t)
2089 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2205 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2090 fill $ reflCall "GHole" [Var (reflm "TT"), Var t']
2206 fill $ reflCall "GHole" [Var (reflm "TT"), Var t']
2092− focus t'; reflectQuotePattern unq t
2208+ focus t'; reflectTTQuotePattern unq t
2093 reflectBinderQuotePattern unq (Guess x y)
2209 reflectBinderQuotePattern unq (Guess x y)
2094 = do x' <- claimTT (sMN 0 "ty"); movelast x'
2210 = do x' <- claimTT (sMN 0 "ty"); movelast x'
2095 y' <- claimTT (sMN 0 "v"); movelast y'
2211 y' <- claimTT (sMN 0 "v"); movelast y'
2096 fill $ reflCall "Guess" [Var (reflm "TT"), Var x', Var y']
2212 fill $ reflCall "Guess" [Var (reflm "TT"), Var x', Var y']
2098− focus x'; reflectQuotePattern unq x
2214+ focus x'; reflectTTQuotePattern unq x
2099− focus y'; reflectQuotePattern unq y
2215+ focus y'; reflectTTQuotePattern unq y
2100 reflectBinderQuotePattern unq (PVar t)
2216 reflectBinderQuotePattern unq (PVar t)
2101 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2217 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2102 fill $ reflCall "PVar" [Var (reflm "TT"), Var t']
2218 fill $ reflCall "PVar" [Var (reflm "TT"), Var t']
2104− focus t'; reflectQuotePattern unq t
2220+ focus t'; reflectTTQuotePattern unq t
2105 reflectBinderQuotePattern unq (PVTy t)
2221 reflectBinderQuotePattern unq (PVTy t)
2106 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2222 = do t' <- claimTT (sMN 0 "ty"); movelast t'
2107 fill $ reflCall "PVTy" [Var (reflm "TT"), Var t']
2223 fill $ reflCall "PVTy" [Var (reflm "TT"), Var t']
2109− focus t'; reflectQuotePattern unq t
2225+ focus t'; reflectTTQuotePattern unq t
2110−reflectQuotePattern unq (App f x)
2226+reflectTTQuotePattern unq (App f x)
2111 = do f' <- claimTT (sMN 0 "f"); movelast f'
2227 = do f' <- claimTT (sMN 0 "f"); movelast f'
2112 x' <- claimTT (sMN 0 "x"); movelast x'
2228 x' <- claimTT (sMN 0 "x"); movelast x'
2113 fill $ reflCall "App" [Var f', Var x']
2229 fill $ reflCall "App" [Var f', Var x']
2115− focus f'; reflectQuotePattern unq f
2231+ focus f'; reflectTTQuotePattern unq f
2116− focus x'; reflectQuotePattern unq x
2232+ focus x'; reflectTTQuotePattern unq x
2117−reflectQuotePattern unq (Constant c)
2233+reflectTTQuotePattern unq (Constant c)
2118 = do fill $ reflCall "TConst" [reflectConstant c]
2234 = do fill $ reflCall "TConst" [reflectConstant c]
2120−reflectQuotePattern unq (Proj t i)
2236+reflectTTQuotePattern unq (Proj t i)
2121 = do t' <- claimTT (sMN 0 "t"); movelast t'
2237 = do t' <- claimTT (sMN 0 "t"); movelast t'
2122 fill $ reflCall "Proj" [Var t', RConstant (I i)]
2238 fill $ reflCall "Proj" [Var t', RConstant (I i)]
2124− focus t'; reflectQuotePattern unq t
2240+ focus t'; reflectTTQuotePattern unq t
2125−reflectQuotePattern unq (Erased)
2241+reflectTTQuotePattern unq (Erased)
2126 = do erased <- claimTT (sMN 0 "erased")
2242 = do erased <- claimTT (sMN 0 "erased")
2127 movelast erased
2243 movelast erased
2128 fill $ (Var erased)
2244 fill $ (Var erased)
2130−reflectQuotePattern unq (Impossible)
2246+reflectTTQuotePattern unq (Impossible)
2131 = do fill $ Var (reflm "Impossible")
2247 = do fill $ Var (reflm "Impossible")
2133−reflectQuotePattern unq (TType exp)
2249+reflectTTQuotePattern unq (TType exp)
2134 = do ue <- getNameFrom (sMN 0 "uexp")
2250 = do ue <- getNameFrom (sMN 0 "uexp")
2135 claim ue (Var (sNS (sUN "TTUExp") ["Reflection", "Language"]))
2251 claim ue (Var (sNS (sUN "TTUExp") ["Reflection", "Language"]))
2136 movelast ue
2252 movelast ue
2137 fill $ reflCall "TType" [Var ue]
2253 fill $ reflCall "TType" [Var ue]
2255+reflectTTQuotePattern unq (UType u)
2256+ = do uH <- getNameFrom (sMN 0 "someUniv")
2257+ claim uH (Var (reflm "Universe"))
2259+ fill $ reflCall "UType" [Var uH]
2262+ fill (Var (reflm (case u of
2263+ NullType -> "NullType"
2264+ UniqueType -> "UniqueType"
2265+ AllTypes -> "AllTypes")))
2268+reflectUniverse :: Universe -> Raw
2270+ (Var (reflm (case u of
2271+ NullType -> "NullType"
2272+ UniqueType -> "UniqueType"
2273+ AllTypes -> "AllTypes")))
2140−-- | Create a reflected term, but leave refs to the provided name intact
2275+-- | Create a reflected TT term, but leave refs to the provided name intact
2141−reflectQuote :: [Name] -> Term -> Raw
2276+reflectTTQuote :: [Name] -> Term -> Raw
2142−reflectQuote unq (P nt n t)
2277+reflectTTQuote unq (P nt n t)
2143 | n `elem` unq = Var n
2278 | n `elem` unq = Var n
2144− | otherwise = reflCall "P" [reflectNameType nt, reflectName n, reflectQuote unq t]
2279+ | otherwise = reflCall "P" [reflectNameType nt, reflectName n, reflectTTQuote unq t]
2145−reflectQuote unq (V n)
2280+reflectTTQuote unq (V n)
2146 = reflCall "V" [RConstant (I n)]
2281 = reflCall "V" [RConstant (I n)]
2147−reflectQuote unq (Bind n b x)
2282+reflectTTQuote unq (Bind n b x)
2148− = reflCall "Bind" [reflectName n, reflectBinderQuote unq b, reflectQuote unq x]
2283+ = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote unq b, reflectTTQuote unq x]
2149−reflectQuote unq (App f x)
2284+reflectTTQuote unq (App f x)
2150− = reflCall "App" [reflectQuote unq f, reflectQuote unq x]
2285+ = reflCall "App" [reflectTTQuote unq f, reflectTTQuote unq x]
2151−reflectQuote unq (Constant c)
2286+reflectTTQuote unq (Constant c)
2152 = reflCall "TConst" [reflectConstant c]
2287 = reflCall "TConst" [reflectConstant c]
2153−reflectQuote unq (Proj t i)
2288+reflectTTQuote unq (Proj t i)
2154− = reflCall "Proj" [reflectQuote unq t, RConstant (I i)]
2289+ = reflCall "Proj" [reflectTTQuote unq t, RConstant (I i)]
2155−reflectQuote unq (Erased) = Var (reflm "Erased")
2290+reflectTTQuote unq (Erased) = Var (reflm "Erased")
2156−reflectQuote unq (Impossible) = Var (reflm "Impossible")
2291+reflectTTQuote unq (Impossible) = Var (reflm "Impossible")
2157−reflectQuote unq (TType exp) = reflCall "TType" [reflectUExp exp]
2292+reflectTTQuote unq (TType exp) = reflCall "TType" [reflectUExp exp]
2293+reflectTTQuote unq (UType u) = reflCall "UType" [reflectUniverse u]
2295+reflectRawQuote :: [Name] -> Raw -> Raw
2296+reflectRawQuote unq (Var n)
2297+ | n `elem` unq = Var n
2298+ | otherwise = reflCall "Var" [reflectName n]
2299+reflectRawQuote unq (RBind n b r) =
2300+ reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote unq b, reflectRawQuote unq r]
2301+reflectRawQuote unq (RApp f x) =
2302+ reflCall "RApp" [reflectRawQuote unq f, reflectRawQuote unq x]
2303+reflectRawQuote unq RType = Var (reflm "RType")
2304+reflectRawQuote unq (RUType u) =
2305+ reflCall "RUType" [reflectUniverse u]
2306+reflectRawQuote unq (RForce r) = reflCall "RForce" [reflectRawQuote unq r]
2307+reflectRawQuote unq (RConstant cst) = reflCall "RConstant" [reflectConstant cst]
2159reflectNameType :: NameType -> Raw
2309reflectNameType :: NameType -> Raw
2160reflectNameType (Bound) = Var (reflm "Bound")
2310reflectNameType (Bound) = Var (reflm "Bound")
@@ -2205,27 +2355,27 @@ reflectNameQuotePattern _ -- for all other names, match any
2207reflectBinder :: Binder Term -> Raw
2357reflectBinder :: Binder Term -> Raw
2208−reflectBinder = reflectBinderQuote []
2358+reflectBinder = reflectBinderQuote reflectTTQuote []
2210−reflectBinderQuote :: [Name] -> Binder Term -> Raw
2360+reflectBinderQuote :: ([Name] -> a -> Raw) -> [Name] -> Binder a -> Raw
2211−reflectBinderQuote unq (Lam t)
2361+reflectBinderQuote q unq (Lam t)
2212− = reflCall "Lam" [Var (reflm "TT"), reflectQuote unq t]
2362+ = reflCall "Lam" [Var (reflm "TT"), q unq t]
2213−reflectBinderQuote unq (Pi _ t k)
2363+reflectBinderQuote q unq (Pi _ t k)
2214− = reflCall "Pi" [Var (reflm "TT"), reflectQuote unq t, reflectQuote unq k]
2364+ = reflCall "Pi" [Var (reflm "TT"), q unq t, q unq k]
2215−reflectBinderQuote unq (Let x y)
2365+reflectBinderQuote q unq (Let x y)
2216− = reflCall "Let" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2366+ = reflCall "Let" [Var (reflm "TT"), q unq x, q unq y]
2217−reflectBinderQuote unq (NLet x y)
2367+reflectBinderQuote q unq (NLet x y)
2218− = reflCall "NLet" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2368+ = reflCall "NLet" [Var (reflm "TT"), q unq x, q unq y]
2219−reflectBinderQuote unq (Hole t)
2369+reflectBinderQuote q unq (Hole t)
2220− = reflCall "Hole" [Var (reflm "TT"), reflectQuote unq t]
2370+ = reflCall "Hole" [Var (reflm "TT"), q unq t]
2221−reflectBinderQuote unq (GHole _ t)
2371+reflectBinderQuote q unq (GHole _ t)
2222− = reflCall "GHole" [Var (reflm "TT"), reflectQuote unq t]
2372+ = reflCall "GHole" [Var (reflm "TT"), q unq t]
2223−reflectBinderQuote unq (Guess x y)
2373+reflectBinderQuote q unq (Guess x y)
2224− = reflCall "Guess" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2374+ = reflCall "Guess" [Var (reflm "TT"), q unq x, q unq y]
2225−reflectBinderQuote unq (PVar t)
2375+reflectBinderQuote q unq (PVar t)
2226− = reflCall "PVar" [Var (reflm "TT"), reflectQuote unq t]
2376+ = reflCall "PVar" [Var (reflm "TT"), q unq t]
2227−reflectBinderQuote unq (PVTy t)
2377+reflectBinderQuote q unq (PVTy t)
2228− = reflCall "PVTy" [Var (reflm "TT"), reflectQuote unq t]
2378+ = reflCall "PVTy" [Var (reflm "TT"), q unq t]
2230mkList :: Raw -> [Raw] -> Raw
2380mkList :: Raw -> [Raw] -> Raw
2231mkList ty [] = RApp (Var (sNS (sUN "Nil") ["List", "Prelude"])) ty
2381mkList ty [] = RApp (Var (sNS (sUN "Nil") ["List", "Prelude"])) ty
@@ -2265,7 +2415,8 @@ reflectConstant ManagedPtrType = Var (reflm "ManagedPtrType")
2265reflectConstant BufferType = Var (reflm "BufferType")
2415reflectConstant BufferType = Var (reflm "BufferType")
2266reflectConstant VoidType = Var (reflm "VoidType")
2416reflectConstant VoidType = Var (reflm "VoidType")
2267reflectConstant Forgot = Var (reflm "Forgot")
2417reflectConstant Forgot = Var (reflm "Forgot")
2268−
2418+reflectConstant WorldType = Var (reflm "WorldType")
2419+reflectConstant TheWorld = Var (reflm "TheWorld")
2270reflectUExp :: UExp -> Raw
2421reflectUExp :: UExp -> Raw
2271reflectUExp (UVar i) = reflCall "UVar" [RConstant (I i)]
2422reflectUExp (UVar i) = reflCall "UVar" [RConstant (I i)]