when the "Test suite rlp-test: PASS" hits
i'm like atlas and the world is writing two lines of code
This commit is contained in:
@@ -36,6 +36,7 @@ module Compiler.RLPC
|
||||
, flagDDumpOpts
|
||||
, flagDDumpAST
|
||||
, def
|
||||
, liftErrorful
|
||||
)
|
||||
where
|
||||
----------------------------------------------------------------------------------
|
||||
@@ -47,6 +48,7 @@ import Control.Monad.Errorful
|
||||
import Compiler.RlpcError
|
||||
import Data.Functor.Identity
|
||||
import Data.Default.Class
|
||||
import Data.Foldable
|
||||
import GHC.Generics (Generic)
|
||||
import Data.Hashable (Hashable)
|
||||
import Data.HashSet (HashSet)
|
||||
@@ -54,26 +56,44 @@ import Data.HashSet qualified as S
|
||||
import Data.Coerce
|
||||
import Lens.Micro
|
||||
import Lens.Micro.TH
|
||||
import System.Exit
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
newtype RLPCT m a = RLPCT {
|
||||
runRLPCT :: ReaderT RLPCOptions (ErrorfulT RlpcError m) a
|
||||
}
|
||||
deriving (Functor, Applicative, Monad)
|
||||
|
||||
type RLPC = RLPCT Identity
|
||||
|
||||
type RLPCIO = RLPCT IO
|
||||
|
||||
instance Functor (RLPCT m) where
|
||||
instance Applicative (RLPCT m) where
|
||||
instance Monad (RLPCT m) where
|
||||
evalRLPC :: RLPCOptions
|
||||
-> RLPC a
|
||||
-> (Maybe a, [RlpcError])
|
||||
evalRLPC opt r = runRLPCT r
|
||||
& flip runReaderT opt
|
||||
& runErrorful
|
||||
|
||||
evalRLPC = undefined
|
||||
evalRLPCT :: (Monad m)
|
||||
=> RLPCOptions
|
||||
-> RLPCT m a
|
||||
-> m (Maybe a, [RlpcError])
|
||||
evalRLPCT = undefined
|
||||
evalRLPCIO = undefined
|
||||
|
||||
liftErrorful :: ErrorfulT e m a -> RLPCT m a
|
||||
liftErrorful e = undefined
|
||||
evalRLPCIO :: RLPCOptions -> RLPCIO a -> IO a
|
||||
evalRLPCIO opt r = do
|
||||
(ma,es) <- evalRLPCT opt r
|
||||
putRlpcErrs es
|
||||
case ma of
|
||||
Just x -> pure x
|
||||
Nothing -> die "Failed, no code compiled."
|
||||
|
||||
putRlpcErrs :: [RlpcError] -> IO ()
|
||||
putRlpcErrs = traverse_ print
|
||||
|
||||
liftErrorful :: (Monad m, IsRlpcError e) => ErrorfulT e m a -> RLPCT m a
|
||||
liftErrorful e = RLPCT $ lift (liftRlpcErrors e)
|
||||
|
||||
data RLPCOptions = RLPCOptions
|
||||
{ _rlpcLogFile :: Maybe FilePath
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
|
||||
module Compiler.RlpcError
|
||||
( IsRlpcError(..)
|
||||
, MsgEnvelope(..)
|
||||
@@ -8,11 +9,16 @@ module Compiler.RlpcError
|
||||
, msgSpan
|
||||
, msgDiagnostic
|
||||
, msgSeverity
|
||||
, liftRlpcErrors
|
||||
)
|
||||
where
|
||||
----------------------------------------------------------------------------------
|
||||
import Control.Monad.Errorful
|
||||
import Lens.Micro.TH
|
||||
import Data.Text (Text)
|
||||
import Data.Text qualified as T
|
||||
import GHC.Exts (IsString(..))
|
||||
import Lens.Micro.Platform
|
||||
import Lens.Micro.Platform.Internal
|
||||
----------------------------------------------------------------------------------
|
||||
|
||||
data MsgEnvelope e = MsgEnvelope
|
||||
@@ -21,10 +27,17 @@ data MsgEnvelope e = MsgEnvelope
|
||||
, _msgSeverity :: Severity
|
||||
}
|
||||
|
||||
newtype RlpcError = Text [Text]
|
||||
deriving Show
|
||||
|
||||
instance IsString RlpcError where
|
||||
fromString = Text . pure . T.pack
|
||||
|
||||
class IsRlpcError e where
|
||||
liftRlpcError :: e -> RlpcError
|
||||
|
||||
data RlpcError
|
||||
instance IsRlpcError RlpcError where
|
||||
liftRlpcError = id
|
||||
|
||||
data Severity = SevWarning
|
||||
| SevError
|
||||
@@ -37,3 +50,8 @@ data SrcSpan = SrcSpan
|
||||
|
||||
makeLenses ''MsgEnvelope
|
||||
|
||||
liftRlpcErrors :: (Functor m, IsRlpcError e)
|
||||
=> ErrorfulT e m a
|
||||
-> ErrorfulT RlpcError m a
|
||||
liftRlpcErrors = mapErrorful liftRlpcError
|
||||
|
||||
|
||||
Reference in New Issue
Block a user