diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-10-03 12:28:08 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-10-03 12:29:12 -0600 |
commit | ae5ea355a32eff2b1b1762f4ac2389d94f388df7 (patch) | |
tree | 51f731607fb2d0b4814d07ed9b196c47e1778d32 /src/Language/Fiddle/Compiler/Qualification.hs | |
parent | da5d0ed5b572b1fbff2f9b6c2016b7bd508b43e8 (diff) | |
download | fiddle-ae5ea355a32eff2b1b1762f4ac2389d94f388df7.tar.gz fiddle-ae5ea355a32eff2b1b1762f4ac2389d94f388df7.tar.bz2 fiddle-ae5ea355a32eff2b1b1762f4ac2389d94f388df7.zip |
Add empty qualification stage.
This stage will be responsible for qualifying all types and attaching
necessary metadata to make the job of later stages much easier.
Diffstat (limited to 'src/Language/Fiddle/Compiler/Qualification.hs')
-rw-r--r-- | src/Language/Fiddle/Compiler/Qualification.hs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/Language/Fiddle/Compiler/Qualification.hs b/src/Language/Fiddle/Compiler/Qualification.hs new file mode 100644 index 0000000..146fd61 --- /dev/null +++ b/src/Language/Fiddle/Compiler/Qualification.hs @@ -0,0 +1,88 @@ +-- | Qualification compilation phase. +-- +-- The qualification phase is responsible for resolving all type references in +-- the AST to their fully-qualified counterparts. This process involves +-- replacing unqualified references with their fully-qualified names and +-- attaching the necessary metadata to each reference. This enriched information +-- is then available for use in later stages of the compilation pipeline. +-- +-- In this phase, symbol resolution statements (such as 'using' statements) are +-- removed, as they become unnecessary once references are fully qualified. +-- Additionally, package structures are flattened, and package declarations are +-- discarded since full qualification renders them redundant. +module Language.Fiddle.Compiler.Qualification (qualificationPhase) where + +import Control.Monad.Identity +import Data.Word +import Language.Fiddle.Ast +import Language.Fiddle.Compiler +import Language.Fiddle.Compiler.ConsistencyCheck +import Language.Fiddle.Internal.Scopes +import Language.Fiddle.Internal.UnitInterface +import Language.Fiddle.Types + +type CurrentStage = Expanded + +data GlobalState = GlobalState + { globalScope :: Scope String (Either SizeBits SizeBytes), + fileDependencies :: [FilePath], + unitInterface :: UnitInterface + } + +newtype LocalState = LocalState (ScopePath String) + +type I = Identity + +type Annot = Commented SourceSpan + +type SizeBits = Word32 + +type SizeBytes = Word32 + +instance CompilationStage Expanded where + type StageAfter Expanded = Qualified + type StageMonad Expanded = Compile GlobalState + type StageState Expanded = LocalState + type StageFunctor Expanded = Identity + type StageAnnotation Expanded = Commented SourceSpan + +qualificationPhase :: CompilationPhase Expanded Qualified +qualificationPhase = + pureCompilationPhase $ + fmap snd + . subCompile (GlobalState mempty mempty mempty) + . advanceStage (LocalState mempty) + +deriving instance AdvanceStage CurrentStage ObjTypeBody + +deriving instance AdvanceStage CurrentStage DeferredRegisterBody + +deriving instance AdvanceStage CurrentStage RegisterBody + +deriving instance AdvanceStage CurrentStage AnonymousBitsType + +deriving instance AdvanceStage CurrentStage ImportStatement + +deriving instance AdvanceStage CurrentStage BitType + +deriving instance AdvanceStage CurrentStage EnumBody + +deriving instance AdvanceStage CurrentStage EnumConstantDecl + +deriving instance AdvanceStage CurrentStage RegisterBitsDecl + +deriving instance AdvanceStage CurrentStage PackageBody + +deriving instance AdvanceStage CurrentStage ObjTypeDecl + +deriving instance AdvanceStage CurrentStage FiddleDecl + +deriving instance AdvanceStage CurrentStage FiddleUnit + +deriving instance AdvanceStage CurrentStage Expression + +deriving instance AdvanceStage CurrentStage RegisterBitsTypeRef + +deriving instance AdvanceStage CurrentStage ObjType + +deriving instance (AdvanceStage CurrentStage t) => AdvanceStage CurrentStage (Directed t) |