@@ -88,6 +88,10 @@ addDyLib libs = do i <- getIState
88addHdr :: Codegen -> String -> Idris ()
88addHdr :: Codegen -> String -> Idris ()
89addHdr tgt f = do i <- getIState; putIState $ i { idris_hdrs = nub $ (tgt, f) : idris_hdrs i }
89addHdr tgt f = do i <- getIState; putIState $ i { idris_hdrs = nub $ (tgt, f) : idris_hdrs i }
91+addImported :: FilePath -> Idris ()
92+addImported f = do i <- getIState
93+ putIState $ i { idris_imported = nub $ f : idris_imported i }
91addLangExt :: LanguageExt -> Idris ()
95addLangExt :: LanguageExt -> Idris ()
92addLangExt TypeProviders = do i <- getIState
96addLangExt TypeProviders = do i <- getIState
93 putIState $ i {
97 putIState $ i {
@@ -357,6 +361,9 @@ addNameIdx' i n
357getHdrs :: Codegen -> Idris [String]
361getHdrs :: Codegen -> Idris [String]
358getHdrs tgt = do i <- getIState; return (forCodegen tgt $ idris_hdrs i)
362getHdrs tgt = do i <- getIState; return (forCodegen tgt $ idris_hdrs i)
364+getImported :: Idris [FilePath]
365+getImported = do i <- getIState; return (idris_imported i)
360setErrSpan :: FC -> Idris ()
367setErrSpan :: FC -> Idris ()
361setErrSpan x = do i <- getIState;
368setErrSpan x = do i <- getIState;
362 case (errSpan i) of
369 case (errSpan i) of
@@ -490,6 +497,12 @@ getUndefined :: Idris [Name]
490getUndefined = do i <- getIState
497getUndefined = do i <- getIState
491 return (map fst (idris_metavars i) \\ primDefs)
498 return (map fst (idris_metavars i) \\ primDefs)
500+isMetavarName :: Name -> IState -> Bool
502+ = case lookupNames n (tt_ctxt ist) of
503+ (t:_) -> isJust $ lookup t (idris_metavars ist)
493getWidth :: Idris ConsoleWidth
506getWidth :: Idris ConsoleWidth
494getWidth = fmap idris_consolewidth getIState
507getWidth = fmap idris_consolewidth getIState
@@ -505,155 +518,16 @@ renderWidth = do iw <- getWidth
505 AutomaticWidth -> runIO getScreenWidth
518 AutomaticWidth -> runIO getScreenWidth
508−iRender :: Doc a -> Idris (SimpleDoc a)
509−iRender d = do w <- getWidth
511− let ideSlave = case idris_outputmode ist of
515− InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
516− ColsWide n -> return $
518− then renderPretty 1.0 1000000000 d
519− else renderPretty 0.8 n d
520− AutomaticWidth | ideSlave -> return $ renderPretty 1.0 1000000000 d
521− | otherwise -> do width <- runIO getScreenWidth
522− return $ renderPretty 0.8 width d
524−ihPrintResult :: Handle -> String -> Idris ()
525−ihPrintResult h s = do i <- getIState
526− case idris_outputmode i of
527− RawOutput -> case s of
529− s -> runIO $ hPutStrLn h s
531− let good = SexpList [SymbolAtom "ok", toSExp s] in
532− runIO $ hPutStrLn h $ convSExp "return" good n
534−-- | Write a pretty-printed term to the console with semantic coloring
535−consoleDisplayAnnotated :: Handle -> Doc OutputAnnotation -> Idris ()
536−consoleDisplayAnnotated h output = do ist <- getIState
537− rendered <- iRender $ output
538− runIO . hPutStrLn h .
539− displayDecorated (consoleDecorate ist) $
543−-- | Write pretty-printed output to IDESlave with semantic annotations
544−ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
545−ideSlaveReturnAnnotated n h out = do ist <- getIState
546− (str, spans) <- fmap displaySpans .
548− fmap (fancifyAnnots ist) $
550− let good = [SymbolAtom "ok", toSExp str, toSExp spans]
551− runIO . hPutStrLn h $ convSExp "return" good n
553−ihPrintTermWithType :: Handle -> Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
554−ihPrintTermWithType h tm ty = do ist <- getIState
555− let output = tm <+> colon <+> ty
556− case idris_outputmode ist of
557− RawOutput -> consoleDisplayAnnotated h output
558− IdeSlave n -> ideSlaveReturnAnnotated n h output
560−-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
561−ihPrintFunTypes :: Handle -> [(Name, Bool)] -> Name -> [(Name, PTerm)] -> Idris ()
562−ihPrintFunTypes h bnd n [] = ihPrintError h $ "No such variable " ++ show n
563−ihPrintFunTypes h bnd n overloads = do imp <- impShow
565− let output = vsep (map (uncurry (ppOverload imp)) overloads)
566− case idris_outputmode ist of
567− RawOutput -> consoleDisplayAnnotated h output
568− IdeSlave n -> ideSlaveReturnAnnotated n h output
569− where fullName n = prettyName True bnd n
570− ppOverload imp n tm = fullName n <+> colon <+> align (pprintPTerm imp bnd [] tm)
572−ihRenderResult :: Handle -> Doc OutputAnnotation -> Idris ()
573−ihRenderResult h d = do ist <- getIState
574− case idris_outputmode ist of
575− RawOutput -> consoleDisplayAnnotated h d
576− IdeSlave n -> ideSlaveReturnAnnotated n h d
578−fancifyAnnots :: IState -> OutputAnnotation -> OutputAnnotation
579−fancifyAnnots ist annot@(AnnName n _ _) =
580− do let ctxt = tt_ctxt ist
582− _ | isDConName n ctxt -> AnnName n (Just DataOutput) Nothing
583− _ | isFnName n ctxt -> AnnName n (Just FunOutput) Nothing
584− _ | isTConName n ctxt -> AnnName n (Just TypeOutput) Nothing
585− _ | otherwise -> annot
586−fancifyAnnots _ annot = annot
588type1Doc :: Doc OutputAnnotation
522type1Doc :: Doc OutputAnnotation
589type1Doc = (annotate AnnConstType $ text "Type 1")
523type1Doc = (annotate AnnConstType $ text "Type 1")
591−-- | Show an error with semantic highlighting
592−ihRenderError :: Handle -> Doc OutputAnnotation -> Idris ()
593−ihRenderError h e = do ist <- getIState
594− case idris_outputmode ist of
595− RawOutput -> consoleDisplayAnnotated h e
597− (str, spans) <- fmap displaySpans .
599− fmap (fancifyAnnots ist) $
601− let good = [SymbolAtom "error", toSExp str, toSExp spans]
602− runIO . hPutStrLn h $ convSExp "return" good n
604−ihPrintError :: Handle -> String -> Idris ()
605−ihPrintError h s = do i <- getIState
606− case idris_outputmode i of
607− RawOutput -> case s of
609− s -> runIO $ hPutStrLn h s
611− let good = SexpList [SymbolAtom "error", toSExp s] in
612− runIO . hPutStrLn h $ convSExp "return" good n
614−ihputStrLn :: Handle -> String -> Idris ()
615−ihputStrLn h s = do i <- getIState
616− case idris_outputmode i of
617− RawOutput -> runIO $ hPutStrLn h s
618− IdeSlave n -> runIO . hPutStrLn h $ convSExp "write-string" s n
620−iputStrLn = ihputStrLn stdout
621−iPrintError = ihPrintError stdout
622−iPrintResult = ihPrintResult stdout
623−iWarn = ihWarn stdout
625−ideslavePutSExp :: SExpable a => String -> a -> Idris ()
626−ideslavePutSExp cmd info = do i <- getIState
627− case idris_outputmode i of
628− IdeSlave n -> runIO . putStrLn $ convSExp cmd info n
631−-- this needs some typing magic and more structured output towards emacs
632−iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
633−iputGoal g = do i <- getIState
634− case idris_outputmode i of
635− RawOutput -> runIO $ putStrLn (displayDecorated (consoleDecorate i) g)
636− IdeSlave n -> runIO . putStrLn $
637− convSExp "write-goal" (displayS (fmap (fancifyAnnots i) g) "") n
639isetPrompt :: String -> Idris ()
526isetPrompt :: String -> Idris ()
640isetPrompt p = do i <- getIState
527isetPrompt p = do i <- getIState
641 case idris_outputmode i of
528 case idris_outputmode i of
642 IdeSlave n -> runIO . putStrLn $ convSExp "set-prompt" p n
529 IdeSlave n -> runIO . putStrLn $ convSExp "set-prompt" p n
644−ihWarn :: Handle -> FC -> Doc OutputAnnotation -> Idris ()
645−ihWarn h fc err = do i <- getIState
646− case idris_outputmode i of
648− do err' <- iRender . fmap (fancifyAnnots i) $
649− text (show fc) <> colon <//> err
650− runIO . hPutStrLn h $ displayDecorated (consoleDecorate i) err'
652− do err' <- iRender . fmap (fancifyAnnots i) $ err
653− let (str, spans) = displaySpans err'
654− runIO . hPutStrLn h $
655− convSExp "warning" (fc_fname fc, fc_start fc, fc_end fc, str, spans) n
657setLogLevel :: Int -> Idris ()
531setLogLevel :: Int -> Idris ()
658setLogLevel l = do i <- getIState
532setLogLevel l = do i <- getIState
659 let opts = idris_options i
533 let opts = idris_options i
@@ -1701,8 +1575,6 @@ matchClause' names i x y = checkRpts $ match (fullApp x) (fullApp y) where
1701 = do mf <- match' f f'
1575 = do mf <- match' f f'
1702 ms <- zipWithM matchArg args args'
1576 ms <- zipWithM matchArg args args'
1703 return (mf ++ concat ms)
1577 return (mf ++ concat ms)
1704−-- match (PRef _ n) (PRef _ n') | n == n' = return []
1705−-- | otherwise = Nothing
1706 match (PRef f n) (PApp _ x []) = match (PRef f n) x
1578 match (PRef f n) (PApp _ x []) = match (PRef f n) x
1707 match (PPatvar f n) xr = match (PRef f n) xr
1579 match (PPatvar f n) xr = match (PRef f n) xr
1708 match xr (PPatvar f n) = match xr (PRef f n)
1580 match xr (PPatvar f n) = match xr (PRef f n)
@@ -1712,7 +1584,10 @@ matchClause' names i x y = checkRpts $ match (fullApp x) (fullApp y) where
1712 (not (isConName n (tt_ctxt i) || isFnName n (tt_ctxt i))
1584 (not (isConName n (tt_ctxt i) || isFnName n (tt_ctxt i))
1713 || tm == Placeholder)
1585 || tm == Placeholder)
1714 = return [(n, tm)]
1586 = return [(n, tm)]
1587+ -- if one namespace is missing, drop the other
1715− | n == n' = return []
1588+ | n == n' || n == dropNS n' || dropNS n == n' = return []
1589+ where dropNS (NS n _) = n
1716 match (PRef _ n) tm
1591 match (PRef _ n) tm
1717 | not names && (not (isConName n (tt_ctxt i) ||
1592 | not names && (not (isConName n (tt_ctxt i) ||
1718 isFnName n (tt_ctxt i)) || tm == Placeholder)
1593 isFnName n (tt_ctxt i)) || tm == Placeholder)
@@ -1855,6 +1730,12 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
1855 mkUniqA arg = do t' <- mkUniq (getTm arg)
1730 mkUniqA arg = do t' <- mkUniq (getTm arg)
1856 return (arg { getTm = t' })
1731 return (arg { getTm = t' })
1733+ -- Initialise the unique name with the environment length (so we're not
1734+ -- looking for too long...)
1735+ initN (UN n) l = UN $ txt (str n ++ show l)
1736+ initN (MN i s) l = MN (i+l) s
1858 -- FIXME: Probably ought to do this for completeness! It's fine as
1739 -- FIXME: Probably ought to do this for completeness! It's fine as
1859 -- long as there are no bindings inside tactics though.
1740 -- long as there are no bindings inside tactics though.
1860 mkUniqT tac = return tac
1741 mkUniqT tac = return tac
@@ -1864,7 +1745,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
1864 = do env <- get
1745 = do env <- get
1865 (n', sc') <-
1746 (n', sc') <-
1866 if n `elem` env
1747 if n `elem` env
1867− then do let n' = uniqueName n (env ++ inScope)
1748+ then do let n' = uniqueName (initN n (length env))
1868 return (n', shadow n n' sc)
1750 return (n', shadow n n' sc)
1869 else return (n, sc)
1751 else return (n, sc)
1870 put (n' : env)
1752 put (n' : env)
@@ -1875,7 +1757,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
1875 = do env <- get
1757 = do env <- get
1876 (n', sc') <-
1758 (n', sc') <-
1877 if n `elem` env
1759 if n `elem` env
1878− then do let n' = uniqueName n (env ++ inScope)
1760+ then do let n' = uniqueName (initN n (length env))
1879 return (n', shadow n n' sc)
1762 return (n', shadow n n' sc)
1880 else return (n, sc)
1763 else return (n, sc)
1881 put (n' : env)
1764 put (n' : env)
@@ -1886,7 +1769,8 @@ mkUniqueNames env tm = evalState (mkUniq tm) env where
1886 = do env <- get
1769 = do env <- get
1887 (n', sc') <-
1770 (n', sc') <-
1888 if n `elem` env
1771 if n `elem` env
1889− then do let n' = uniqueName n (env ++ inScope)
1772+ then do let n' = uniqueName (initN n (length env))
1890 return (n', shadow n n' sc)
1774 return (n', shadow n n' sc)
1891 else return (n, sc)
1775 else return (n, sc)
1892 put (n' : env)
1776 put (n' : env)