things
This commit is contained in:
@@ -89,6 +89,7 @@ library
|
|||||||
DerivingVia
|
DerivingVia
|
||||||
StandaloneDeriving
|
StandaloneDeriving
|
||||||
DerivingStrategies
|
DerivingStrategies
|
||||||
|
BlockArguments
|
||||||
|
|
||||||
executable rlpc
|
executable rlpc
|
||||||
import: warnings
|
import: warnings
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module Compiler.RLPC
|
|||||||
-- ** Lenses
|
-- ** Lenses
|
||||||
, rlpcLogFile, rlpcDFlags, rlpcEvaluator, rlpcInputFiles, rlpcLanguage
|
, rlpcLogFile, rlpcDFlags, rlpcEvaluator, rlpcInputFiles, rlpcLanguage
|
||||||
-- * Misc. MTL-style functions
|
-- * Misc. MTL-style functions
|
||||||
, liftErrorful, hoistRlpcT
|
, liftErrorful, liftMaybe, hoistRlpcT
|
||||||
-- * Misc. Rlpc Monad -related types
|
-- * Misc. Rlpc Monad -related types
|
||||||
, RLPCOptions(RLPCOptions), IsRlpcError(..), RlpcError(..)
|
, RLPCOptions(RLPCOptions), IsRlpcError(..), RlpcError(..)
|
||||||
, MsgEnvelope(..), Severity(..)
|
, MsgEnvelope(..), Severity(..)
|
||||||
@@ -108,6 +108,9 @@ evalRLPCT opt r = runRLPCT r
|
|||||||
liftErrorful :: (Monad m, IsRlpcError e) => ErrorfulT (MsgEnvelope e) m a -> RLPCT m a
|
liftErrorful :: (Monad m, IsRlpcError e) => ErrorfulT (MsgEnvelope e) m a -> RLPCT m a
|
||||||
liftErrorful e = RLPCT $ lift (fmap liftRlpcError `mapErrorful` e)
|
liftErrorful e = RLPCT $ lift (fmap liftRlpcError `mapErrorful` e)
|
||||||
|
|
||||||
|
liftMaybe :: (Monad m) => Maybe a -> RLPCT m a
|
||||||
|
liftMaybe m = RLPCT . lift . ErrorfulT . pure $ (m, [])
|
||||||
|
|
||||||
hoistRlpcT :: (forall a. m a -> n a)
|
hoistRlpcT :: (forall a. m a -> n a)
|
||||||
-> RLPCT m a -> RLPCT n a
|
-> RLPCT m a -> RLPCT n a
|
||||||
hoistRlpcT f rma = RLPCT $ ReaderT $ \opt ->
|
hoistRlpcT f rma = RLPCT $ ReaderT $ \opt ->
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ module Core.Utils
|
|||||||
( programRhss
|
( programRhss
|
||||||
, programGlobals
|
, programGlobals
|
||||||
, isAtomic
|
, isAtomic
|
||||||
-- , insertModule
|
|
||||||
, extractProgram
|
|
||||||
, freeVariables
|
, freeVariables
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
@@ -30,15 +28,6 @@ isAtomic _ = False
|
|||||||
|
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- TODO: export list awareness
|
|
||||||
-- insertModule :: Module b -> Program b -> Program b
|
|
||||||
-- insertModule (Module _ p) = programScDefs %~ (<>m)
|
|
||||||
|
|
||||||
extractProgram :: Module b -> Program b
|
|
||||||
extractProgram (Module _ p) = p
|
|
||||||
|
|
||||||
----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
freeVariables :: Expr' -> Set Name
|
freeVariables :: Expr' -> Set Name
|
||||||
freeVariables = cata go
|
freeVariables = cata go
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ floatNonStrictCases g = goE
|
|||||||
goE e
|
goE e
|
||||||
traverse_ goE altBodies
|
traverse_ goE altBodies
|
||||||
pure e'
|
pure e'
|
||||||
goC (f :$ x) = (:$) <$> goC f <*> goC x
|
goC (App f x) = App <$> goC f <*> goC x
|
||||||
goC (Let r bs e) = Let r <$> bs' <*> goE e
|
goC (Let r bs e) = Let r <$> bs' <*> goE e
|
||||||
where bs' = travBs goC bs
|
where bs' = travBs goC bs
|
||||||
goC (Lit l) = pure (Lit l)
|
goC (Lit l) = pure (Lit l)
|
||||||
@@ -132,6 +132,7 @@ floatNonStrictCases g = goE
|
|||||||
& traverse goC
|
& traverse goC
|
||||||
& const (pure bs)
|
& const (pure bs)
|
||||||
-- ^ ??? what the fuck?
|
-- ^ ??? what the fuck?
|
||||||
|
-- ^ 24/02/22: what is this shit lol?
|
||||||
|
|
||||||
-- when provided with a case expr, floatCase will float the case into a
|
-- when provided with a case expr, floatCase will float the case into a
|
||||||
-- supercombinator of its free variables. the sc is returned along with an
|
-- supercombinator of its free variables. the sc is returned along with an
|
||||||
|
|||||||
41
src/Misc/Lift1.hs
Normal file
41
src/Misc/Lift1.hs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
module Misc.Lift1
|
||||||
|
( Lift1(..)
|
||||||
|
, liftCon, liftCon2, liftCon3
|
||||||
|
, Lift(..)
|
||||||
|
)
|
||||||
|
where
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
import Language.Haskell.TH hiding (Type, Name)
|
||||||
|
import Language.Haskell.TH.Syntax hiding (Type, Name)
|
||||||
|
import Language.Haskell.TH.Syntax qualified as TH
|
||||||
|
import Language.Haskell.TH.Quote
|
||||||
|
import Data.Kind qualified
|
||||||
|
import GHC.Generics
|
||||||
|
|
||||||
|
import Data.Fix
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class Lift1 (f :: Data.Kind.Type -> Data.Kind.Type) where
|
||||||
|
lift1 :: (Quote m, Lift t) => f t -> m Exp
|
||||||
|
|
||||||
|
liftCon :: Quote m => TH.Name -> m Exp -> m Exp
|
||||||
|
liftCon n = fmap (AppE (ConE n))
|
||||||
|
|
||||||
|
liftCon2 :: Quote m => TH.Name -> m Exp -> m Exp -> m Exp
|
||||||
|
liftCon2 n a b = do
|
||||||
|
a' <- a
|
||||||
|
b' <- b
|
||||||
|
pure $ ConE n `AppE` a' `AppE` b'
|
||||||
|
|
||||||
|
liftCon3 :: Quote m => TH.Name -> m Exp -> m Exp -> m Exp -> m Exp
|
||||||
|
liftCon3 n a b c = do
|
||||||
|
a' <- a
|
||||||
|
b' <- b
|
||||||
|
c' <- c
|
||||||
|
pure $ ConE n `AppE` a' `AppE` b' `AppE` c'
|
||||||
|
|
||||||
|
instance Lift1 f => Lift (Fix f) where
|
||||||
|
lift (Fix f) = AppE (ConE 'Fix) <$> lift1 f
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user