Skip to content

Commit

Permalink
remove writeFileEnsureLn from the App effect
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Jan 30, 2024
1 parent 4de925e commit dfd5a18
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
3 changes: 0 additions & 3 deletions app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Juvix.Compiler.Pipeline.Root
import Juvix.Compiler.Pipeline.Run
import Juvix.Data.Error qualified as Error
import Juvix.Extra.Paths.Base hiding (rootBuildDir)
import Juvix.Prelude.Base qualified as Prelude
import Juvix.Prelude.Pretty hiding
( Doc,
)
Expand All @@ -20,7 +19,6 @@ data App m a where
ExitMsg :: ExitCode -> Text -> App m a
ExitFailMsg :: Text -> App m a
ExitJuvixError :: JuvixError -> App m a
WriteFileEnsureLn :: Path Abs File -> Text -> App m ()
PrintJuvixError :: JuvixError -> App m ()
AskRoot :: App m Root
AskArgs :: App m RunAppIOArgs
Expand Down Expand Up @@ -67,7 +65,6 @@ reAppIO args@RunAppIOArgs {..} =
FromAppPathFile p -> embed (prepathToAbsFile invDir (p ^. pathPath))
GetMainFile m -> getMainFile' m
FromAppPathDir p -> liftIO (prepathToAbsDir invDir (p ^. pathPath))
WriteFileEnsureLn p txt -> embed @IO (Prelude.writeFileEnsureLn p txt)
RenderStdOut t
| _runAppIOArgsGlobalOptions ^. globalOnlyErrors -> return ()
| otherwise -> embed $ do
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Commands.Base
where

import App
import CommonOptions hiding (writeFileEnsureLn)
import CommonOptions hiding (ensureLn, writeFileEnsureLn)
import GlobalOptions
import Juvix.Compiler.Pipeline
import Juvix.Prelude hiding (writeFileEnsureLn)
import Juvix.Prelude
2 changes: 1 addition & 1 deletion app/Commands/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ writeCoreFile [email protected] {..} = do
Left e -> exitJuvixError e
Right md -> do
let txt = show (Core.ppOutDefault (Core.disambiguateNames md ^. Core.moduleInfoTable))
writeFileEnsureLn coreFile txt
embed @IO $ writeFileEnsureLn coreFile txt
4 changes: 2 additions & 2 deletions app/Commands/Dev/Asm/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ runCommand opts = do
let outputCell = Nockma.TermCell c
outputText = Nockma.ppPrintOpts nockmaOpts outputCell
outfile <- Compile.outputFile opts file
writeFileEnsureLn outfile outputText
embed @IO $ writeFileEnsureLn outfile outputText
_ -> do
case run $ runReader entryPoint $ runError $ asmToMiniC tab of
Left err -> exitJuvixError err
Right C.MiniCResult {..} -> do
buildDir <- askBuildDir
ensureDir buildDir
cFile <- inputCFile file
writeFileEnsureLn cFile _resultCCode
embed @IO $ writeFileEnsureLn cFile _resultCCode
outfile <- Compile.outputFile opts file
Compile.runCommand
opts
Expand Down
12 changes: 6 additions & 6 deletions app/Commands/Dev/Core/Compile/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ runCPipeline pa@PipelineArg {..} = do
entryPoint <- getEntry pa
C.MiniCResult {..} <- getRight (run (runReader entryPoint (runError (coreToMiniC _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] C.MiniCResult))))
cFile <- inputCFile _pipelineArgFile
writeFileEnsureLn cFile _resultCCode
embed @IO $ writeFileEnsureLn cFile _resultCCode
outfile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
Compile.runCommand
_pipelineArgOptions
Expand Down Expand Up @@ -87,7 +87,7 @@ runGebPipeline pa@PipelineArg {..} = do
_lispPackageEntry = "*entry*"
}
Geb.Result {..} <- getRight (run (runReader entryPoint (runError (coreToGeb spec _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] Geb.Result))))
writeFileEnsureLn gebFile _resultCode
embed @IO $ writeFileEnsureLn gebFile _resultCode

runVampIRPipeline ::
forall r.
Expand All @@ -98,7 +98,7 @@ runVampIRPipeline pa@PipelineArg {..} = do
entryPoint <- getEntry pa
vampirFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
VampIR.Result {..} <- getRight (run (runReader entryPoint (runError (coreToVampIR _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] VampIR.Result))))
writeFileEnsureLn vampirFile _resultCode
embed @IO $ writeFileEnsureLn vampirFile _resultCode

runAsmPipeline :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r ()
runAsmPipeline pa@PipelineArg {..} = do
Expand All @@ -111,7 +111,7 @@ runAsmPipeline pa@PipelineArg {..} = do
$ _pipelineArgModule
tab' <- getRight r
let code = Asm.ppPrint tab' tab'
writeFileEnsureLn asmFile code
embed @IO $ writeFileEnsureLn asmFile code

runTreePipeline :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r ()
runTreePipeline pa@PipelineArg {..} = do
Expand All @@ -124,7 +124,7 @@ runTreePipeline pa@PipelineArg {..} = do
$ _pipelineArgModule
tab' <- getRight r
let code = Tree.ppPrint tab' tab'
writeFileEnsureLn treeFile code
embed @IO $ writeFileEnsureLn treeFile code

runNockmaPipeline :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r ()
runNockmaPipeline pa@PipelineArg {..} = do
Expand All @@ -137,4 +137,4 @@ runNockmaPipeline pa@PipelineArg {..} = do
$ _pipelineArgModule
tab' <- getRight r
let code = Nockma.ppSerialize tab'
writeFileEnsureLn nockmaFile code
embed @IO $ writeFileEnsureLn nockmaFile code
6 changes: 3 additions & 3 deletions app/Commands/Dev/Tree/Compile/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runCPipeline pa@PipelineArg {..} = do
. runError @JuvixError
$ treeToMiniC _pipelineArgTable
cFile <- inputCFile _pipelineArgFile
writeFileEnsureLn cFile _resultCCode
embed @IO $ writeFileEnsureLn cFile _resultCCode
outfile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
Compile.runCommand
_pipelineArgOptions
Expand All @@ -82,7 +82,7 @@ runAsmPipeline pa@PipelineArg {..} = do
$ _pipelineArgTable
tab' <- getRight r
let code = Asm.ppPrint tab' tab'
writeFileEnsureLn asmFile code
embed @IO $ writeFileEnsureLn asmFile code

runNockmaPipeline :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r ()
runNockmaPipeline pa@PipelineArg {..} = do
Expand All @@ -95,4 +95,4 @@ runNockmaPipeline pa@PipelineArg {..} = do
$ _pipelineArgTable
tab' <- getRight r
let code = Nockma.ppSerialize tab'
writeFileEnsureLn nockmaFile code
embed @IO $ writeFileEnsureLn nockmaFile code
3 changes: 2 additions & 1 deletion src/Juvix/Prelude/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,5 @@ ensureLn t =
_ -> Text.snoc t '\n'

writeFileEnsureLn :: (MonadMask m, MonadIO m) => Path Abs File -> Text -> m ()
writeFileEnsureLn p = Utf8.writeFile (toFilePath p) . ensureLn
writeFileEnsureLn p = Utf8.writeFile (toFilePath p)
{-# INLINE writeFileEnsureLn #-}

0 comments on commit dfd5a18

Please sign in to comment.