@@ -50,6 +50,7 @@ import IRTS.CodegenCommon
50import IRTS.System
50import IRTS.System
52import Data.List.Split (splitOn)
52import Data.List.Split (splitOn)
53+import Data.List (groupBy)
53import qualified Data.Text as T
54import qualified Data.Text as T
55import Text.Trifecta.Result(Result(..))
56import Text.Trifecta.Result(Result(..))
@@ -663,25 +664,55 @@ process h fn (Eval t)
663 tyDoc = pprintDelab ist ty'
664 tyDoc = pprintDelab ist ty'
664 ihPrintTermWithType h tmDoc tyDoc
665 ihPrintTermWithType h tmDoc tyDoc
666−process h fn (NewDefn fc (tyDecl:decls))
667+
668+process h fn (NewDefn decls) = logLvl 3 ("Defining names using these decls: " ++ show namedGroups) >> mapM_ defineName namedGroups where
669+ namedGroups = groupBy (\d1 d2 -> getName d1 == getName d2) decls
670+ getName :: PDecl -> Maybe Name
671+ getName (PTy docs argdocs syn fc opts name ty) = Just name
672+ getName (PClauses fc opts name (clause:clauses)) = Just (getClauseName clause)
674+ -- getClauseName is partial and I am not sure it's used safely! -- trillioneyes
675+ getClauseName (PClause fc name whole with rhs whereBlock) = name
676+ getClauseName (PWith fc name whole with rhs whereBlock) = name
677+ defineName :: [PDecl] -> Idris ()
678+ defineName (tyDecl@(PTy docs argdocs syn fc opts name ty) : decls) = do
679+ elabDecl EAll toplevel tyDecl
680+ elabClauses toplevel fc opts name (concatMap getClauses decls)
681+ defineName [PClauses fc opts _ [clause]] = do
682+ let pterm = getRHS clause
683+ (tm,ty) <- elabVal toplevel False pterm
685+ let tm' = force (normaliseAll ctxt [] tm)
686+ let ty' = force (normaliseAll ctxt [] ty)
687+ updateContext (addCtxtDef (getClauseName clause) (Function ty' tm'))
688+ getClauses (PClauses fc opts name clauses) = clauses
690+ getRHS :: PClause -> PTerm
691+ getRHS (PClause fc name whole with rhs whereBlock) = rhs
692+ getRHS (PWith fc name whole with rhs whereBlock) = rhs
693+ getRHS (PClauseR fc with rhs whereBlock) = rhs
694+ getRHS (PWithR fc with rhs whereBlock) = rhs
667− | isTyDecl tyDecl = do
696+-- process h fn (NewDefn (tyDecl:decls)) | isTyDecl tyDecl = do
668− elabDecl EAll toplevel tyDecl
697+-- elabDecl EAll toplevel tyDecl
669− name <- getName tyDecl
698+-- (name, fc) <- getInfo tyDecl
670− logLvl 3 $ "Defining " ++ show name ++ " with this type decl: " ++ show tyDecl
699+-- logLvl 3 $ "Defining " ++ show name ++ " with this type decl: " ++ show tyDecl
671− logLvl 5 $ "Using this definition: " ++ show decls
700+-- logLvl 5 $ "Using this definition: " ++ show decls
672− elabClauses toplevel fc [] name defn
701+-- elabClauses toplevel fc [] name defn
673− where getName (PTy docs argdocs syn fc opts name ty) = return name
702+-- where getInfo (PTy docs argdocs syn fc opts name ty) = return (name, fc)
674− getName _ = fail "New definitions must begin with a type declaration"
703+-- getInfo _ = fail "New definitions must begin with a type declaration"
675− isTyDecl PTy{} = True
704+-- isTyDecl PTy{} = True
676− isTyDecl _ = False
705+-- isTyDecl _ = False
677− defn = concatMap getClauses decls
706+-- defn = concatMap getClauses decls
678− getClauses (PClauses fc opts name clauses) = clauses
707+-- getClauses (PClauses fc opts name clauses) = clauses
679− getClauses _ = []
708+-- getClauses _ = []
710+-- process h fn (NewDefn [PCAF fc name val])
680− -- = do (tm, ty) <- elabVal toplevel False val
711+-- = do (tm, ty) <- elabVal toplevel False val
681− -- ctxt <- getContext
712+-- ctxt <- getContext
682− -- let tm' = force (normaliseAll ctxt [] tm)
713+-- let tm' = force (normaliseAll ctxt [] tm)
683− -- let ty' = force (normaliseAll ctxt [] ty)
714+-- let ty' = force (normaliseAll ctxt [] ty)
684− -- updateContext (addCtxtDef name (Function ty' tm'))
715+-- updateContext (addCtxtDef name (Function ty' tm'))
686process h fn (ExecVal t)
717process h fn (ExecVal t)
687 = do ctxt <- getContext
718 = do ctxt <- getContext