on master help sign in
Progress towards defining functions in Tactical
commit7d2893e414976d85fc8d35c7d8f035b3210d11e6 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateThu 2 Apr 2015, 17:24 (12 years ago) parentc74acae
3 files changed+33−5
libs/prelude/Language/Reflection/Tactical.idr+3 src/Idris/ElabTerm.hs+28−2 src/Idris/Reflection.hs+2−3
libs/prelude/Language/Reflection/Tactical.idr+3
@@ -138,6 +138,9 @@ rewriteWith rule = prim__Rewrite rule
138138declareType : TyDecl -> Tactical ()
139139declareType decl = prim__DeclareType decl
140140
141+defineFunction : FunDefn -> Tactical ()
142+defineFunction defun = prim__DefineFunction defun
143+
141144debug : Tactical a
142145debug = prim__Debug Nothing
143146
src/Idris/ElabTerm.hs+28−2
@@ -10,6 +10,7 @@ import Idris.Error
1010import Idris.ProofSearch
1111import Idris.Output (pshow)
1212
13+import Idris.Core.CaseTree (SC, SC'(STerm))
1314import Idris.Core.Elaborate hiding (Tactic(..))
1415import Idris.Core.TT
1516import Idris.Core.Evaluate
@@ -1596,6 +1597,30 @@ runTactical fc env tm = do tm' <- eval tm
15961597
15971598 returnUnit = fmap fst $ get_type_val (Var unitCon)
15981599
1600+ defineFunction :: RFunDefn -> ElabD ()
1601+ defineFunction (RDefineFun n clauses) =
1602+ do ctxt <- get_context
1603+ ty <- maybe (fail "no type decl") return $ lookupTyExact n ctxt
1604+ let info = CaseInfo True True False -- TODO document and figure out
1605+ clauses' <- forM clauses (\(RMkFunClause lhs rhs) ->
1606+ do lhs' <- lift $ check ctxt [] lhs
1607+ rhs' <- lift $ check ctxt [] rhs
1608+ return (fst lhs', fst rhs'))
1609+ trace (show clauses') $ return ()
1610+ set_context $
1611+ addCasedef n (const [])
1612+ info False (STerm Erased)
1613+ True False -- TODO what are these?
1614+ [] [] -- TODO argument types, inaccessible types
1615+ (map Right clauses')
1616+ (map (\(l,r) -> ([], l, r)) clauses')
1617+ (map (\(l,r) -> ([], l, r)) clauses')
1618+ (map (\(l,r) -> ([], l, r)) clauses')
1619+ (map (\(l,r) -> ([], l, r)) clauses')
1620+ ty
1621+ ctxt
1622+ return ()
1623+
15991624 -- | Do a step in the reflected elaborator monad. The input is the
16001625 -- step, the output is the (reflected) term returned.
16011626 runTacTm :: Term -> ElabD Term
@@ -1709,8 +1734,9 @@ runTactical fc env tm = do tm' <- eval tm
17091734 aux <- getAux
17101735 returnUnit
17111736 | n == tacN "prim__DefineFunction", [decl] <- args
1712− = do undefined
1713− undefined
1737+ = do defn <- reifyFunDefn decl
1738+ defineFunction defn
1739+ returnUnit
17141740 | n == tacN "prim__Debug", [ty, msg] <- args
17151741 = do let msg' = fromTTMaybe msg
17161742 case msg' of
src/Idris/Reflection.hs+2−3
@@ -17,7 +17,6 @@ rArgToPArg (RExplicit n _) = PExp 0 [] n Placeholder
1717rArgToPArg (RImplicit n _) = PImp 0 False [] n Placeholder
1818rArgToPArg (RConstraint n _) = PConstraint 0 [] n Placeholder
1919
20−data RFunClause = RMkFunClause Raw Raw
21−
22−data RFunDefn = RDefineFun Name [RFunClause]
20+data RFunClause = RMkFunClause Raw Raw deriving Show
2321
22+data RFunDefn = RDefineFun Name [RFunClause] deriving Show