diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-10-17 00:36:03 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-10-17 00:36:03 -0600 |
commit | 62dffb99e29eba9004ef2764fbdd9b0462de4742 (patch) | |
tree | 663298cb18eff8f6d7966aba1ec7845d58e19894 /src/Language/Fiddle/Ast/Internal/SyntaxTree.hs | |
parent | c31a34382d6fe1307a0c6fe1710c42f27fe833ca (diff) | |
download | fiddle-62dffb99e29eba9004ef2764fbdd9b0462de4742.tar.gz fiddle-62dffb99e29eba9004ef2764fbdd9b0462de4742.tar.bz2 fiddle-62dffb99e29eba9004ef2764fbdd9b0462de4742.zip |
Add ContExpression syntax tree.
This is for expressions which must be calculatable at compile time.
Diffstat (limited to 'src/Language/Fiddle/Ast/Internal/SyntaxTree.hs')
-rw-r--r-- | src/Language/Fiddle/Ast/Internal/SyntaxTree.hs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs index 5a8aa6d..613dae4 100644 --- a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs +++ b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs @@ -30,6 +30,7 @@ module Language.Fiddle.Ast.Internal.SyntaxTree FiddleUnit (..), Identifier (..), Expression (..), + ConstExpression (..), ImportStatement (..), ImportList (..), FiddleDecl (..), @@ -53,6 +54,7 @@ module Language.Fiddle.Ast.Internal.SyntaxTree mapDirectedM, asDirected, undirected, + trueValue, ) where @@ -284,6 +286,20 @@ data Identifier f a = Identifier } deriving (Generic, Annotated, Alter, Typeable, Walk) +-- | Const expressions are expressions which must be eventually calculated +-- during compilation. This means all the data required to fully calculate the +-- expression must exist at compile time. +data ConstExpression u (s :: Stage) :: SynTree where + ConstExpression :: + { constExpression :: Variant (s .>= Qualified) (N u) (Expression u s f a), + constExpressionAnnot :: a + } -> + ConstExpression u s f a + deriving (Generic, Annotated, Alter, Typeable, Walk) + +trueValue :: (s .>= Qualified ~ True) => ConstExpression u s f a -> N u +trueValue (ConstExpression {constExpression = (LeftV v)}) = v + -- | Expressions used within Fiddle, including literals and variables. data Expression (u :: unit) (s :: Stage) :: SynTree where -- | A numeric literal, whose value is dependent on the compilation stage. @@ -385,7 +401,7 @@ data FiddleDecl :: StagedSynTree where -- | The location identifier. locationIdent :: Identifier f a, -- | The associated expression. - locationExpr :: Expression Address stage f a, + locationExpr :: ConstExpression Address stage f a, -- | Annotation for the location declaration. locationAnnot :: a } -> @@ -462,7 +478,7 @@ data ObjType stage f a where { -- | The type of the array elements. arrayObjType :: ObjType stage f a, -- | The size of the array. - arraySize :: Expression Unitless stage f a, + arraySize :: ConstExpression Unitless stage f a, -- | Annotation for the array type. arrayAnnot :: a } -> @@ -632,7 +648,7 @@ data RegisterBitsTypeRef stage f a where { -- | Reference to the array type. bitsArrayTypeRef :: RegisterBitsTypeRef stage f a, -- | Size of the array. - bitsArraySize :: Expression Unitless stage f a, + bitsArraySize :: ConstExpression Unitless stage f a, -- | Annotation for the array. bitsArrayAnnot :: a } -> |