Skip to content

Commit

Permalink
Handled some unsafeFromRight
Browse files Browse the repository at this point in the history
  • Loading branch information
bezirg committed Jan 11, 2024
1 parent 6d4948f commit 0a31016
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion plutus-core/executables/plutus/AnyProgram/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ readProgram :: SLang s -> File s -> IO (FromLang s)
readProgram sngS fileS = do
bs <- readFileName (fileS^.fName)
case fileS^.fType.fFormat of
Flat_ -> withFlatL sngS $ pure $ unsafeFromRight $ unflat bs
Text -> parseProgram sngS $ T.decodeUtf8Lenient bs
Flat_ -> withFlatL sngS $
case unflat bs of
Left err -> failE $ show err
Right res -> pure res
_ -> failE "not implemented yet"

writeProgram :: (?opts :: Opts)
Expand Down
23 changes: 14 additions & 9 deletions plutus-core/executables/plutus/Mode/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import PlutusPrelude
import Control.Monad
import Prettyprinter

runCompile :: (?opts :: Opts)
=> IO SomeAst
runCompile :: (?opts :: Opts) => IO SomeAst
runCompile = case ?opts of
Opts {_inputs = []} -> failE "No input file given. Use --stdin if you want to read program from stdin. See also --help"
Opts {_output = Nothing} -> failE "No output file given. Use --stdout to write program to stdout"
Expand All @@ -30,17 +29,23 @@ runCompile = case ?opts of

readCompileApply :: (?opts :: Opts)
=> SLang t -> FromLang t -> SomeFile -> IO (FromLang t)
readCompileApply sngT accT someFileS =
readCompile someFileS sngT
>>= pure . unsafeFromRight . applyProgram sngT accT
readCompileApply sngT accT someFileS = do
astT <- readCompile someFileS sngT
case accT `applyTarget` astT of
-- application errors use the annotation type of the target
Left err -> withOrdPrettyA (_sann sngT) $ failE $ show err
Right applied -> pure applied
where
applyTarget = applyProgram sngT

readCompile :: (?opts :: Opts)
=> SomeFile -> SLang t -> IO (FromLang t)
readCompile (SomeFile sngS fileS) sngT = do
when (_verbosity ?opts == VFull) $
printE $ show $ "Compiling" <+> pretty fileS
ast <- readProgram sngS fileS
case compileProgram sngS sngT ast of
Left e -> withOrdPrettyA (_sann sngS) $ failE $ show e
Right r -> pure r
astS <- readProgram sngS fileS
case compileProgram sngS sngT astS of
-- compilation errors use the annotation type of the sources
Left err -> withOrdPrettyA (_sann sngS) $ failE $ show err
Right res -> pure res

0 comments on commit 0a31016

Please sign in to comment.