Skip to content

Commit

Permalink
feat: add exePath option to madlib run
Browse files Browse the repository at this point in the history
  • Loading branch information
aboeglin committed May 16, 2024
1 parent 6a9e4fb commit a3ad67f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions compiler/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ run cmd = do
Repl target ->
Repl.start target

Run target path args watchMode ->
runRun target path args watchMode
Run target path args watchMode exePath ->
runRun target path args watchMode exePath

Format path code fix width ->
runFormatter width fix path code
Expand Down
7 changes: 6 additions & 1 deletion compiler/main/Run/CommandLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data Command
, runInput :: FilePath
, runArgs :: [String]
, runWatch :: Bool
, exePath :: FilePath
}
| Package { packageSubCommand :: PackageSubCommand, rebuild :: Bool }
| LanguageServer
Expand Down Expand Up @@ -84,6 +85,10 @@ parseOutput :: Parser FilePath
parseOutput = strOption
(long "output" <> short 'o' <> metavar "OUTPUT" <> help "What path to compile to" <> showDefault <> value "./build/")

parseExePath :: Parser FilePath
parseExePath = strOption
(long "exe-path" <> metavar "EXECUTABLE PATH" <> help "What path the exe file should be compiled to, works only for llvm target" <> showDefault <> value "./build/run")

parseVerbose :: Parser Bool
parseVerbose = switch (long "verbose" <> short 'v' <> help "Verbose output" <> showDefault)

Expand Down Expand Up @@ -243,7 +248,7 @@ parseRunArguments = many
)

parseRun :: Parser Command
parseRun = Run <$> parseLimitedTarget <*> parseRunInput <*> parseRunArguments <*> parseWatch
parseRun = Run <$> parseLimitedTarget <*> parseRunInput <*> parseRunArguments <*> parseWatch <*> parseExePath


parseFolder :: Parser FilePath
Expand Down
15 changes: 7 additions & 8 deletions compiler/main/Run/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ import System.Console.ANSI
import GHC.IO (unsafePerformIO)


runRun :: Target -> FilePath -> [String] -> Bool -> IO ()
runRun target input args watchMode = do
runRun :: Target -> FilePath -> [String] -> Bool -> FilePath -> IO ()
runRun target input args watchMode exePath = do
if ".mad" `isSuffixOf` input then do
runModule target input args watchMode
runModule target input args watchMode exePath
else do
let packagePath = joinPath ["madlib_modules", input]
let packageMadlibDotJsonPath = joinPath [packagePath, "madlib.json"]
Expand All @@ -61,19 +61,18 @@ runRun target input args watchMode = do

Right MadlibDotJson.MadlibDotJson { MadlibDotJson.bin = Just bin } -> do
let exePath = joinPath [packagePath, bin]
runModule target exePath args watchMode
runModule target exePath args watchMode exePath

runFolder :: FilePath
runFolder = "build/"


runModule :: Target -> FilePath -> [String] -> Bool -> IO ()
runModule target input args watchMode = do
runModule :: Target -> FilePath -> [String] -> Bool -> FilePath -> IO ()
runModule target input args watchMode exePath = do
canEntrypoint <- canonicalizePath input
canCurrentFolder <- canonicalizePath "./"
rootPath <- canonicalizePath "./"

let llvmOutputPath = runFolder <> "run"
let llvmOutputPath = exePath
let jsOutputPath = joinPath [runFolder, dropFileName input, (takeBaseName . takeFileName $ input) <> ".mjs"]

canonicalOutputPath <-
Expand Down

0 comments on commit a3ad67f

Please # to comment.