@@ -191,66 +191,11 @@ ibc i (IBCDyLib n) f = return f {ibc_dynamic_libs = n : ibc_dynamic_libs f }
191ibc i (IBCHeader tgt n) f = return f { ibc_hdrs = (tgt, n) : ibc_hdrs f }
191ibc i (IBCHeader tgt n) f = return f { ibc_hdrs = (tgt, n) : ibc_hdrs f }
192ibc i (IBCDef n) f
192ibc i (IBCDef n) f
193 = do f' <- case lookupDefExact n (tt_ctxt i) of
193 = do f' <- case lookupDefExact n (tt_ctxt i) of
194− Just v -> do -- (v', (f', _)) <- runStateT (updateDef v) (f, length (symbols f))
195− return f { ibc_defs = (n,v) : ibc_defs f }
194+ Just v -> return f { ibc_defs = (n,v) : ibc_defs f }
196 _ -> ifail "IBC write failed"
195 _ -> ifail "IBC write failed"
197 case lookupCtxtExact n (idris_patdefs i) of
196 case lookupCtxtExact n (idris_patdefs i) of
198 Just v -> return f' { ibc_patdefs = (n,v) : ibc_patdefs f }
197 Just v -> return f' { ibc_patdefs = (n,v) : ibc_patdefs f }
199 _ -> return f' -- Not a pattern definition
198 _ -> return f' -- Not a pattern definition
201− updateDef :: Def -> StateT (IBCFile, Int) Idris Def
202− updateDef (CaseOp c t args o s cd)
203− = do o' <- mapM updateOrig o
205− return (CaseOp c t args o' s cd')
206− updateDef t = return t
208− updateOrig (Left t) = do t' <- update t
210− updateOrig (Right (l,r)) = do l' <- update l
212− return (Right (l', r'))
214− updateCD (CaseDefs (ts, t) (cs, c) (is, i) (rs, r))
215− = do c' <- updateSC c; r' <- updateSC r
216− return (CaseDefs (ts, t) (cs, c') (is, i) (rs, r'))
218− updateSC (Case up n alts) = do alts' <- mapM updateAlt alts
219− return (Case up n alts')
220− updateSC (ProjCase t alts) = do t' <- update t
221− alts' <- mapM updateAlt alts
222− return (ProjCase t' alts')
223− updateSC (STerm t) = do t' <- update t
225− updateSC t = return t
227− updateAlt (ConCase n i a sc) = do sc' <- updateSC sc
228− return (ConCase n i a sc')
229− updateAlt (FnCase n a sc) = do sc' <- updateSC sc
230− return (FnCase n a sc')
231− updateAlt (ConstCase i sc) = do sc' <- updateSC sc
232− return (ConstCase i sc')
233− updateAlt (SucCase n sc) = do sc' <- updateSC sc
234− return (SucCase n sc')
235− updateAlt (DefaultCase sc) = do sc' <- updateSC sc
236− return (DefaultCase sc')
238− update (P t n@(MN _ _) ty) = return (P t n ty)
239− update (P t n@(UN _) ty) = return (P t n ty)
240− update (P t n ty) = do (f, len) <- ST.get
241− (i, _) <- lift (addNameIdx n)
243− ST.put (f { symbols = symbols f ++ [n] }, len+1)
244− return (P t (SymRef i) ty)
245− update (App f a) = do f' <- update f; a' <- update a
247− update (Bind n b sc) = do b' <- fmapMB update b
249− return (Bind n b' sc')
250− update (Proj t i) = do t' <- update t
255ibc i (IBCDoc n) f = case lookupCtxtExact n (idris_docstrings i) of
200ibc i (IBCDoc n) f = case lookupCtxtExact n (idris_docstrings i) of
256 Just v -> return f { ibc_docstrings = (n,v) : ibc_docstrings f }
201 Just v -> return f { ibc_docstrings = (n,v) : ibc_docstrings f }
@@ -470,7 +415,7 @@ pPatdefs ds
470pDefs :: Bool -> [Name] -> [(Name, Def)] -> Idris ()
415pDefs :: Bool -> [Name] -> [(Name, Def)] -> Idris ()
471pDefs reexp syms ds
416pDefs reexp syms ds
472 = mapM_ (\ (n, d) ->
417 = mapM_ (\ (n, d) ->
473− do let d' = force d -- (updateDef d)
418+ do d' <- updateDef d
474 case d' of
419 case d' of
475 TyDecl _ _ -> return ()
420 TyDecl _ _ -> return ()
476 _ -> do iLOG $ "SOLVING " ++ show n
421 _ -> do iLOG $ "SOLVING " ++ show n
@@ -483,23 +428,55 @@ pDefs reexp syms ds
483 else iLOG $ "Exporting " ++ show n) ds
428 else iLOG $ "Exporting " ++ show n) ds
485 updateDef (CaseOp c t args o s cd)
430 updateDef (CaseOp c t args o s cd)
431+ = do o' <- mapM updateOrig o
486− = CaseOp c t args (map updateOrig o) s (updateCD cd)
433+ return $ CaseOp c t args o' s cd'
487− updateDef t = t
434+ updateDef t = return t
489− updateOrig (Left t) = Left (update t)
436+ updateOrig (Left t) = liftM Left (update t)
490− updateOrig (Right (l, r)) = Right (update l, update r)
437+ updateOrig (Right (l, r)) = do l' <- update l
439+ return $ Right (l', r')
492 updateCD (CaseDefs (ts, t) (cs, c) (is, i) (rs, r))
441 updateCD (CaseDefs (ts, t) (cs, c) (is, i) (rs, r))
442+ = do t' <- updateSC t
493− = CaseDefs (ts, fmap update t)
446+ return $ CaseDefs (ts, t') (cs, c') (is, i') (rs, r')
494− (cs, fmap update c)
447+
495− (is, fmap update i)
448+ updateSC (Case t n alts) = do alts' <- mapM updateAlt alts
496− (rs, fmap update r)
449+ return (Case t n alts')
497−
450+ updateSC (ProjCase t alts) = do alts' <- mapM updateAlt alts
498− update (P t (SymRef i) ty) = P t (syms!!i) ty
451+ return (ProjCase t alts')
452+ updateSC (STerm t) = do t' <- update t
454+ updateSC c = return c
456+ updateAlt (ConCase n i ns t) = do t' <- updateSC t
457+ return (ConCase n i ns t')
458+ updateAlt (FnCase n ns t) = do t' <- updateSC t
459+ return (FnCase n ns t')
460+ updateAlt (ConstCase c t) = do t' <- updateSC t
461+ return (ConstCase c t')
462+ updateAlt (SucCase n t) = do t' <- updateSC t
463+ return (SucCase n t')
464+ updateAlt (DefaultCase t) = do t' <- updateSC t
465+ return (DefaultCase t')
467+ update (P t n ty) = do n' <- getSymbol n
499− update (App f a) = App (update f) (update a)
469+ update (App f a) = liftM2 App (update f) (update a)
500− update (Bind n b sc) = Bind n (fmap update b) (update sc)
470+ update (Bind n b sc) = do b' <- updateB b
472+ return $ Bind n b' sc'
474+ updateB (Let t v) = liftM2 Let (update t) (update v)
475+ updateB b = do ty' <- update (binderTy b)
476+ return (b { binderTy = ty' })
501− update (Proj t i) = Proj (update t) i
477+ update (Proj t i) = do t' <- update t
502− update t = t
479+ update t = return t
504pDocs :: [(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))] -> Idris ()
481pDocs :: [(Name, (Docstring D.DocTerm, [(Name, Docstring D.DocTerm)]))] -> Idris ()
505pDocs ds = mapM_ (\ (n, a) -> addDocStr n (fst a) (snd a)) ds
482pDocs ds = mapM_ (\ (n, a) -> addDocStr n (fst a) (snd a)) ds