Safe Haskell | None |
---|---|
Language | Haskell2010 |
Provides translation from a subset of the dynamically typed Fortran syntax (Language.Fortran.AST) to the strongly typed expression language (Language.Fortran.Model).
Synopsis
- type FortranExpr = HFree CoreOp FortranVar
- data Some f where
- type SomeVar = Some FortranVar
- type SomeExpr = Some (PairOf D FortranExpr)
- type SomeType = Some D
- newtype KindSelector = KindSelector {
- selectKind :: Integer -> Maybe Precision
- data FortranSemantics = FortranSemantics {}
- defaultSemantics :: FortranSemantics
- data TranslateEnv = TranslateEnv {}
- defaultTranslateEnv :: TranslateEnv
- data TranslateError
- newtype TranslateT m a = TranslateT {}
- runTranslateT :: (Monad m, MonadFail m) => TranslateT m a -> TranslateEnv -> m (Either TranslateError a)
- translateExpression :: (Monad m, MonadFail m) => Expression (Analysis ann) -> TranslateT m SomeExpr
- translateExpression' :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (FortranExpr a)
- translateCoerceExpression :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (HFree MetaOp FortranExpr a)
- data TypeInfo ann
- typeInfo :: TypeSpec ann -> TypeInfo ann
- translateTypeInfo :: (Monad m, MonadFail m, Show ann) => TypeInfo ann -> TranslateT m SomeType
- fsIntegerKinds :: Lens' FortranSemantics KindSelector
- fsRealKinds :: Lens' FortranSemantics KindSelector
- fsLogicalKinds :: Lens' FortranSemantics KindSelector
- fsCharacterKinds :: Lens' FortranSemantics KindSelector
- fsDoublePrecisionKinds :: Lens' FortranSemantics (Maybe KindSelector)
- teVarsInScope :: Lens' TranslateEnv (Map UniqueName SomeVar)
- teImplicitVars :: Lens' TranslateEnv Bool
- teSemantics :: Lens' TranslateEnv FortranSemantics
- tiSrcSpan :: forall ann. Lens' (TypeInfo ann) SrcSpan
- tiBaseType :: forall ann. Lens' (TypeInfo ann) BaseType
- tiSelectorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann))
- tiSelectorKind :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann))
- tiDeclaratorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann))
- tiDimensionDeclarators :: forall ann. Lens' (TypeInfo ann) (Maybe (AList DimensionDeclarator ann))
- tiAttributes :: forall ann. Lens' (TypeInfo ann) (Maybe (AList Attribute ann))
Types
Fortran Expressions
type FortranExpr = HFree CoreOp FortranVar Source #
The type of strongly-typed Fortran expressions.
Existentials
An existential type containing f a
for some type a
.
type SomeVar = Some FortranVar Source #
A Fortran variable with an existential type.
Semantics
newtype KindSelector Source #
A function mapping numeric kind annotations from Fortran programs to actual
precision, for a particular basic type bt
.
data FortranSemantics Source #
A (currently very incomplete) specification of the semantics of a particular version of Fortran, needed when translating.
defaultSemantics :: FortranSemantics Source #
Kinds
The default semantics has sensible defaults for kind 0 (unspecified). Otherwise, the kind is the number of bytes used for the type's representation. Only power-of-two values up to 8 are valid. Characters only allow single byte precision. Reals only allow 4- or 8-byte precision.
Translation Monad
Environment
data TranslateEnv Source #
In order to translate Fortran expressions, we require some information about the environment. That information is capture in this record.
TranslateEnv | |
|
Instances
Monad m => MonadReader TranslateEnv (TranslateT m) Source # | |
Defined in Language.Fortran.Model.Translate ask :: TranslateT m TranslateEnv # local :: (TranslateEnv -> TranslateEnv) -> TranslateT m a -> TranslateT m a # reader :: (TranslateEnv -> a) -> TranslateT m a # |
Errors
data TranslateError Source #
ErrUnsupportedItem Text | Tried to translate a part of the language that is not (yet) supported. |
ErrBadLiteral | Found a literal value that we didn't know how to translate. May or may not be valid Fortran. |
ErrUnexpectedType Text SomeType SomeType |
|
ErrInvalidOpApplication (Some (Rec D)) | Tried to apply an operator to arguments with the wrong types. |
ErrVarNotInScope Name | Reference to a variable that's not currently in scope |
ErrInvalidKind Text Integer |
|
Instances
Describe TranslateError Source # | |
Defined in Language.Fortran.Model.Translate describe :: TranslateError -> Text Source # | |
Monad m => MonadError TranslateError (TranslateT m) Source # | |
Defined in Language.Fortran.Model.Translate throwError :: TranslateError -> TranslateT m a # catchError :: TranslateT m a -> (TranslateError -> TranslateT m a) -> TranslateT m a # |
Monad
newtype TranslateT m a Source #
Instances
runTranslateT :: (Monad m, MonadFail m) => TranslateT m a -> TranslateEnv -> m (Either TranslateError a) Source #
Translating Expressions
translateExpression :: (Monad m, MonadFail m) => Expression (Analysis ann) -> TranslateT m SomeExpr Source #
Translate an expression with an unknown type. The return value existentially captures the type of the result.
translateExpression' :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (FortranExpr a) Source #
Translate an expression with a known type. Fails if the actual type does not match.
translateCoerceExpression :: (Monad m, MonadFail m) => D a -> Expression (Analysis ann) -> TranslateT m (HFree MetaOp FortranExpr a) Source #
Translate an expression and try to coerce it to a particular type. Fails if the actual type cannot be coerced to the given type.
Translating Types
TypeInfo
The different ways of specifying Fortran types are complicated. This record contains information about all the different things that might contribute to a type.
typeInfo :: TypeSpec ann -> TypeInfo ann Source #
Create a simple TypeInfo
from an TypeSpec
. Many use cases will need
to add more information to fully specify the type.
Translation
translateTypeInfo :: (Monad m, MonadFail m, Show ann) => TypeInfo ann -> TranslateT m SomeType Source #
Convert a TypeInfo
to its corresponding strong type.
Lenses
FortranSemantics
fsIntegerKinds :: Lens' FortranSemantics KindSelector Source #
fsRealKinds :: Lens' FortranSemantics KindSelector Source #
fsLogicalKinds :: Lens' FortranSemantics KindSelector Source #
fsCharacterKinds :: Lens' FortranSemantics KindSelector Source #
fsDoublePrecisionKinds :: Lens' FortranSemantics (Maybe KindSelector) Source #
TranslateEnv
teVarsInScope :: Lens' TranslateEnv (Map UniqueName SomeVar) Source #
teImplicitVars :: Lens' TranslateEnv Bool Source #
teSemantics :: Lens' TranslateEnv FortranSemantics Source #
TypeInfo
tiBaseType :: forall ann. Lens' (TypeInfo ann) BaseType Source #
tiSelectorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #
tiSelectorKind :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #
tiDeclaratorLength :: forall ann. Lens' (TypeInfo ann) (Maybe (Expression ann)) Source #
tiDimensionDeclarators :: forall ann. Lens' (TypeInfo ann) (Maybe (AList DimensionDeclarator ann)) Source #
tiAttributes :: forall ann. Lens' (TypeInfo ann) (Maybe (AList Attribute ann)) Source #