1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 19:49:20 +03:00

Remove module parameters (#1848)

This commit is contained in:
janmasrovira 2023-02-16 12:05:49 +01:00 committed by GitHub
parent c93013229a
commit dd8457d097
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 57 deletions

View File

@ -69,8 +69,7 @@ goModule m = case sing :: SModuleIsTop t of
SModuleLocal -> goModule' m SModuleLocal -> goModule' m
where where
goModule' :: Module 'Scoped t -> Sem r Abstract.Module goModule' :: Module 'Scoped t -> Sem r Abstract.Module
goModule' Module {..} goModule' Module {..} = do
| null _moduleParameters = do
body' <- goModuleBody _moduleBody body' <- goModuleBody _moduleBody
examples' <- goExamples _moduleDoc examples' <- goExamples _moduleDoc
return return
@ -79,7 +78,6 @@ goModule m = case sing :: SModuleIsTop t of
_moduleBody = body', _moduleBody = body',
_moduleExamples = examples' _moduleExamples = examples'
} }
| otherwise = unsupported "Module parameters"
where where
name' :: Abstract.Name name' :: Abstract.Name
name' = case sing :: SModuleIsTop t of name' = case sing :: SModuleIsTop t of

View File

@ -398,7 +398,6 @@ type LocalModuleName s = SymbolType s
data Module (s :: Stage) (t :: ModuleIsTop) = Module data Module (s :: Stage) (t :: ModuleIsTop) = Module
{ _moduleKw :: KeywordRef, { _moduleKw :: KeywordRef,
_modulePath :: ModulePathType s t, _modulePath :: ModulePathType s t,
_moduleParameters :: [InductiveParameters s],
_moduleDoc :: Maybe (Judoc s), _moduleDoc :: Maybe (Judoc s),
_moduleBody :: [Statement s] _moduleBody :: [Statement s]
} }
@ -511,7 +510,6 @@ data OpenModule (s :: Stage) = OpenModule
{ _openModuleKw :: KeywordRef, { _openModuleKw :: KeywordRef,
_openModuleName :: ModuleRefType s, _openModuleName :: ModuleRefType s,
_openModuleImportKw :: Maybe KeywordRef, _openModuleImportKw :: Maybe KeywordRef,
_openParameters :: [ExpressionType s],
_openUsingHiding :: Maybe UsingHiding, _openUsingHiding :: Maybe UsingHiding,
_openPublic :: PublicAnn _openPublic :: PublicAnn
} }

View File

@ -208,13 +208,11 @@ instance (SingI s, SingI t) => PrettyCode (Module s t) where
ppCode Module {..} = do ppCode Module {..} = do
moduleBody' <- indent' <$> ppCode _moduleBody moduleBody' <- indent' <$> ppCode _moduleBody
modulePath' <- ppModulePathType _modulePath modulePath' <- ppModulePathType _modulePath
moduleParameters' <- ppInductiveParameters _moduleParameters
moduleDoc' <- mapM ppCode _moduleDoc moduleDoc' <- mapM ppCode _moduleDoc
return $ return $
moduleDoc' moduleDoc'
?<> kwModule ?<> kwModule
<+> modulePath' <+> modulePath'
<+?> moduleParameters'
<> kwSemicolon <> kwSemicolon
<> line <> line
<> moduleBody' <> moduleBody'
@ -368,18 +366,10 @@ instance (SingI s) => PrettyCode (OpenModule s) where
SParsed -> ppCode _openModuleName SParsed -> ppCode _openModuleName
SScoped -> ppCode _openModuleName SScoped -> ppCode _openModuleName
openUsingHiding' <- mapM ppUsingHiding _openUsingHiding openUsingHiding' <- mapM ppUsingHiding _openUsingHiding
openParameters' <- ppOpenParams
importkw' <- mapM ppCode _openModuleImportKw importkw' <- mapM ppCode _openModuleImportKw
let openPublic' = ppPublic let openPublic' = ppPublic
return $ kwOpen <+?> importkw' <+> openModuleName' <+?> openParameters' <+?> openUsingHiding' <+?> openPublic' return $ kwOpen <+?> importkw' <+> openModuleName' <+?> openUsingHiding' <+?> openPublic'
where where
ppAtom' = case sing :: SStage s of
SParsed -> ppCodeAtom
SScoped -> ppCodeAtom
ppOpenParams :: Sem r (Maybe (Doc Ann))
ppOpenParams = case _openParameters of
[] -> return Nothing
_ -> Just . hsep <$> mapM ppAtom' _openParameters
ppUsingHiding :: UsingHiding -> Sem r (Doc Ann) ppUsingHiding :: UsingHiding -> Sem r (Doc Ann)
ppUsingHiding uh = do ppUsingHiding uh = do
bracedList <- bracedList <-

View File

