From 77f2f900d8bfe373aded590a23f7abbc705994e5 Mon Sep 17 00:00:00 2001 From: crumbtoo Date: Thu, 1 Feb 2024 15:24:16 -0700 Subject: [PATCH] core driver --- README.md | 2 +- app/CoreDriver.hs | 15 +++++++++------ app/Main.hs | 8 -------- app/RlpDriver.hs | 11 +++++++++++ rlp.cabal | 8 ++++---- src/Compiler/RLPC.hs | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4b010ec..ef70c2d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ $ cabal test --test-show-details=direct $ rlpc -ddump-eval examples/factorial.hs # Compile and evaluate t.hs, with evaluation info dumped to t.log $ rlpc -ddump-eval -l t.log t.hs -# Print the raw structure describing the compiler options and die +# Print the raw structure describing the compiler options # (option parsing still must succeed in order to print) $ rlpc -ddump-opts t.hs ``` diff --git a/app/CoreDriver.hs b/app/CoreDriver.hs index ba546c9..56ec299 100644 --- a/app/CoreDriver.hs +++ b/app/CoreDriver.hs @@ -3,12 +3,15 @@ module CoreDriver ) where -------------------------------------------------------------------------------- +import Compiler.RLPC +import Control.Monad + +import Core.Lex +import Core.Parse +import GM +-------------------------------------------------------------------------------- driver :: RLPCIO () -driver = undefined - -parseProg :: RLPCOptions - -> Text - -> (Maybe Program', [MsgEnvelope RlpcError]) -parseProg o = lexCoreR >=> parseCoreProgR +driver = forFiles_ $ \f -> + withSource f (lexCoreR >=> parseCoreProgR >=> evalProgR) diff --git a/app/Main.hs b/app/Main.hs index 440789c..ea31543 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -107,11 +107,3 @@ driver = view rlpcLanguage >>= \case LanguageCore -> CoreDriver.driver LanguageRlp -> RlpDriver.driver -forFiles_ :: (Monad m) - => (RLPCOptions -> FilePath -> RLPCT m a) - -> RLPCT m () -forFiles_ k = do - fs <- view rlpcInputFiles - o <- ask - forM_ fs (k o) - diff --git a/app/RlpDriver.hs b/app/RlpDriver.hs index e69de29..3df1b24 100644 --- a/app/RlpDriver.hs +++ b/app/RlpDriver.hs @@ -0,0 +1,11 @@ +module RlpDriver + ( driver + ) + where +-------------------------------------------------------------------------------- +import Compiler.RLPC +-------------------------------------------------------------------------------- + +driver :: RLPCIO () +driver = undefined + diff --git a/rlp.cabal b/rlp.cabal index b813073..daad383 100644 --- a/rlp.cabal +++ b/rlp.cabal @@ -38,8 +38,7 @@ library , Rlp.Lex , Rlp.Parse.Types , Compiler.Types - - other-modules: Data.Heap + , Data.Heap , Data.Pretty , Core.Parse , Core.Lex @@ -86,8 +85,9 @@ library executable rlpc import: warnings main-is: Main.hs - -- other-modules: - -- other-extensions: + other-modules: RlpDriver + , CoreDriver + build-depends: base >=4.17.0.0 && <4.20.0.0 , rlp , optparse-applicative >= 0.18.1 && < 0.19 diff --git a/src/Compiler/RLPC.hs b/src/Compiler/RLPC.hs index 54719a9..5468223 100644 --- a/src/Compiler/RLPC.hs +++ b/src/Compiler/RLPC.hs @@ -33,6 +33,8 @@ module Compiler.RLPC , MsgEnvelope(..), Severity(..) , addDebugMsg , whenDFlag, whenFFlag + -- * Misc. Utilities + , forFiles_, withSource -- * Convenient re-exports , addFatal, addWound, def ) @@ -58,6 +60,7 @@ import Data.HashSet qualified as S import Data.Coerce import Data.Text (Text) import Data.Text qualified as T +import Data.Text.IO qualified as T import Text.ANSI qualified as Ansi import Text.PrettyPrint hiding ((<>)) import Lens.Micro.Platform @@ -219,3 +222,17 @@ docRlpcErr msg = header tshow :: (Show a) => a -> Text tshow = T.pack . show +-------------------------------------------------------------------------------- + +forFiles_ :: (Monad m) + => (FilePath -> RLPCT m a) + -> RLPCT m () +forFiles_ k = do + fs <- view rlpcInputFiles + forM_ fs k + +-- TODO: catch any exceptions, i.e. non-existent files should be handled by the +-- compiler +withSource :: (MonadIO m) => FilePath -> (Text -> RLPCT m a) -> RLPCT m a +withSource f k = liftIO (T.readFile f) >>= k +