Can set the compiler and make it echo its command.

This commit is contained in:
Erik Svedäng 2017-12-12 11:23:59 +01:00
parent ee17b3622b
commit 26815686a8
3 changed files with 34 additions and 6 deletions

View File

@ -29,8 +29,8 @@ import Eval
defaultProject :: Project
defaultProject = Project { projectTitle = "Untitled"
, projectIncludes = [SystemInclude "core.h"]
, projectCFlags = ["-fPIC"]
, projectLibFlags = ["-lm"]
, projectCFlags = [""]
, projectLibFlags = [""]
, projectFiles = []
, projectEchoC = False
, projectCarpDir = "./"
@ -38,6 +38,8 @@ defaultProject = Project { projectTitle = "Untitled"
, projectPrompt = if os == "darwin" then "" else "> "
, projectCarpSearchPaths = []
, projectPrintTypedAST = False
, projectCompiler = "clang -fPIC -lm"
, projectEchoCompilationCommand = False
}
completeKeywords :: Monad m => String -> String -> m [Completion]

View File

@ -813,7 +813,9 @@ commandBuild args =
liftIO $ do putStrLnWithColor Red ("[CODEGEN ERROR] " ++ show err)
return dynamicNil
Right okSrc ->
liftIO $ do let incl = projectIncludesToC proj
liftIO $ do let compiler = projectCompiler proj
echoCompilationCommand = projectEchoCompilationCommand proj
incl = projectIncludesToC proj
includeCorePath = " -I" ++ projectCarpDir proj ++ "/core/ "
switches = " -g "
flags = projectFlags proj ++ includeCorePath ++ switches
@ -824,10 +826,14 @@ commandBuild args =
createDirectoryIfMissing False outDir
writeFile outMain (incl ++ okSrc)
case Map.lookup "main" (envBindings env) of
Just _ -> do callCommand ("clang " ++ outMain ++ " -o " ++ outExe ++ " " ++ flags)
Just _ -> do let cmd = compiler ++ " " ++ outMain ++ " -o " ++ outExe ++ " " ++ flags
when echoCompilationCommand (putStrLn cmd)
callCommand cmd
when (execMode == Repl) (putStrLn ("Compiled to '" ++ outExe ++ "'"))
return dynamicNil
Nothing -> do callCommand ("clang " ++ outMain ++ " -shared -o " ++ outLib ++ " " ++ flags)
Nothing -> do let cmd = compiler ++ " " ++ outMain ++ " -shared -o " ++ outLib ++ " " ++ flags
when echoCompilationCommand (putStrLn cmd)
callCommand cmd
when (execMode == Repl) (putStrLn ("Compiled to '" ++ outLib ++ "'"))
return dynamicNil
@ -1051,6 +1057,8 @@ commandProjectSet [XObj (Str key) _ _, value] =
"search-path" -> return ctx { contextProj = proj { projectCarpSearchPaths = addIfNotPresent valueStr (projectCarpSearchPaths proj) } }
"printAST" -> return ctx { contextProj = proj { projectPrintTypedAST = (valueStr == "true") } }
"echoC" -> return ctx { contextProj = proj { projectEchoC = (valueStr == "true") } }
"echoCompilationCommand" -> return ctx { contextProj = proj { projectEchoCompilationCommand = (valueStr == "true") } }
"compiler" -> return ctx { contextProj = proj { projectCompiler = valueStr } }
_ ->
liftIO $ do putStrLnWithColor Red ("Unrecognized key: '" ++ key ++ "'")
return ctx

View File

@ -568,19 +568,37 @@ data Project = Project { projectTitle :: String
, projectPrompt :: String
, projectCarpSearchPaths :: [FilePath]
, projectPrintTypedAST :: Bool
, projectCompiler :: String
, projectEchoCompilationCommand :: Bool
}
projectFlags :: Project -> String
projectFlags proj = joinWithSpace (projectCFlags proj ++ projectLibFlags proj)
instance Show Project where
show (Project title incl cFlags libFlags srcFiles echoC carpDir outDir prompt searchPaths printTypedAST) =
show (Project
title
incl
cFlags
libFlags
srcFiles
echoC
carpDir
outDir
prompt
searchPaths
printTypedAST
compiler
echoCompilationCommand
) =
unlines [ "Title: " ++ title
, "Compiler: " ++ compiler
, "Includes:\n " ++ joinWith "\n " (map show incl)
, "Cflags:\n " ++ joinWith "\n " cFlags
, "Library flags:\n " ++ joinWith "\n " libFlags
, "Carp source files:\n " ++ joinWith "\n " srcFiles
, "Echo C: " ++ if echoC then "true" else "false"
, "Echo compilation command: " ++ if echoCompilationCommand then "true" else "false"
, "Output directory: " ++ outDir
, "CARP_DIR: " ++ carpDir
, "Prompt: " ++ prompt