@ -252,7 +252,6 @@ instance PrettyPrint (OpenModule 'Scoped) where
ppCode OpenModule {..} = do ppCode OpenModule {..} = do
let name' = ppCode _openModuleName let name' = ppCode _openModuleName
usingHiding' = ppCode <$> _openUsingHiding usingHiding' = ppCode <$> _openUsingHiding
openParameters' = hsep . fmap ppAtom <$> nonEmpty _openParameters
importkw' = ppCode <$> _openModuleImportKw importkw' = ppCode <$> _openModuleImportKw
public' = case _openPublic of public' = case _openPublic of
Public -> Just (noLoc P.kwPublic) Public -> Just (noLoc P.kwPublic)
@ -260,7 +259,6 @@ instance PrettyPrint (OpenModule 'Scoped) where
ppCode _openModuleKw ppCode _openModuleKw
<+?> importkw' <+?> importkw'
<+> name' <+> name'
<+?> openParameters'
<+?> usingHiding' <+?> usingHiding'
<+?> public' <+?> public'

View File

@ -533,7 +533,7 @@ checkTopModule ::
(Members '[Error ScoperError, Reader ScopeParameters, State ScoperState, InfoTableBuilder, NameIdGen] r) => (Members '[Error ScoperError, Reader ScopeParameters, State ScoperState, InfoTableBuilder, NameIdGen] r) =>
Module 'Parsed 'ModuleTop -> Module 'Parsed 'ModuleTop ->
Sem r (ModuleRef'' 'S.NotConcrete 'ModuleTop) Sem r (ModuleRef'' 'S.NotConcrete 'ModuleTop)
checkTopModule m@(Module _moduleKw path params doc body) = do checkTopModule m@(Module _moduleKw path doc body) = do
r <- checkedModule r <- checkedModule
modify (over (scoperModulesCache . cachedModules) (HashMap.insert path r)) modify (over (scoperModulesCache . cachedModules) (HashMap.insert path r))
registerModule (r ^. moduleRefModule) registerModule (r ^. moduleRefModule)
@ -563,14 +563,12 @@ checkTopModule m@(Module _moduleKw path params doc body) = do
checkedModule = do checkedModule = do
(s, (m', p)) <- runState iniScope $ do (s, (m', p)) <- runState iniScope $ do
path' <- freshTopModulePath path' <- freshTopModulePath
localScope $ localScope $ do
withParams params $ \params' -> do
(_moduleExportInfo, body') <- checkModuleBody body (_moduleExportInfo, body') <- checkModuleBody body
doc' <- mapM checkJudoc doc doc' <- mapM checkJudoc doc
let _moduleRefModule = let _moduleRefModule =
Module Module
{ _modulePath = path', { _modulePath = path',
_moduleParameters = params',
_moduleBody = body', _moduleBody = body',
_moduleDoc = doc', _moduleDoc = doc',
_moduleKw _moduleKw
@ -604,20 +602,18 @@ checkLocalModule ::
Module 'Parsed 'ModuleLocal -> Module 'Parsed 'ModuleLocal ->
Sem r (Module 'Scoped 'ModuleLocal) Sem r (Module 'Scoped 'ModuleLocal)
checkLocalModule Module {..} = do checkLocalModule Module {..} = do
(_moduleExportInfo, moduleBody', moduleParameters', moduleDoc') <- (_moduleExportInfo, moduleBody', moduleDoc') <-
withScope $ withScope $ do
withParams _moduleParameters $ \p' -> do
inheritScope inheritScope
(e, b) <- checkModuleBody _moduleBody (e, b) <- checkModuleBody _moduleBody
doc' <- mapM checkJudoc _moduleDoc doc' <- mapM checkJudoc _moduleDoc
return (e, b, p', doc') return (e, b, doc')
_modulePath' <- reserveSymbolOf S.KNameLocalModule _modulePath _modulePath' <- reserveSymbolOf S.KNameLocalModule _modulePath
let moduleId = _modulePath' ^. S.nameId let moduleId = _modulePath' ^. S.nameId
_moduleRefName = set S.nameConcrete () _modulePath' _moduleRefName = set S.nameConcrete () _modulePath'
_moduleRefModule = _moduleRefModule =
Module Module
{ _modulePath = _modulePath', { _modulePath = _modulePath',
_moduleParameters = moduleParameters',
_moduleBody = moduleBody', _moduleBody = moduleBody',
_moduleDoc = moduleDoc', _moduleDoc = moduleDoc',
_moduleKw _moduleKw
@ -710,13 +706,11 @@ checkOpenModuleNoImport OpenModule {..}
| isJust _openModuleImportKw = error "unsupported: open import statement" | isJust _openModuleImportKw = error "unsupported: open import statement"
| otherwise = do | otherwise = do
openModuleName'@(ModuleRef' (_ :&: moduleRef'')) <- lookupModuleSymbol _openModuleName openModuleName'@(ModuleRef' (_ :&: moduleRef'')) <- lookupModuleSymbol _openModuleName
openParameters' <- mapM checkParseExpressionAtoms _openParameters
mergeScope (alterScope (moduleRef'' ^. moduleExportInfo)) mergeScope (alterScope (moduleRef'' ^. moduleExportInfo))
registerName (moduleRef'' ^. moduleRefName) registerName (moduleRef'' ^. moduleRefName)
return return
OpenModule OpenModule
{ _openModuleName = openModuleName', { _openModuleName = openModuleName',
_openParameters = openParameters',
.. ..
} }
where where