core driver
This commit is contained in:
@@ -23,7 +23,7 @@ $ cabal test --test-show-details=direct
|
|||||||
$ rlpc -ddump-eval examples/factorial.hs
|
$ rlpc -ddump-eval examples/factorial.hs
|
||||||
# Compile and evaluate t.hs, with evaluation info dumped to t.log
|
# Compile and evaluate t.hs, with evaluation info dumped to t.log
|
||||||
$ rlpc -ddump-eval -l t.log t.hs
|
$ 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)
|
# (option parsing still must succeed in order to print)
|
||||||
$ rlpc -ddump-opts t.hs
|
$ rlpc -ddump-opts t.hs
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -3,12 +3,15 @@ module CoreDriver
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
import Compiler.RLPC
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
|
import Core.Lex
|
||||||
|
import Core.Parse
|
||||||
|
import GM
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
driver :: RLPCIO ()
|
driver :: RLPCIO ()
|
||||||
driver = undefined
|
driver = forFiles_ $ \f ->
|
||||||
|
withSource f (lexCoreR >=> parseCoreProgR >=> evalProgR)
|
||||||
parseProg :: RLPCOptions
|
|
||||||
-> Text
|
|
||||||
-> (Maybe Program', [MsgEnvelope RlpcError])
|
|
||||||
parseProg o = lexCoreR >=> parseCoreProgR
|
|
||||||
|
|
||||||
|
|||||||
@@ -107,11 +107,3 @@ driver = view rlpcLanguage >>= \case
|
|||||||
LanguageCore -> CoreDriver.driver
|
LanguageCore -> CoreDriver.driver
|
||||||
LanguageRlp -> RlpDriver.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.Lex
|
||||||
, Rlp.Parse.Types
|
, Rlp.Parse.Types
|
||||||
, Compiler.Types
|
, Compiler.Types
|
||||||
|
, Data.Heap
|
||||||
other-modules: Data.Heap
|
|
||||||
, Data.Pretty
|
, Data.Pretty
|
||||||
, Core.Parse
|
, Core.Parse
|
||||||
, Core.Lex
|
, Core.Lex
|
||||||
@@ -86,8 +85,9 @@ library
|
|||||||
executable rlpc
|
executable rlpc
|
||||||
import: warnings
|
import: warnings
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
-- other-modules:
|
other-modules: RlpDriver
|
||||||
-- other-extensions:
|
, CoreDriver
|
||||||
|
|
||||||
build-depends: base >=4.17.0.0 && <4.20.0.0
|
build-depends: base >=4.17.0.0 && <4.20.0.0
|
||||||
, rlp
|
, rlp
|
||||||
, optparse-applicative >= 0.18.1 && < 0.19
|
, optparse-applicative >= 0.18.1 && < 0.19
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ module Compiler.RLPC
|
|||||||
, MsgEnvelope(..), Severity(..)
|
, MsgEnvelope(..), Severity(..)
|
||||||
, addDebugMsg
|
, addDebugMsg
|
||||||
, whenDFlag, whenFFlag
|
, whenDFlag, whenFFlag
|
||||||
|
-- * Misc. Utilities
|
||||||
|
, forFiles_, withSource
|
||||||
-- * Convenient re-exports
|
-- * Convenient re-exports
|
||||||
, addFatal, addWound, def
|
, addFatal, addWound, def
|
||||||
)
|
)
|
||||||
@@ -58,6 +60,7 @@ import Data.HashSet qualified as S
|
|||||||
import Data.Coerce
|
import Data.Coerce
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Text qualified as T
|
import Data.Text qualified as T
|
||||||
|
import Data.Text.IO qualified as T
|
||||||
import Text.ANSI qualified as Ansi
|
import Text.ANSI qualified as Ansi
|
||||||
import Text.PrettyPrint hiding ((<>))
|
import Text.PrettyPrint hiding ((<>))
|
||||||
import Lens.Micro.Platform
|
import Lens.Micro.Platform
|
||||||
@@ -219,3 +222,17 @@ docRlpcErr msg = header
|
|||||||
tshow :: (Show a) => a -> Text
|
tshow :: (Show a) => a -> Text
|
||||||
tshow = T.pack . show
|
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