mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 04:27:55 +03:00
Can set the compiler and make it echo its command.
This commit is contained in:
parent
ee17b3622b
commit
26815686a8
@ -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]
|
||||
|
14
src/Eval.hs
14
src/Eval.hs
@ -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
|
||||
|
20
src/Obj.hs
20
src/Obj.hs
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user