core driver
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
module RlpDriver
|
||||
( driver
|
||||
)
|
||||
where
|
||||
--------------------------------------------------------------------------------
|
||||
import Compiler.RLPC
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
driver :: RLPCIO ()
|
||||
driver = undefined
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user