From 21e6e5940ecb462436b8dc94428c5cee5cdc9072 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 27 Sep 2024 16:20:32 -0600 Subject: Add import resolution phase and also add a more abstractions around compliation phases. --- src/Language/Fiddle/Compiler/ConsistencyCheck.hs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Language/Fiddle/Compiler/ConsistencyCheck.hs') diff --git a/src/Language/Fiddle/Compiler/ConsistencyCheck.hs b/src/Language/Fiddle/Compiler/ConsistencyCheck.hs index 90f4aa4..4c708f7 100644 --- a/src/Language/Fiddle/Compiler/ConsistencyCheck.hs +++ b/src/Language/Fiddle/Compiler/ConsistencyCheck.hs @@ -5,7 +5,11 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} -module Language.Fiddle.Compiler.ConsistencyCheck (checkConsistency) where +module Language.Fiddle.Compiler.ConsistencyCheck + ( checkConsistency, + consistencyCheckPhase, + ) +where import Control.Monad (forM, forM_, unless, when) import Control.Monad.Identity (Identity (Identity)) @@ -22,7 +26,10 @@ import qualified Data.Map as Map import Data.Maybe (fromMaybe) import qualified Data.Set as Set import qualified Data.Text as Text +import Data.Void import Data.Word (Word32) +import GHC.TypeError as TypeError +import GHC.TypeLits import Language.Fiddle.Ast import Language.Fiddle.Compiler import Language.Fiddle.Internal.Scopes @@ -44,6 +51,11 @@ type SizeBits = Word32 type SizeBytes = Word32 +consistencyCheckPhase :: + CompilationPhase Expanded Checked +consistencyCheckPhase = + CompilationPhase (const $ return ()) (\() -> checkConsistency) + checkConsistency :: FiddleUnit Expanded I Annot -> Compile () (FiddleUnit Checked I Annot) @@ -52,6 +64,13 @@ checkConsistency = . subCompile (GlobalState mempty) . advanceStage (LocalState mempty) +instance CompilationStage Checked where + type StageAfter Checked = TypeError (TypeError.Text "No stage after Checked") + type StageMonad Checked = Compile GlobalState + type StageState Checked = LocalState + type StageFunctor Checked = Identity + type StageAnnotation Checked = Commented SourceSpan + instance CompilationStage Expanded where type StageAfter Expanded = Checked type StageMonad Expanded = Compile GlobalState @@ -81,6 +100,8 @@ deriving instance AdvanceStage Expanded EnumConstantDecl deriving instance AdvanceStage Expanded PackageBody +deriving instance AdvanceStage Expanded ImportStatement + deriving instance (AdvanceStage Expanded t) => AdvanceStage Expanded (Directed t) instance AdvanceStage Expanded RegisterBody where -- cgit