@@ -44,8 +44,7 @@ import System.Directory
44import System.Environment
44import System.Environment
45import System.FilePath ((</>), addTrailingPathSeparator)
45import System.FilePath ((</>), addTrailingPathSeparator)
47−-- | Given a 'main' term to compiler, return the IRs which can be used to
47+-- | Compile to simplified forms and return CodegenInfo
49compile :: Codegen -> FilePath -> Maybe Term -> Idris CodegenInfo
48compile :: Codegen -> FilePath -> Maybe Term -> Idris CodegenInfo
50compile codegen f mtm
49compile codegen f mtm
51 = do checkMVs -- check for undefined metavariables
50 = do checkMVs -- check for undefined metavariables
@@ -74,7 +73,7 @@ compile codegen f mtm
74 Just _ -> False
73 Just _ -> False
76 let defs = defsIn ++ maindef
75 let defs = defsIn ++ maindef
77− -- iputStrLn $ showSep "\n" (map show defs)
76+
78 -- Inlined top level LDecl made here
77 -- Inlined top level LDecl made here
79 let defsInlined = inlineAll defs
78 let defsInlined = inlineAll defs
80 let defsUniq = map (allocUnique (addAlist defsInlined emptyContext))
79 let defsUniq = map (allocUnique (addAlist defsInlined emptyContext))
@@ -90,7 +89,7 @@ compile codegen f mtm
90 let defuns = inline defuns_in
89 let defuns = inline defuns_in
91 logLvl 5 $ show defuns
90 logLvl 5 $ show defuns
92 logLvl 1 "Resolving variables for CG"
91 logLvl 1 "Resolving variables for CG"
93− -- iputStrLn $ showSep "\n" (map show (toAlist defuns))
92+
94 let checked = simplifyDefs defuns (toAlist defuns)
93 let checked = simplifyDefs defuns (toAlist defuns)
95 outty <- outputTy
94 outty <- outputTy
96 dumpCases <- getDumpCases
95 dumpCases <- getDumpCases
@@ -109,13 +108,6 @@ compile codegen f mtm
109 hdrs impdirs objs libs flags
108 hdrs impdirs objs libs flags
110 NONE c (toAlist defuns)
109 NONE c (toAlist defuns)
111 tagged iface exports
110 tagged iface exports
112−-- runIO $ case codegen of
113−-- ViaC -> codegenC cginfo
114−-- ViaJava -> codegenJava cginfo
115−-- ViaJavaScript -> codegenJavaScript cginfo
116−-- ViaNode -> codegenNode cginfo
117−-- ViaLLVM -> codegenLLVM cginfo
118−-- Bytecode -> dumpBC c f
119 Error e -> ierror e
111 Error e -> ierror e
120 where checkMVs = do i <- getIState
112 where checkMVs = do i <- getIState
121 case map fst (idris_metavars i) \\ primDefs of
113 case map fst (idris_metavars i) \\ primDefs of
@@ -125,9 +117,6 @@ compile codegen f mtm
125 case idris_totcheckfail i of
117 case idris_totcheckfail i of
126 [] -> return ()
118 [] -> return ()
127 ((fc, msg):fs) -> ierror . At fc . Msg $ "Cannot compile:\n " ++ msg
119 ((fc, msg):fs) -> ierror . At fc . Msg $ "Cannot compile:\n " ++ msg
128− inDir d h = do let f = d </> h
129− ex <- doesFileExist f
130− if ex then return f else return h
132generate :: Codegen -> FilePath -> CodegenInfo -> IO ()
121generate :: Codegen -> FilePath -> CodegenInfo -> IO ()
133generate codegen mainmod ir
122generate codegen mainmod ir
@@ -136,7 +125,7 @@ generate codegen mainmod ir
136 Via "c" -> codegenC ir
125 Via "c" -> codegenC ir
137 -- Any external code generator
126 -- Any external code generator
138 Via cg -> do let cmd = "idris-codegen-" ++ cg
127 Via cg -> do let cmd = "idris-codegen-" ++ cg
139− args = ["--yes-really", mainmod, "-o", outputFile ir] ++ compilerFlags ir
128+ args = [mainmod, "-o", outputFile ir] ++ compilerFlags ir
140 exit <- rawSystem cmd args
129 exit <- rawSystem cmd args
141 when (exit /= ExitSuccess) $
130 when (exit /= ExitSuccess) $
142 putStrLn ("FAILURE: " ++ show cmd ++ " " ++ show args)
131 putStrLn ("FAILURE: " ++ show cmd ++ " " ++ show args)
@@ -485,75 +474,6 @@ doForeign vs env (ret : fname : world : args)
485 deNS n = n
474 deNS n = n
486doForeign vs env xs = ifail "Badly formed foreign function call"
475doForeign vs env xs = ifail "Badly formed foreign function call"
489− - | (_, (Constant (Str fgnName) : fgnArgTys : ret : [])) <- unApply fgn
490− = case getFTypes fgnArgTys of
491− Nothing -> ifail $ "Foreign type specification is not a constant list: " ++ show (fgn:args)
493− args' <- mapM (irTerm vs env) (init args)
494− return $ LForeign LANG_C (mkIty' ret) fgnName (zip tys args')
496− | otherwise = ifail "Badly formed foreign function call"
498− getFTypes :: TT Name -> Maybe [FType]
499− getFTypes tm = case unApply tm of
500− -- nil : {a : Type} -> List a
501− (nil, [_]) -> Just []
502− -- cons : {a : Type} -> a -> List a -> List a
503− (cons, [_, ty, xs]) -> (mkIty' ty :) <$> getFTypes xs
506− mkIty' (P _ (UN ty) _) = mkIty (str ty)
507− mkIty' (App (P _ (UN fi) _) (P _ (UN intTy) _))
509− = mkIntIty (str intTy)
511− mkIty' (App (App (P _ (UN ff) _) _) (App (P _ (UN fa) _) (App (P _ (UN io) _) _)))
512− | ff == txt "FFunction"
517− mkIty' (App (App (P _ (UN ff) _) _) _)
518− | ff == txt "FFunction"
523− -- would be better if these FInt types were evaluated at compile time
524− -- TODO: add %eval directive for such things
525− -- Issue #1742 on the issue tracker.
526− -- https://github.com/idris-lang/Idris-dev/issues/1742
527− mkIty "FFloat" = FArith ATFloat
528− mkIty "FInt" = mkIntIty "ITNative"
529− mkIty "FChar" = mkIntIty "ITChar"
530− mkIty "FByte" = mkIntIty "IT8"
531− mkIty "FShort" = mkIntIty "IT16"
532− mkIty "FLong" = mkIntIty "IT64"
533− mkIty "FBits8" = mkIntIty "IT8"
534− mkIty "FBits16" = mkIntIty "IT16"
535− mkIty "FBits32" = mkIntIty "IT32"
536− mkIty "FBits64" = mkIntIty "IT64"
537− mkIty "FString" = FString
539− mkIty "FManagedPtr" = FManagedPtr
540− mkIty "FUnit" = FUnit
541− mkIty "FFunction" = FFunction
542− mkIty "FFunctionIO" = FFunctionIO
543− mkIty "FBits8x16" = FArith (ATInt (ITVec IT8 16))
544− mkIty "FBits16x8" = FArith (ATInt (ITVec IT16 8))
545− mkIty "FBits32x4" = FArith (ATInt (ITVec IT32 4))
546− mkIty "FBits64x2" = FArith (ATInt (ITVec IT64 2))
547− mkIty x = error $ "Unknown type " ++ x
549− mkIntIty "ITNative" = FArith (ATInt ITNative)
550− mkIntIty "ITChar" = FArith (ATInt ITChar)
551− mkIntIty "IT8" = FArith (ATInt (ITFixed IT8))
552− mkIntIty "IT16" = FArith (ATInt (ITFixed IT16))
553− mkIntIty "IT32" = FArith (ATInt (ITFixed IT32))
554− mkIntIty "IT64" = FArith (ATInt (ITFixed IT64))
557irTree :: [Name] -> SC -> Idris LExp
477irTree :: [Name] -> SC -> Idris LExp
558irTree args tree = do
478irTree args tree = do
559 logLvl 3 $ "Compiling " ++ show args ++ "\n" ++ show tree
479 logLvl 3 $ "Compiling " ++ show args ++ "\n" ++ show tree