3Description : Coordinates the compilation process.
6Maintainer : The Idris Community.
8{-# LANGUAGE CPP, FlexibleContexts, PatternGuards, TypeSynonymInstances, NamedFieldPuns, MultiWayIf #-}
10module IRTS.Compiler(compile, generate) where
14import Idris.Core.CaseTree
15import Idris.Core.Evaluate
22import IRTS.CodegenCommon
23import IRTS.Defunctionalise
31import Prelude hiding (id, (.))
33import Control.Category
34import Control.Monad.State
36import Data.Maybe (maybe)
37import qualified Data.Map as M
39import qualified Data.Set as S
40import System.Directory
45-- | Compile to simplified forms and return CodegenInfo
46compile :: Codegen -> FilePath -> Maybe Term -> Idris CodegenInfo
47compile codegen f mtm = do
48 logCodeGen 1 "Compiling Output."
49 iReport 2 "Compiling Output."
50 checkMVs -- check for undefined metavariables
51 checkTotality -- refuse to compile if there are totality problems
52 exports <- findExports
53 let rootNames = case mtm of
57 logCodeGen 1 "Running Erasure Analysis"
58 iReport 3 "Running Erasure Analysis"
59 reachableNames <- performUsageAnalysis
60 (rootNames ++ getExpNames exports)
61 maindef <- case mtm of
63 Just tm -> do md <- irMain tm
64 logCodeGen 1 $ "MAIN: " ++ show md
65 return [(sMN 0 "runMain", md)]
66 objs <- getObjectFiles codegen
67 libs <- getLibs codegen
68 flags <- getFlags codegen
69 hdrs <- getHdrs codegen
70 impdirs <- rankedImportDirs f
71 ttDeclarations <- getDeclarations reachableNames
72 defsIn <- mkDecls reachableNames
73 -- if no 'main term' given, generate interface files
74 let iface = case mtm of
78 let defs = defsIn ++ maindef
80 -- Inlined top level LDecl made here
81 let defsInlined = inlineAll defs
82 let defsUniq = map (allocUnique (addAlist defsInlined emptyContext))
85 logCodeGen 1 "Inlining"
87 dumpCases <- getDumpCases
90 Just f -> runIO $ writeFile f (showCaseTrees defsUniq)
92 let (nexttag, tagged) = addTags 65536 (liftAll defsInlined)
93 let ctxtIn = addAlist tagged emptyContext
95 logCodeGen 1 "Defunctionalising"
96 iReport 3 "Defunctionalising"
97 let defuns_in = defunctionalise nexttag ctxtIn
98 logCodeGen 5 $ show defuns_in
99 logCodeGen 1 "Inlining"
101 let defuns = inline defuns_in
102 logCodeGen 5 $ show defuns
103 logCodeGen 1 "Resolving variables for CG"
105 let checked = simplifyDefs defuns (toAlist defuns)
107 dumpDefun <- getDumpDefun
110 Just f -> runIO $ writeFile f (dumpDefuns defuns)
111 triple <- Idris.AbsSyntax.targetTriple
112 cpu <- Idris.AbsSyntax.targetCPU
113 logCodeGen 1 "Generating Code."
114 iReport 2 "Generating Code."
116 OK c -> do return $ CodegenInfo f outty triple cpu
117 hdrs impdirs objs libs flags
118 NONE c (toAlist defuns)
122 where checkMVs = do i <- getIState
123 case map fst (idris_metavars i) \\ primDefs of
125 ms -> do iputStrLn $ "WARNING: There are incomplete holes:\n " ++ show ms
126 iputStrLn "\nEvaluation of any of these will crash at run time."
128 checkTotality = do i <- getIState
129 case idris_totcheckfail i of
131 ((fc, msg):fs) -> ierror . At fc . Msg $ "Cannot compile:\n " ++ msg
133generate :: Codegen -> FilePath -> CodegenInfo -> IO ()
134generate codegen mainmod ir
136 -- Built-in code generators (FIXME: lift these out!)
137 Via _ "c" -> codegenC ir
138 -- Any external code generator
139 Via fm cg -> do input <- case fm of
140 IBCFormat -> return mainmod
142 tempdir <- getTemporaryDirectory
143 (fn, h) <- openTempFile tempdir "idris-cg.json"
147 let cmd = "idris-codegen-" ++ cg
148 args = [input, "-o", outputFile ir] ++ compilerFlags ir
149 exit <- rawSystem cmd (if interfaces ir then "--interface" : args else args)
150 when (exit /= ExitSuccess) $
151 putStrLn ("FAILURE: " ++ show cmd ++ " " ++ show args)
152 Bytecode -> dumpBC (simpleDecls ir) (outputFile ir)
154irMain :: TT Name -> Idris LDecl
156 i <- irTerm (sMN 0 "runMain") M.empty [] tm
157 return $ LFun [] (sMN 0 "runMain") [] (LForce i)
159mkDecls :: [Name] -> Idris [(Name, LDecl)]
162 let ds = filter (\(n, d) -> n `elem` used || isCon d) $ ctxtAlist (tt_ctxt i)
163 decls <- mapM build ds
166getDeclarations :: [Name] -> Idris ([(Name, TTDecl)])
169 let ds = filter (\(n, (d,_,_,_,_,_)) -> n `elem` used || isCon d) $ ((toAlist . definitions . tt_ctxt) i)
172showCaseTrees :: [(Name, LDecl)] -> String
173showCaseTrees = showSep "\n\n" . map showCT . sortBy (comparing defnRank)
175 showCT (n, LFun opts f args lexp)
177 show n ++ " " ++ showSep " " (map show args) ++ " =\n\t"
180 showOpts | Inline `elem` opts = "%inline "
182 showCT (n, LConstructor c t a) = "data " ++ show n ++ " " ++ show a
184 defnRank :: (Name, LDecl) -> String
185 defnRank (n, LFun _ _ _ _) = "1" ++ nameRank n
186 defnRank (n, LConstructor _ _ _) = "2" ++ nameRank n
188 nameRank :: Name -> String
189 nameRank (UN s) = "1" ++ show s
190 nameRank (MN i s) = "2" ++ show s ++ show i
191 nameRank (NS n ns) = "3" ++ concatMap show (reverse ns) ++ nameRank n
192 nameRank (SN sn) = "4" ++ snRank sn
193 nameRank n = "5" ++ show n
195 snRank :: SpecialName -> String
196 snRank (WhereN i n n') = "1" ++ nameRank n' ++ nameRank n ++ show i
197 snRank (ImplementationN n args) = "2" ++ nameRank n ++ concatMap show args
198 snRank (ParentN n s) = "3" ++ nameRank n ++ show s
199 snRank (MethodN n) = "4" ++ nameRank n
200 snRank (CaseN _ n) = "5" ++ nameRank n
201 snRank (ImplementationCtorN n) = "7" ++ nameRank n
202 snRank (WithN i n) = "8" ++ nameRank n ++ show i
204isCon (TyDecl _ _) = True
207build :: (Name, Def) -> Idris (Name, LDecl)
212 let args = map (\x -> sMN x "op") [0..] in
213 return (n, (LFun [] n (take ar args)
214 (LOp op (map LV (take ar args)))))
215 _ -> do def <- mkLDecl n d
216 logCodeGen 3 $ "Compiled " ++ show n ++ " =\n\t" ++ show def
219 | Just (ar, op) <- lookup n (idris_scprims i)
221 | Just ar <- lookup n (S.toList (idris_externs i))
222 = Just (ar, LExternal n)
223 getPrim n i = Nothing
225declArgs args inl n (LLam xs x) = declArgs (args ++ xs) inl n x
226declArgs args inl n x = LFun (if inl then [Inline] else []) n args x
228mkLDecl n (Function tm _)
229 = declArgs [] True n <$> irTerm n M.empty [] tm
231mkLDecl n (CaseOp ci _ _ _ pats cd)
232 = declArgs [] (case_inlinable ci || caseName n) n <$> irTree n args sc
234 (args, sc) = cases_runtime cd
236 -- Always attempt to inline functions arising from 'case' expressions
237 caseName (SN (CaseN _ _)) = True
238 caseName (SN (WithN _ _)) = True
239 caseName (NS n _) = caseName n
242mkLDecl n (TyDecl (DCon tag arity _) _) =
243 LConstructor n tag . length <$> fgetState (cg_usedpos . ist_callgraph n)
245mkLDecl n (TyDecl (TCon t a) _) = return $ LConstructor n (-1) a
246mkLDecl n _ = return $ (declArgs [] True n LNothing) -- postulate, never run
249 { viMethod :: Maybe Name
253type Vars = M.Map Name VarInfo
255irTerm :: Name -> Vars -> [Name] -> Term -> Idris LExp
256irTerm top vs env tm@(App _ f a) = do
260 | n `elem` map fst (idris_metavars ist) \\ primDefs
261 -> return $ LError $ "ABORT: Attempt to evaluate hole " ++ show n
263 | m == txt "mkForeignPrim"
264 -> doForeign vs env (reverse (drop 4 args)) -- drop implicits
266 (P _ (UN u) _, [_, arg])
267 | u == txt "unsafePerformPrimIO"
268 -> irTerm top vs env arg
271 | u == txt "assert_unreachable"
272 -> return $ LError $ "ABORT: Reached an unreachable case in " ++ show top
274 (P _ (UN u) _, [_, msg])
275 | u == txt "idris_crash"
276 -> do msg' <- irTerm top vs env msg
277 return $ LOp LCrash [msg']
279 -- TMP HACK - until we get inlining.
280 (P _ (UN r) _, [_, _, _, _, _, arg])
282 -> irTerm top vs env arg
284 -- 'void' doesn't have any pattern clauses and only gets called on
285 -- erased things in higher order contexts (also a TMP HACK...)
290 -- Laziness, the old way
291 (P _ (UN l) _, [_, arg])
293 -> error "lazy has crept in somehow"
295 (P _ (UN l) _, [_, arg])
297 -> LForce <$> irTerm top vs env arg
299 -- Laziness, the new way
300 (P _ (UN l) _, [_, _, arg])
302 -> LLazyExp <$> irTerm top vs env arg
304 (P _ (UN l) _, [_, _, arg])
306 -> LForce <$> irTerm top vs env arg
308 (P _ (UN a) _, [_, _, _, arg])
309 | a == txt "assert_smaller"
310 -> irTerm top vs env arg
312 (P _ (UN a) _, [_, arg])
313 | a == txt "assert_total"
314 -> irTerm top vs env arg
316 (P _ (UN p) _, [_, arg])
318 -> do arg' <- irTerm top vs env arg
319 return $ LOp LPar [LLazyExp arg']
321 (P _ (UN pf) _, [arg])
322 | pf == txt "prim_fork"
323 -> do arg' <- irTerm top vs env arg
324 return $ LOp LFork [LLazyExp arg']
326 (P _ (UN m) _, [_,size,t])
328 -> irTerm top vs env t
330 (P _ (UN tm) _, [_,t])
331 | tm == txt "trace_malloc"
332 -> irTerm top vs env t -- TODO
334 -- This case is here until we get more general inlining. It's just
335 -- a really common case, and the laziness hurts...
336 (P _ (NS (UN be) [b,p]) _, [_,x,(App _ (App _ (App _ (P _ (UN d) _) _) _) t),
337 (App _ (App _ (App _ (P _ (UN d') _) _) _) e)])
338 | be == txt "ifThenElse"
344 x' <- irTerm top vs env x
345 t' <- irTerm top vs env t
346 e' <- irTerm top vs env e
347 return (LCase Shared x'
348 [LConCase 0 (sNS (sUN "False") ["Bool","Prelude"]) [] e'
349 ,LConCase 1 (sNS (sUN "True" ) ["Bool","Prelude"]) [] t'
353 (P (DCon t arity _) n _, args) -> do
354 detag <- fgetState (opt_detaggable . ist_optimisation n)
355 used <- map fst <$> fgetState (cg_usedpos . ist_callgraph n)
357 let isNewtype = length used == 1 && detag
358 let argsPruned = [a | (i,a) <- zip [0..] args, i `elem` used]
360 -- The following code removes fields from data constructors
361 -- and performs the newtype optimisation.
363 -- The general rule here is:
364 -- Everything we get as input is not touched by erasure,
365 -- so it conforms to the official arities and types
366 -- and we can reason about it like it's plain TT.
368 -- It's only the data that leaves this point that's erased
369 -- and possibly no longer typed as the original TT version.
371 -- Especially, underapplied constructors must yield functions
372 -- even if all the remaining arguments are erased
373 -- (the resulting function *will* be applied, to NULLs).
375 -- This will probably need rethinking when we get erasure from functions.
377 -- "padLams" will wrap our term in LLam-bdas and give us
378 -- the "list of future unerased args" coming from these lambdas.
380 -- We can do whatever we like with the list of unerased args,
381 -- hence it takes a lambda: \unerased_argname_list -> resulting_LExp.
382 let padLams = padLambdas used (length args) arity
384 case compare (length args) arity of
387 GT -> ifail ("overapplied data constructor: " ++ show tm ++
389 "Arity: " ++ show arity ++ "\n" ++
390 "Arguments: " ++ show args ++ "\n" ++
391 "Pruned arguments: " ++ show argsPruned)
395 -> irTerm top vs env (head argsPruned)
397 -- compile Nat-likes as bigints
398 | Just LikeZ <- isLikeNat ist n
399 -> irTerm top vs env $ Constant (BI 0)
401 -- compile Nat-likes as bigints
402 | Just LikeS <- isLikeNat ist n
403 -> irTerm top vs env $
404 App Complete (P Ref (sUN "prim__addBigInt") Erased) (Constant $ BI 1)
406 | otherwise -- not newtype, plain data ctor
407 -> buildApp (LV n) argsPruned
409 -- not saturated, underapplied
410 LT | isNewtype -- newtype
411 , length argsPruned == 1 -- and we already have the value
412 -> padLams . (\tm [] -> tm) -- the [] asserts there are no unerased args
413 <$> irTerm top vs env (head argsPruned)
415 | isNewtype -- newtype but the value is not among args yet
416 -> return . padLams $ \[vn] -> LApp False (LV n) [LV vn]
418 -- compile Nat-likes as bigints
419 | Just LikeS <- isLikeNat ist n
420 -> irTerm top vs env $
421 App Complete (P Ref (sUN "prim__addBigInt") Erased) (Constant $ BI 1)
423 -- not a newtype, just apply to a constructor
425 -> padLams . applyToNames <$> buildApp (LV n) argsPruned
428 (P (TCon t a) n _, args) -> return LNothing
430 -- an external name applied to arguments
431 (P _ n _, args) | S.member (n, length args) (idris_externs ist) -> do
432 LOp (LExternal n) <$> mapM (irTerm top vs env) args
434 -- a name applied to arguments
435 (P _ n _, args) -> do
436 case lookup n (idris_scprims ist) of
437 -- if it's a primitive that is already saturated,
438 -- compile to the corresponding op here already to save work
439 Just (arity, op) | length args == arity
440 -> LOp op <$> mapM (irTerm top vs env) args
442 -- otherwise, just apply the name
443 _ -> applyName n ist args
445 -- turn de bruijn vars into regular named references and try again
446 (V i, args) -> irTerm top vs env $ mkApp (P Bound (env !! i) Erased) args
450 <$> irTerm top vs env f
451 <*> mapM (irTerm top vs env) args
454 buildApp :: LExp -> [Term] -> Idris LExp
455 buildApp e [] = return e
456 buildApp e xs = LApp False e <$> mapM (irTerm top vs env) xs
458 applyToNames :: LExp -> [Name] -> LExp
459 applyToNames tm [] = tm
460 applyToNames tm ns = LApp False tm $ map LV ns
462 padLambdas :: [Int] -> Int -> Int -> ([Name] -> LExp) -> LExp
463 padLambdas used startIdx endSIdx mkTerm
464 = LLam allNames $ mkTerm nonerasedNames
466 allNames = [sMN i "sat" | i <- [startIdx .. endSIdx-1]]
467 nonerasedNames = [sMN i "sat" | i <- [startIdx .. endSIdx-1], i `elem` used]
469 applyName :: Name -> IState -> [Term] -> Idris LExp
470 applyName n ist args =
471 LApp False (LV n) <$> mapM (irTerm top vs env . erase) (zip [0..] args)
474 | i >= arity || i `elem` used = x
477 arity = case fst4 <$> lookupCtxtExact n (definitions . tt_ctxt $ ist) of
478 Just (CaseOp ci ty tys def tot cdefs) -> length tys
479 Just (TyDecl (DCon tag ar _) _) -> ar
480 Just (TyDecl Ref ty) -> length $ getArgTys ty
481 Just (Operator ty ar op) -> ar
482 Just def -> error $ "unknown arity: " ++ show (n, def)
483 Nothing -> 0 -- no definition, probably local name => can't erase anything
485 -- name for purposes of usage info lookup
487 | Just n' <- viMethod =<< M.lookup n vs = n'
490 used = maybe [] (map fst . usedpos) $ lookupCtxtExact uName (idris_callgraph ist)
491 fst4 (x,_,_,_,_,_) = x
493irTerm top vs env (P _ n _) = return $ LV n
494irTerm top vs env (V i)
495 | i >= 0 && i < length env = return $ LV (env!!i)
496 | otherwise = ifail $ "bad de bruijn index: " ++ show i
498irTerm top vs env (Bind n (Lam _ _) sc) = LLam [n'] <$> irTerm top vs (n':env) sc
500 n' = uniqueName n env
502irTerm top vs env (Bind n (Let _ _ v) sc)
503 = LLet n <$> irTerm top vs env v <*> irTerm top vs (n : env) sc
505irTerm top vs env (Bind _ _ _) = return $ LNothing
507irTerm top vs env (Proj t (-1)) = do
508 t' <- irTerm top vs env t
509 return $ LOp (LMinus (ATInt ITBig))
512irTerm top vs env (Proj t i) = LProj <$> irTerm top vs env t <*> pure i
513irTerm top vs env (Constant TheWorld) = return LNothing
514irTerm top vs env (Constant c) = return (LConst c)
515irTerm top vs env (TType _) = return LNothing
516irTerm top vs env Erased = return LNothing
517irTerm top vs env Impossible = return LNothing
519data LikeNat = LikeZ | LikeS
521isLikeNat :: IState -> Name -> Maybe LikeNat
523 | Just cTy <- lookupTyExact cn $ tt_ctxt ist
524 , (P TCon{} tyN _, _) <- unApply $ getRetTy cTy
525 , Just (z, s) <- natLikeCtors tyN cTy
526 = if | cn == z -> Just LikeZ
527 | cn == s -> Just LikeS
528 | otherwise -> Nothing
530 natLikeCtors :: Name -> Type -> Maybe (Name, Name)
531 natLikeCtors tyN cTy = case lookupCtxtExact tyN $ idris_datatypes ist of
532 Just TI{con_names = [z, s]}
533 | 0 <- getUsedCount z
534 , looksLikeS tyN s cTy
537 Just TI{con_names = [s, z]}
538 | 0 <- getUsedCount z
539 , looksLikeS tyN s cTy
544 getUsedCount :: Name -> Int
546 maybe 0 (length . usedpos)
548 $ idris_callgraph ist
550 looksLikeS :: Name -> Name -> Type -> Bool
551 looksLikeS tyN cn cTy
552 | Just [(i, _)] <- fmap usedpos $ lookupCtxtExact cn $ idris_callgraph ist
553 , [recTy] <- [recTy | (j, (_n, recTy)) <- zip [0..] (getArgTys cTy), j == i]
554 , (P TCon{} recTyN _, _) <- unApply recTy
560doForeign :: Vars -> [Name] -> [Term] -> Idris LExp
561doForeign vs env (ret : fname : world : args)
562 = do args' <- mapM splitArg args
563 let fname' = toFDesc fname
564 let ret' = toFDesc ret
565 return $ LForeign ret' fname' args'
567 splitArg tm | (_, [_,_,l,r]) <- unApply tm -- pair, two implicits
568 = do let l' = toFDesc l
569 r' <- irTerm (sMN 0 "__foreignCall") vs env r
571 splitArg _ = ifail $ "Badly formed foreign function call: " ++
572 show (ret : fname : world : args)
575 toFDesc (Constant (Str str)) = FStr str
577 | (P _ n _, []) <- unApply tm = FCon (deNS n)
578 | (P _ n _, as) <- unApply tm = FApp (deNS n) (map toFDesc as)
583doForeign vs env xs = ifail "Badly formed foreign function call"
585irTree :: Name -> [Name] -> SC -> Idris LExp
586irTree top args tree = do
587 logCodeGen 3 $ "Compiling " ++ show args ++ "\n" ++ show tree
588 LLam args <$> irSC top M.empty tree
590irSC :: Name -> Vars -> SC -> Idris LExp
591irSC top vs (STerm t) = irTerm top vs [] t
592irSC top vs (UnmatchedCase str) = return $ LError str
594irSC top vs (ProjCase tm alts) = do
595 tm' <- irTerm top vs [] tm
596 alts' <- mapM (irAlt top vs tm') alts
597 return $ LCase Shared tm' alts'
599-- Transform matching on Delay to applications of Force.
600irSC top vs (Case up n [ConCase (UN delay) i [_, _, n'] sc])
601 | delay == txt "Delay"
602 = do sc' <- irSC top vs sc -- mkForce n' n sc
603 return $ lsubst n' (LForce (LV n)) sc'
605-- There are two transformations in this case:
607-- 1. Newtype-case elimination:
609-- wrap({e1}) -> P({e1}) ==> P({e0})
611-- This is important because newtyped constructors are compiled away entirely
612-- and we need to do that everywhere.
614-- 2. Unused-case elimination (only valid for singleton branches):
616-- C(x,y) -> P[... x,y not used ...]
618-- This is important for runtime because sometimes we case on irrelevant data:
620-- In the example above, {e0} will most probably have been erased
621-- so this vain projection would make the resulting program segfault
622-- because the code generator still emits a PROJECT(...) G-machine instruction.
624-- Hence, we check whether the variables are used at all
625-- and erase the casesplit if they are not.
627irSC top vs (Case up n [alt]) = do
628 replacement <- case alt of
629 ConCase cn a ns sc -> do
630 detag <- fgetState (opt_detaggable . ist_optimisation cn)
631 used <- map fst <$> fgetState (cg_usedpos . ist_callgraph cn)
632 if detag && length used == 1
633 then return . Just $ substSC (ns !! head used) n sc
638 Just sc -> irSC top vs sc
640 alt' <- irAlt top vs (LV n) alt
641 return $ case namesBoundIn alt' `usedIn` subexpr alt' of
642 [] -> subexpr alt' -- strip the unused top-most case
643 _ -> LCase up (LV n) [alt']
645 namesBoundIn :: LAlt -> [Name]
646 namesBoundIn (LConCase cn i ns sc) = ns
647 namesBoundIn (LConstCase c sc) = []
648 namesBoundIn (LDefaultCase sc) = []
650 subexpr :: LAlt -> LExp
651 subexpr (LConCase _ _ _ e) = e
652 subexpr (LConstCase _ e) = e
653 subexpr (LDefaultCase e) = e
655-- FIXME: When we have a non-singleton case-tree of the form
661-- and C is detaggable (the only constructor of the family), we can be sure
662-- that the first branch will be always taken -- so we add special handling
663-- to remove the dead default branch.
665-- If we don't do so and C is newtype-optimisable, we will miss this newtype
666-- transformation and the resulting code will probably segfault.
668-- This work-around is not entirely optimal; the best approach would be
669-- to ensure that such case trees don't arise in the first place.
671irSC top vs (Case up n alts@[ConCase cn a ns sc, DefaultCase sc']) = do
672 detag <- fgetState (opt_detaggable . ist_optimisation cn)
674 then irSC top vs (Case up n [ConCase cn a ns sc])
675 else LCase up (LV n) <$> mapM (irAlt top vs (LV n)) alts
677irSC top vs sc@(Case up n alts) = do
678 -- check that neither alternative needs the newtype optimisation,
680 goneWrong <- or <$> mapM isDetaggable alts
682 $ ifail ("irSC: non-trivial case-match on detaggable data: " ++ show sc)
685 LCase up (LV n) <$> mapM (irAlt top vs (LV n)) alts
687 isDetaggable (ConCase cn _ _ _) = fgetState $ opt_detaggable . ist_optimisation cn
688 isDetaggable _ = return False
690irSC top vs ImpossibleCase = return LNothing
692irAlt :: Name -> Vars -> LExp -> CaseAlt -> Idris LAlt
694-- this leaves out all unused arguments of the constructor
695irAlt top vs tm (ConCase n t args sc) = do
696 likeNat <- isLikeNat <$> getIState <*> pure n
697 used <- map fst <$> fgetState (cg_usedpos . ist_callgraph n)
698 let usedArgs = [a | (i,a) <- zip [0..] args, i `elem` used]
703 sc' <- irSC top vs sc
705 [pv] -> return $ LDefaultCase $ LLet pv
707 (LMinus (ATInt ITBig))
714 _ -> ifail $ "irAlt/LikeS: multiple used args: " ++ show usedArgs
717 Just LikeZ -> LConstCase (BI 0) <$> irSC top vs sc
720 Nothing -> LConCase (-1) n usedArgs <$> irSC top (methodVars `M.union` vs) sc
722 methodVars = case n of
723 SN (ImplementationCtorN interfaceName)
724 -> M.fromList [(v, VI
725 { viMethod = Just $ mkFieldName n i
726 }) | (v,i) <- zip args [0..]]
728 -> M.empty -- not an implementation constructor
730irAlt top vs _ (ConstCase x rhs)
731 | matchable x = LConstCase x <$> irSC top vs rhs
732 | matchableTy x = LDefaultCase <$> irSC top vs rhs
734 matchable (I _) = True
735 matchable (BI _) = True
736 matchable (Ch _) = True
737 matchable (Str _) = True
738 matchable (B8 _) = True
739 matchable (B16 _) = True
740 matchable (B32 _) = True
741 matchable (B64 _) = True
744 matchableTy (AType (ATInt ITNative)) = True
745 matchableTy (AType (ATInt ITBig)) = True
746 matchableTy (AType (ATInt ITChar)) = True
747 matchableTy StrType = True
749 matchableTy (AType (ATInt (ITFixed IT8))) = True
750 matchableTy (AType (ATInt (ITFixed IT16))) = True
751 matchableTy (AType (ATInt (ITFixed IT32))) = True
752 matchableTy (AType (ATInt (ITFixed IT64))) = True
754 matchableTy _ = False
756irAlt top vs tm (SucCase n rhs) = do
757 rhs' <- irSC top vs rhs
758 return $ LDefaultCase (LLet n (LOp (LMinus (ATInt ITBig))
760 LConst (BI 1)]) rhs')
762irAlt top vs _ (ConstCase c rhs)
763 = ifail $ "Can't match on (" ++ show c ++ ")"
765irAlt top vs _ (DefaultCase rhs)
766 = LDefaultCase <$> irSC top vs rhs
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list