Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Nov 6, 2023
1 parent 654f60b commit 47ae86b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Concrete/Data/ParsedInfoTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Juvix.Prelude

data InfoTable = InfoTable
{ _infoParsedComments :: Comments,
_infoParsedModules :: HashMap TopModulePath ScopedModule
_infoParsedModules :: HashMap TopModulePath (Either ScopedModule (Module 'Parsed 'ModuleTop))
}

makeLenses ''InfoTable
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Concrete/Data/ParsedInfoTableBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ build :: BuilderState -> InfoTable
build st =
InfoTable
{ _infoParsedComments = mkComments (st ^. stateComments),
_infoParsedModules = st ^. stateModules
_infoParsedModules = fmap Right (st ^. stateModules)
}

registerItem' :: (Members '[HighlightBuilder] r) => ParsedItem -> Sem r ()
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Concrete/Data/Scope/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ newtype ModulesCache = ModulesCache
data ScopeParameters = ScopeParameters
{ -- | Used for import cycle detection.
_scopeTopParents :: [Import 'Parsed],
_scopeParsedModules :: HashMap TopModulePath ScopedModule
_scopeParsedModules :: HashMap TopModulePath (Either ScopedModule (Module 'Parsed 'ModuleTop))
}

data RecordInfo = RecordInfo
Expand All @@ -57,7 +57,7 @@ data RecordInfo = RecordInfo
data ScoperState = ScoperState
{ _scoperModulesCache :: ModulesCache,
-- | Local and top modules
_scoperModules :: HashMap S.ModuleNameId ScopedModuleRef,
_scoperModules :: HashMap S.ModuleNameId ScopedModule,
_scoperScope :: HashMap TopModulePath Scope,
_scoperAlias :: HashMap S.NameId PreSymbolEntry,
_scoperSignatures :: HashMap S.NameId (NameSignature 'Parsed),
Expand Down
3 changes: 0 additions & 3 deletions src/Juvix/Compiler/Concrete/Data/ScopedName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ topModulePathSymbol = over nameConcrete (^. C.modulePathName)
topModulePathName :: TopModulePath -> Name
topModulePathName = over nameConcrete C.topModulePathToName

unConcrete :: Name' a -> Name' (Maybe C.Name)
unConcrete = set nameConcrete Nothing

symbolText :: Symbol -> Text
symbolText s = s ^. nameConcrete . C.symbolText

Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Concrete/Extra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ groupStatements = \case
^. importModule
. scopedModulePath
. S.nameId
== getModuleRefNameId (o ^. openModuleName)
== getScopedModuleNameId (o ^. openModuleName)
(StatementImport _, _) -> False
(StatementOpenModule {}, StatementOpenModule {}) -> True
(StatementOpenModule {}, _) -> False
Expand Down
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Concrete/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type family SymbolType s = res | res -> s where
type ModuleRefType :: Stage -> GHC.Type
type family ModuleRefType s = res | res -> s where
ModuleRefType 'Parsed = Name
ModuleRefType 'Scoped = ScopedModuleRef
ModuleRefType 'Scoped = ScopedModule

type IdentifierType :: Stage -> GHC.Type
type family IdentifierType s = res | res -> s where
Expand Down Expand Up @@ -1108,6 +1108,9 @@ getModuleRefName (ScopedModuleRef (_ :&: ScopedModuleRef' {..})) = _scopedModule
getModuleRefNameId :: ScopedModuleRef -> S.NameId
getModuleRefNameId m = getModuleRefName m ^. S.nameId

getScopedModuleNameId :: ScopedModule -> S.NameId
getScopedModuleNameId m = m ^. scopedModuleName . S.nameId

data OpenModule (s :: Stage) = OpenModule
{ _openModuleName :: ModuleRefType s,
_openModuleParams :: OpenModuleParams s
Expand Down Expand Up @@ -2020,7 +2023,6 @@ instance (SingI s) => HasLoc (AxiomDef s) where
instance HasLoc (OpenModule 'Scoped) where
getLoc m =
getLoc (m ^. openModuleParams . openModuleKw)
<> getLoc (m ^. openModuleName)
<>? fmap getLoc (m ^. openModuleParams . openPublicKw . unIrrelevant)

instance HasLoc (ProjectionDef s) where
Expand Down
21 changes: 5 additions & 16 deletions src/Juvix/Compiler/Concrete/Print/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Juvix.Compiler.Concrete.Extra qualified as Concrete
import Juvix.Compiler.Concrete.Keywords qualified as Kw
import Juvix.Compiler.Concrete.Language
import Juvix.Compiler.Concrete.Pretty.Options
import Juvix.Compiler.Store.Scoped.Language (Alias, ModuleSymbolEntry, PreSymbolEntry (..), SymbolEntry, aliasName, moduleEntry, symbolEntry)
import Juvix.Compiler.Store.Scoped.Language (Alias, ModuleSymbolEntry, PreSymbolEntry (..), ScopedModule, SymbolEntry, aliasName, moduleEntry, scopedModuleName, symbolEntry)
import Juvix.Data.Ape.Base
import Juvix.Data.Ape.Print
import Juvix.Data.CodeAnn (Ann, CodeAnn (..), ppStringLit)
Expand Down Expand Up @@ -466,11 +466,8 @@ instance PrettyPrint QualifiedName where
let symbols = _qualifiedPath ^. pathParts NonEmpty.|> _qualifiedSymbol
dotted (ppSymbolType <$> symbols)

instance (SingI t) => PrettyPrint (ModuleRef'' 'S.NotConcrete t) where
ppCode = ppCode @(ModuleRef' 'S.NotConcrete) . project

instance PrettyPrint (ModuleRef'' 'S.Concrete t) where
ppCode m = ppCode (m ^. moduleRefName)
instance PrettyPrint ScopedModule where
ppCode m = ppCode (m ^. scopedModuleName)

instance PrettyPrint ScopedIden where
ppCode = ppCode . (^. scopedIdenName)
Expand Down Expand Up @@ -1070,16 +1067,8 @@ instance (SingI s) => PrettyPrint (UsingItem s) where
kwmodule = ppCode <$> (ui ^. usingModuleKw)
kwmodule <?+> (sym' <+?> kwAs' <+?> alias')

instance PrettyPrint (ModuleRef' 'S.NotConcrete) where
ppCode (ModuleRef' (t :&: m)) =
let path = m ^. moduleRefModule . modulePath
txt = case t of
SModuleTop -> annotate (AnnKind KNameTopModule) (pretty path)
SModuleLocal -> annotate (AnnKind KNameLocalModule) (pretty path)
in noLoc txt

instance PrettyPrint ModuleRef where
ppCode (ModuleRef' (_ :&: ModuleRef'' {..})) = ppCode _moduleRefName
instance PrettyPrint ScopedModuleRef where
ppCode (ScopedModuleRef (_ :&: ScopedModuleRef' {..})) = ppCode (_scopedModuleRefScopedModule ^. scopedModuleName)

instance (SingI s) => PrettyPrint (Import s) where
ppCode :: forall r. (Members '[ExactPrint, Reader Options] r) => Import s -> Sem r ()
Expand Down
Loading

0 comments on commit 47ae86b

Please sign in to comment.