on master help sign in
Allow Elab scripts to create new metavariables

This is mainly to allow debugging and development using the interactive Elab shell.

commitfc57624070a2d9a328119d5fbabfc5a37c434da5 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateWed 10 Jun 2015, 09:46 (11 years ago) parent42025b0
2 files changed+24−6
libs/prelude/Language/Reflection/Elab.idr+7−1 src/Idris/Elab/Term.hs+17−5
libs/prelude/Language/Reflection/Elab.idr+7−1
@@ -120,7 +120,7 @@ data Elab : Type -> Type where
120120 prim__RecursiveElab : Raw -> Elab () -> Elab (TT, TT)
121121
122122 prim__Debug : {a : Type} -> List ErrorReportPart -> Elab a
123−
123+ prim__Metavar : TTName -> Elab ()
124124
125125-------------
126126-- Public API
@@ -350,6 +350,12 @@ namespace Tactics
350350 debugMessage : (msg : List ErrorReportPart) -> Elab a
351351 debugMessage msg = prim__Debug msg
352352
353+ ||| Create a new top-level metavariable to solve the current hole.
354+ |||
355+ ||| @ name the name for the top-level variable
356+ metavar : (name : TTName) -> Elab ()
357+ metavar name = prim__Metavar name
358+
353359 ||| Recursively invoke the reflected elaborator with some goal.
354360 |||
355361 ||| The result is the final term and its type.
src/Idris/Elab/Term.hs+17−5
@@ -881,15 +881,11 @@ elab ist info emode opts fn tm
881881 -- names which have been used elsewhere in the term, since we
882882 -- won't be able to use them in the resulting application.
883883 let unique_used = getUniqueUsed (tt_ctxt ist) ptm
884− let n' = mkN n
884+ let n' = metavarName (namespace info) n
885885 attack
886886 defer unique_used n'
887887 solve
888888 highlightSource nfc (AnnName n' (Just MetavarOutput) Nothing Nothing)
889− where mkN n@(NS _ _) = n
890− mkN n = case namespace info of
891− Just xs@(_:_) -> sNS n xs
892− _ -> n
893889 elab' ina fc (PProof ts) = do compute; mapM_ (runTac True ist (elabFC info) fn) ts
894890 elab' ina fc (PTactics ts)
895891 | not pattern = do mapM_ (runTac False ist fc fn) ts
@@ -1696,6 +1692,11 @@ case_ ind autoSolve ist fn tm = do
16961692 else casetac (forget val)
16971693 when autoSolve solveAll
16981694
1695+-- | Compute the appropriate name for a top-level metavariable
1696+metavarName :: Maybe [String] -> Name -> Name
1697+metavarName _ n@(NS _ _) = n
1698+metavarName (Just (ns@(_:_))) n = sNS n ns
1699+metavarName _ n = n
16991700
17001701runTactical :: IState -> FC -> Env -> Term -> [String] -> ElabD Term
17011702runTactical ist fc env tm ns = do tm' <- eval tm
@@ -1974,6 +1975,17 @@ runTactical ist fc env tm ns = do tm' <- eval tm
19741975 fmap fst . checkClosed $
19751976 rawPair (Var $ reflm "TT", Var $ reflm "TT")
19761977 (tm', ty')
1978+ | n == tacN "prim__Metavar", [n] <- args
1979+ = do n' <- reifyTTName n
1980+ ctxt <- get_context
1981+ ptm <- get_term
1982+ -- See documentation above in the elab case for PMetavar
1983+ let unique_used = getUniqueUsed ctxt ptm
1984+ let mvn = metavarName (Just ns) n'
1985+ attack
1986+ defer unique_used mvn
1987+ solve
1988+ returnUnit
19771989 | n == tacN "prim__Debug", [ty, msg] <- args
19781990 = do msg' <- eval msg
19791991 parts <- reifyReportParts msg