summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Language/Fiddle/Ast/Internal/SyntaxTree.hs20
-rw-r--r--src/Language/Fiddle/Parser.hs8
2 files changed, 8 insertions, 20 deletions
diff --git a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
index f627f15..9566ab5 100644
--- a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
+++ b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
@@ -17,7 +17,6 @@ module Language.Fiddle.Ast.Internal.SyntaxTree
BitsOffset,
-- Witness Types
Witness (..),
- WitnessType,
-- AST Types
Name (..),
Directive (..),
@@ -60,7 +59,6 @@ import Data.List.NonEmpty hiding (map)
import Data.Text (Text)
import Data.Type.Bool
import Data.Typeable
-import Data.Void (Void)
import Data.Word (Word32)
import GHC.Generics
import Language.Fiddle.Ast.Internal.Instances
@@ -107,22 +105,12 @@ type family NumberType (a :: Stage) :: Type where
type family ImportInterface (stage :: Stage) :: Type where
ImportInterface s = If (s < ImportsResolved) () UnitInterface
--- | A way to disable or enable a subtree type based on a type-level boolean.
+-- | A type which is only constructible if the type-level condition 's' holds.
--
--- This is used over GADT's specific parameterization to allow for deriving
--- generics and reduce boilerplate.
---
--- This is a wrapper type to allow defining instances.
+-- This type is used as a way to enable/disable parts of the syntax tree based
+-- on type level booleans (typically incorporating the compilation 'stage')
data Witness (s :: Bool) where
- Witness :: (WitnessType s) -> Witness s
-
--- | If the type level expression is true, the witness type is the Unit type, if
--- it is false, the witness type is Void, thus making whatever it touches
--- uninhabitable. This is how parts of the AST is enabled or disabled during
--- compilation.
-type family WitnessType (s :: Bool) where
- WitnessType True = ()
- WitnessType False = Void
+ Witness :: Witness True
-- A Name is multiple identifiers separated by dots. It's the way of namespaces
-- to different packages.
diff --git a/src/Language/Fiddle/Parser.hs b/src/Language/Fiddle/Parser.hs
index ef40cc9..b3eed63 100644
--- a/src/Language/Fiddle/Parser.hs
+++ b/src/Language/Fiddle/Parser.hs
@@ -140,7 +140,7 @@ fiddleDeclP = do
PackageDecl (pure ())
<$> name
<*> defer body packageBodyP
- KWUsing -> UsingDecl (Witness ()) <$> name
+ KWUsing -> UsingDecl Witness <$> name
KWLocation -> LocationDecl (pure ()) <$> ident <*> (tok TokEq >> expressionP)
KWBits -> BitsDecl (pure ()) <$> ident <*> (tok TokColon >> bitTypeP)
KWImport -> ImportDecl <$> importStatementP
@@ -182,7 +182,7 @@ objTypeP = do
(ReferencedObjType (pure ()) <$> name)
<|> ( do
t <- bodyTypeP
- AnonymousObjType (Witness ()) <$> defer body (objTypeBodyP t)
+ AnonymousObjType Witness <$> defer body (objTypeBodyP t)
)
exprInParenP :: Pa Expression
@@ -198,7 +198,7 @@ objTypeDeclP =
withMeta $
( do
tok_ KWAssertPos
- AssertPosStatement (Witness ()) <$> exprInParenP
+ AssertPosStatement Witness <$> exprInParenP
)
<|> ( do
tok_ KWReserved
@@ -278,7 +278,7 @@ registerBitsTypeRefP = do
baseTypeRef =
withMeta $
(RegisterBitsJustBits <$> exprInParenP)
- <|> (RegisterBitsAnonymousType (Witness ()) <$> anonymousBitsTypeP)
+ <|> (RegisterBitsAnonymousType Witness <$> anonymousBitsTypeP)
<|> (RegisterBitsReference (pure ()) <$> name)
anonymousBitsTypeP :: Pa AnonymousBitsType