@@ -5,6 +5,7 @@ module IRTS.Defunctionalise(module IRTS.Defunctionalise,
55
66import IRTS.Lang
77import Idris.Core.TT
8+import Idris.Core.CaseTree
89
910import Debug.Trace
1011import Data.Maybe
@@ -18,7 +19,7 @@ data DExp = DV LVar
1819 | DUpdate Name DExp -- eval expression, then update var with it
1920 | DProj DExp Int
2021 | DC Int Name [DExp]
21− | DCase DExp [DAlt]
22+ | DCase CaseType DExp [DAlt]
2223 | DChkCase DExp [DAlt] -- a case where the type is unknown (for EVAL/APPLY)
2324 | DConst Const
2425 | DForeign FLang FType String [(FType, DExp)]
@@ -105,9 +106,9 @@ addApps defs (n, LFun _ _ args e)
105106 return $ DProj (DUpdate n t') i
106107 aa env (LProj t i) = do t' <- aa env t
107108 return $ DProj t' i
108− aa env (LCase e alts) = do e' <- aa env e
109− alts' <- mapM (aaAlt env) alts
110− return $ DCase e' alts'
109+ aa env (LCase up e alts) = do e' <- aa env e
110+ alts' <- mapM (aaAlt env) alts
111+ return $ DCase up e' alts'
111112 aa env (LConst c) = return $ DConst c
112113 aa env (LForeign l t n args) = liftM (DForeign l t n) (mapM (aaF env) args)
113114 aa env (LOp LFork args) = liftM (DOp LFork) (mapM (aa env) args)
@@ -161,7 +162,7 @@ addApps defs (n, LFun _ _ args e)
161162
162163 needsEval x (DApp _ _ args) = or (map (needsEval x) args)
163164 needsEval x (DC _ _ args) = or (map (needsEval x) args)
164− needsEval x (DCase e alts) = needsEval x e || or (map nec alts)
165+ needsEval x (DCase up e alts) = needsEval x e || or (map nec alts)
165166 where nec (DConCase _ _ _ e) = needsEval x e
166167 nec (DConstCase _ e) = needsEval x e
167168 nec (DDefaultCase e) = needsEval x e
@@ -264,8 +265,11 @@ instance Show DExp where
264265 show' env (DUpdate n e) = "!update " ++ show n ++ "(" ++ show' env e ++ ")"
265266 show' env (DC i n args) = show n ++ ")" ++ showSep ", " (map (show' env) args) ++ ")"
266267 show' env (DProj t i) = show t ++ "!" ++ show i
267− show' env (DCase e alts) = "case " ++ show' env e ++ " of {\n\t" ++
268+ show' env (DCase up e alts) = "case" ++ update ++ show' env e ++ " of {\n\t" ++
268269 showSep "\n\t| " (map (showAlt env) alts)
270+ where update = case up of
271+ Shared -> " "
272+ Updatable -> "! "
269273 show' env (DChkCase e alts) = "case' " ++ show' env e ++ " of {\n\t" ++
270274 showSep "\n\t| " (map (showAlt env) alts)
271275 show' env (DConst c) = show c