mirror of
https://github.com/anoma/juvix.git
synced 2025-01-06 06:53:33 +03:00
Make FunctionLhs a field of FunctionDef (#3202)
This commit is contained in:
parent
ad0333467b
commit
5fea31eec6
@ -293,7 +293,7 @@ printDocumentation = replParseIdentifiers >=> printIdentifiers
|
|||||||
getDocFunction fun = do
|
getDocFunction fun = do
|
||||||
tbl :: Scoped.InfoTable <- getScopedInfoTable
|
tbl :: Scoped.InfoTable <- getScopedInfoTable
|
||||||
let def = tbl ^?! Scoped.infoFunctions . at fun . _Just
|
let def = tbl ^?! Scoped.infoFunctions . at fun . _Just
|
||||||
return (def ^. Concrete.signDoc)
|
return (def ^. Concrete.functionDefDoc)
|
||||||
|
|
||||||
getDocInductive :: Scoped.NameId -> Repl (Maybe (Concrete.Judoc 'Concrete.Scoped))
|
getDocInductive :: Scoped.NameId -> Repl (Maybe (Concrete.Judoc 'Concrete.Scoped))
|
||||||
getDocInductive ind = do
|
getDocInductive ind = do
|
||||||
|
@ -541,12 +541,12 @@ goAxiom axiom = do
|
|||||||
goDeriving :: forall r. (Members '[Reader HtmlOptions] r) => Deriving 'Scoped -> Sem r Html
|
goDeriving :: forall r. (Members '[Reader HtmlOptions] r) => Deriving 'Scoped -> Sem r Html
|
||||||
goDeriving def = do
|
goDeriving def = do
|
||||||
sig <- ppHelper (ppCode def)
|
sig <- ppHelper (ppCode def)
|
||||||
defHeader (def ^. derivingFunLhs . funLhsName . functionDefName) sig Nothing
|
defHeader (def ^. derivingFunLhs . funLhsName . functionDefNameScoped) sig Nothing
|
||||||
|
|
||||||
goFunctionDef :: forall r. (Members '[Reader HtmlOptions] r) => FunctionDef 'Scoped -> Sem r Html
|
goFunctionDef :: forall r. (Members '[Reader HtmlOptions] r) => FunctionDef 'Scoped -> Sem r Html
|
||||||
goFunctionDef def = do
|
goFunctionDef def = do
|
||||||
sig <- ppHelper (ppCode (functionDefLhs def))
|
sig <- ppHelper (ppCode (def ^. functionDefLhs))
|
||||||
defHeader (def ^. signName . functionDefName) sig (def ^. signDoc)
|
defHeader (def ^. functionDefName . functionDefNameScoped) sig (def ^. functionDefDoc)
|
||||||
|
|
||||||
goInductive :: forall r. (Members '[Reader HtmlOptions] r) => InductiveDef 'Scoped -> Sem r Html
|
goInductive :: forall r. (Members '[Reader HtmlOptions] r) => InductiveDef 'Scoped -> Sem r Html
|
||||||
goInductive def = do
|
goInductive def = do
|
||||||
|
@ -61,8 +61,8 @@ runInfoTableBuilder ini = reinterpret (runState ini) $ \case
|
|||||||
modify' (over infoInductives (HashMap.insert (ity ^. inductiveName . nameId) ity))
|
modify' (over infoInductives (HashMap.insert (ity ^. inductiveName . nameId) ity))
|
||||||
highlightDoc (ity ^. inductiveName . nameId) j
|
highlightDoc (ity ^. inductiveName . nameId) j
|
||||||
RegisterFunctionDef f -> do
|
RegisterFunctionDef f -> do
|
||||||
let j = f ^. signDoc
|
let j = f ^. functionDefDoc
|
||||||
fid = f ^. signName . functionDefName . nameId
|
fid = f ^. functionDefName . functionDefNameScoped . nameId
|
||||||
modify' (over infoFunctions (HashMap.insert fid f))
|
modify' (over infoFunctions (HashMap.insert fid f))
|
||||||
highlightDoc fid j
|
highlightDoc fid j
|
||||||
RegisterName n -> highlightName (S.anameFromName n)
|
RegisterName n -> highlightName (S.anameFromName n)
|
||||||
|
@ -68,7 +68,7 @@ instance (SingI s) => HasNameSignature s (FunctionLhs s) where
|
|||||||
addArgs FunctionLhs {..} = addArgs _funLhsTypeSig
|
addArgs FunctionLhs {..} = addArgs _funLhsTypeSig
|
||||||
|
|
||||||
instance (SingI s) => HasNameSignature s (FunctionDef s) where
|
instance (SingI s) => HasNameSignature s (FunctionDef s) where
|
||||||
addArgs = addArgs . functionDefLhs
|
addArgs = addArgs . (^. functionDefLhs)
|
||||||
|
|
||||||
instance (SingI s) => HasNameSignature s (InductiveDef s, ConstructorDef s) where
|
instance (SingI s) => HasNameSignature s (InductiveDef s, ConstructorDef s) where
|
||||||
addArgs ::
|
addArgs ::
|
||||||
|
@ -72,7 +72,7 @@ groupStatements = \case
|
|||||||
definesSymbol n s = case s of
|
definesSymbol n s = case s of
|
||||||
StatementInductive d -> n `elem` syms d
|
StatementInductive d -> n `elem` syms d
|
||||||
StatementAxiom d -> n == symbolParsed (d ^. axiomName)
|
StatementAxiom d -> n == symbolParsed (d ^. axiomName)
|
||||||
StatementFunctionDef d -> withFunctionSymbol False (\n' -> n == symbolParsed n') (d ^. signName)
|
StatementFunctionDef d -> withFunctionSymbol False (\n' -> n == symbolParsed n') (d ^. functionDefName)
|
||||||
_ -> False
|
_ -> False
|
||||||
where
|
where
|
||||||
syms :: InductiveDef s -> [Symbol]
|
syms :: InductiveDef s -> [Symbol]
|
||||||
@ -115,4 +115,4 @@ isLhsFunctionLike FunctionLhs {..} = notNull (_funLhsTypeSig ^. typeSigArgs)
|
|||||||
|
|
||||||
isFunctionLike :: FunctionDef 'Parsed -> Bool
|
isFunctionLike :: FunctionDef 'Parsed -> Bool
|
||||||
isFunctionLike d@FunctionDef {..} =
|
isFunctionLike d@FunctionDef {..} =
|
||||||
isLhsFunctionLike (functionDefLhs d) || (not . isBodyExpression) _signBody
|
isLhsFunctionLike (d ^. functionDefLhs) || (not . isBodyExpression) _functionDefBody
|
||||||
|
@ -26,29 +26,33 @@ simplestFunctionDefParsed funNameTxt funBody = do
|
|||||||
|
|
||||||
simplestFunctionDef :: forall s. (SingI s) => FunctionName s -> ExpressionType s -> FunctionDef s
|
simplestFunctionDef :: forall s. (SingI s) => FunctionName s -> ExpressionType s -> FunctionDef s
|
||||||
simplestFunctionDef funName funBody =
|
simplestFunctionDef funName funBody =
|
||||||
FunctionDef
|
let lhs =
|
||||||
{ _signName = name,
|
FunctionLhs
|
||||||
_signBody = SigBodyExpression funBody,
|
{ _funLhsName = name,
|
||||||
_signTypeSig =
|
_funLhsTypeSig =
|
||||||
TypeSig
|
TypeSig
|
||||||
{ _typeSigColonKw = Irrelevant Nothing,
|
{ _typeSigColonKw = Irrelevant Nothing,
|
||||||
_typeSigArgs = [],
|
_typeSigArgs = [],
|
||||||
_typeSigRetType = Nothing
|
_typeSigRetType = Nothing
|
||||||
},
|
},
|
||||||
_signDoc = Nothing,
|
_funLhsBuiltin = Nothing,
|
||||||
_signPragmas = Nothing,
|
_funLhsTerminating = Nothing,
|
||||||
_signBuiltin = Nothing,
|
_funLhsInstance = Nothing,
|
||||||
_signTerminating = Nothing,
|
_funLhsCoercion = Nothing
|
||||||
_signInstance = Nothing,
|
}
|
||||||
_signCoercion = Nothing
|
in FunctionDef
|
||||||
}
|
{ _functionDefBody = SigBodyExpression funBody,
|
||||||
|
_functionDefLhs = lhs,
|
||||||
|
_functionDefDoc = Nothing,
|
||||||
|
_functionDefPragmas = Nothing
|
||||||
|
}
|
||||||
where
|
where
|
||||||
name :: FunctionSymbolType s
|
name :: FunctionSymbolType s
|
||||||
name = case sing :: SStage s of
|
name = case sing :: SStage s of
|
||||||
SParsed -> FunctionDefName funName
|
SParsed -> FunctionDefName funName
|
||||||
SScoped ->
|
SScoped ->
|
||||||
FunctionDefNameScoped
|
FunctionDefNameScoped
|
||||||
{ _functionDefName = funName,
|
{ _functionDefNameScoped = funName,
|
||||||
_functionDefNamePattern = Nothing
|
_functionDefNamePattern = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ statementLabel = \case
|
|||||||
StatementSyntax s -> goSyntax s
|
StatementSyntax s -> goSyntax s
|
||||||
StatementOpenModule {} -> Nothing
|
StatementOpenModule {} -> Nothing
|
||||||
StatementProjectionDef {} -> Nothing
|
StatementProjectionDef {} -> Nothing
|
||||||
StatementFunctionDef f -> withFunctionSymbol Nothing (Just . (^. symbolTypeLabel)) (f ^. signName)
|
StatementFunctionDef f -> withFunctionSymbol Nothing (Just . (^. symbolTypeLabel)) (f ^. functionDefName)
|
||||||
StatementDeriving f -> withFunctionSymbol Nothing (Just . (^. symbolTypeLabel)) (f ^. derivingFunLhs . funLhsName)
|
StatementDeriving f -> withFunctionSymbol Nothing (Just . (^. symbolTypeLabel)) (f ^. derivingFunLhs . funLhsName)
|
||||||
StatementImport i -> Just (i ^. importModulePath . to modulePathTypeLabel)
|
StatementImport i -> Just (i ^. importModulePath . to modulePathTypeLabel)
|
||||||
StatementInductive i -> Just (i ^. inductiveName . symbolTypeLabel)
|
StatementInductive i -> Just (i ^. inductiveName . symbolTypeLabel)
|
||||||
|
@ -716,7 +716,7 @@ instance Serialize FunctionDefNameParsed
|
|||||||
instance NFData FunctionDefNameParsed
|
instance NFData FunctionDefNameParsed
|
||||||
|
|
||||||
data FunctionDefNameScoped = FunctionDefNameScoped
|
data FunctionDefNameScoped = FunctionDefNameScoped
|
||||||
{ _functionDefName :: S.Symbol,
|
{ _functionDefNameScoped :: S.Symbol,
|
||||||
_functionDefNamePattern :: Maybe PatternArg
|
_functionDefNamePattern :: Maybe PatternArg
|
||||||
}
|
}
|
||||||
deriving stock (Eq, Ord, Show, Generic)
|
deriving stock (Eq, Ord, Show, Generic)
|
||||||
@ -726,15 +726,10 @@ instance Serialize FunctionDefNameScoped
|
|||||||
instance NFData FunctionDefNameScoped
|
instance NFData FunctionDefNameScoped
|
||||||
|
|
||||||
data FunctionDef (s :: Stage) = FunctionDef
|
data FunctionDef (s :: Stage) = FunctionDef
|
||||||
{ _signName :: FunctionSymbolType s,
|
{ _functionDefDoc :: Maybe (Judoc s),
|
||||||
_signTypeSig :: TypeSig s,
|
_functionDefPragmas :: Maybe ParsedPragmas,
|
||||||
_signDoc :: Maybe (Judoc s),
|
_functionDefLhs :: FunctionLhs s,
|
||||||
_signPragmas :: Maybe ParsedPragmas,
|
_functionDefBody :: FunctionDefBody s
|
||||||
_signBuiltin :: Maybe (WithLoc BuiltinFunction),
|
|
||||||
_signBody :: FunctionDefBody s,
|
|
||||||
_signTerminating :: Maybe KeywordRef,
|
|
||||||
_signInstance :: Maybe KeywordRef,
|
|
||||||
_signCoercion :: Maybe KeywordRef
|
|
||||||
}
|
}
|
||||||
deriving stock (Generic)
|
deriving stock (Generic)
|
||||||
|
|
||||||
@ -3057,16 +3052,23 @@ makePrisms ''NamedArgumentNew
|
|||||||
makePrisms ''ConstructorRhs
|
makePrisms ''ConstructorRhs
|
||||||
makePrisms ''FunctionDefNameParsed
|
makePrisms ''FunctionDefNameParsed
|
||||||
|
|
||||||
functionDefLhs :: FunctionDef s -> FunctionLhs s
|
functionDefBuiltin :: Lens' (FunctionDef s) (Maybe (WithLoc BuiltinFunction))
|
||||||
functionDefLhs FunctionDef {..} =
|
functionDefBuiltin = functionDefLhs . funLhsBuiltin
|
||||||
FunctionLhs
|
|
||||||
{ _funLhsBuiltin = _signBuiltin,
|
functionDefTerminating :: Lens' (FunctionDef s) (Maybe KeywordRef)
|
||||||
_funLhsTerminating = _signTerminating,
|
functionDefTerminating = functionDefLhs . funLhsTerminating
|
||||||
_funLhsInstance = _signInstance,
|
|
||||||
_funLhsCoercion = _signCoercion,
|
functionDefInstance :: Lens' (FunctionDef s) (Maybe KeywordRef)
|
||||||
_funLhsName = _signName,
|
functionDefInstance = functionDefLhs . funLhsInstance
|
||||||
_funLhsTypeSig = _signTypeSig
|
|
||||||
}
|
functionDefCoercion :: Lens' (FunctionDef s) (Maybe KeywordRef)
|
||||||
|
functionDefCoercion = functionDefLhs . funLhsCoercion
|
||||||
|
|
||||||
|
functionDefName :: Lens' (FunctionDef s) (FunctionSymbolType s)
|
||||||
|
functionDefName = functionDefLhs . funLhsName
|
||||||
|
|
||||||
|
functionDefTypeSig :: Lens' (FunctionDef s) (TypeSig s)
|
||||||
|
functionDefTypeSig = functionDefLhs . funLhsTypeSig
|
||||||
|
|
||||||
fixityFieldHelper :: SimpleGetter (ParsedFixityFields s) (Maybe a) -> SimpleGetter (ParsedFixityInfo s) (Maybe a)
|
fixityFieldHelper :: SimpleGetter (ParsedFixityFields s) (Maybe a) -> SimpleGetter (ParsedFixityInfo s) (Maybe a)
|
||||||
fixityFieldHelper l = to (^? fixityFields . _Just . l . _Just)
|
fixityFieldHelper l = to (^? fixityFields . _Just . l . _Just)
|
||||||
@ -3263,7 +3265,7 @@ getLocFunctionSymbolType = case sing :: SStage s of
|
|||||||
|
|
||||||
instance HasLoc FunctionDefNameScoped where
|
instance HasLoc FunctionDefNameScoped where
|
||||||
getLoc FunctionDefNameScoped {..} =
|
getLoc FunctionDefNameScoped {..} =
|
||||||
getLoc _functionDefName
|
getLoc _functionDefNameScoped
|
||||||
<>? (getLoc <$> _functionDefNamePattern)
|
<>? (getLoc <$> _functionDefNamePattern)
|
||||||
|
|
||||||
instance HasLoc FunctionDefNameParsed where
|
instance HasLoc FunctionDefNameParsed where
|
||||||
@ -3525,12 +3527,13 @@ instance (SingI s) => HasLoc (FunctionDefBody s) where
|
|||||||
|
|
||||||
instance (SingI s) => HasLoc (FunctionDef s) where
|
instance (SingI s) => HasLoc (FunctionDef s) where
|
||||||
getLoc FunctionDef {..} =
|
getLoc FunctionDef {..} =
|
||||||
(getLoc <$> _signDoc)
|
let FunctionLhs {..} = _functionDefLhs
|
||||||
?<> (getLoc <$> _signPragmas)
|
in (getLoc <$> _functionDefDoc)
|
||||||
?<> (getLoc <$> _signBuiltin)
|
?<> (getLoc <$> _functionDefPragmas)
|
||||||
?<> (getLoc <$> _signTerminating)
|
?<> (getLoc <$> _funLhsBuiltin)
|
||||||
?<> (getLocFunctionSymbolType _signName)
|
?<> (getLoc <$> _funLhsTerminating)
|
||||||
<> getLoc _signBody
|
?<> (getLocFunctionSymbolType _funLhsName)
|
||||||
|
<> getLoc _functionDefBody
|
||||||
|
|
||||||
instance HasLoc (Example s) where
|
instance HasLoc (Example s) where
|
||||||
getLoc e = e ^. exampleLoc
|
getLoc e = e ^. exampleLoc
|
||||||
@ -3719,7 +3722,7 @@ getFunctionSymbol sym = case sing :: SStage s of
|
|||||||
SParsed -> case sym of
|
SParsed -> case sym of
|
||||||
FunctionDefName p -> p
|
FunctionDefName p -> p
|
||||||
FunctionDefNamePattern {} -> impossibleError "invalid call"
|
FunctionDefNamePattern {} -> impossibleError "invalid call"
|
||||||
SScoped -> sym ^. functionDefName
|
SScoped -> sym ^. functionDefNameScoped
|
||||||
|
|
||||||
functionSymbolPattern :: forall s. (SingI s) => FunctionSymbolType s -> Maybe (PatternAtomType s)
|
functionSymbolPattern :: forall s. (SingI s) => FunctionSymbolType s -> Maybe (PatternAtomType s)
|
||||||
functionSymbolPattern f = case sing :: SStage s of
|
functionSymbolPattern f = case sing :: SStage s of
|
||||||
@ -3729,19 +3732,19 @@ functionSymbolPattern f = case sing :: SStage s of
|
|||||||
withFunctionSymbol :: forall s a. (SingI s) => a -> (SymbolType s -> a) -> FunctionSymbolType s -> a
|
withFunctionSymbol :: forall s a. (SingI s) => a -> (SymbolType s -> a) -> FunctionSymbolType s -> a
|
||||||
withFunctionSymbol a f sym = case sing :: SStage s of
|
withFunctionSymbol a f sym = case sing :: SStage s of
|
||||||
SParsed -> maybe a f (sym ^? _FunctionDefName)
|
SParsed -> maybe a f (sym ^? _FunctionDefName)
|
||||||
SScoped -> f (sym ^. functionDefName)
|
SScoped -> f (sym ^. functionDefNameScoped)
|
||||||
|
|
||||||
namedArgumentNewSymbolParsed :: (SingI s) => SimpleGetter (NamedArgumentNew s) Symbol
|
namedArgumentNewSymbolParsed :: (SingI s) => SimpleGetter (NamedArgumentNew s) Symbol
|
||||||
namedArgumentNewSymbolParsed = to $ \case
|
namedArgumentNewSymbolParsed = to $ \case
|
||||||
NamedArgumentItemPun a -> a ^. namedArgumentPunSymbol
|
NamedArgumentItemPun a -> a ^. namedArgumentPunSymbol
|
||||||
NamedArgumentNewFunction a -> symbolParsed (getFunctionSymbol (a ^. namedArgumentFunctionDef . signName))
|
NamedArgumentNewFunction a -> symbolParsed (getFunctionSymbol (a ^. namedArgumentFunctionDef . functionDefName))
|
||||||
|
|
||||||
namedArgumentNewSymbol :: Lens' (NamedArgumentNew 'Parsed) Symbol
|
namedArgumentNewSymbol :: Lens' (NamedArgumentNew 'Parsed) Symbol
|
||||||
namedArgumentNewSymbol f = \case
|
namedArgumentNewSymbol f = \case
|
||||||
NamedArgumentItemPun a -> NamedArgumentItemPun <$> (namedArgumentPunSymbol f a)
|
NamedArgumentItemPun a -> NamedArgumentItemPun <$> (namedArgumentPunSymbol f a)
|
||||||
NamedArgumentNewFunction a -> do
|
NamedArgumentNewFunction a -> do
|
||||||
a' <- f (a ^?! namedArgumentFunctionDef . signName . _FunctionDefName)
|
a' <- f (a ^?! namedArgumentFunctionDef . functionDefName . _FunctionDefName)
|
||||||
return $ NamedArgumentNewFunction (over namedArgumentFunctionDef (set signName (FunctionDefName a')) a)
|
return $ NamedArgumentNewFunction (over namedArgumentFunctionDef (set functionDefName (FunctionDefName a')) a)
|
||||||
|
|
||||||
scopedIdenSrcName :: Lens' ScopedIden S.Name
|
scopedIdenSrcName :: Lens' ScopedIden S.Name
|
||||||
scopedIdenSrcName f n = case n ^. scopedIdenAlias of
|
scopedIdenSrcName f n = case n ^. scopedIdenAlias of
|
||||||
|
@ -1205,10 +1205,10 @@ ppPipeBranches allowSameLine isTop ppBranch = \case
|
|||||||
instance (SingI s) => PrettyPrint (FunctionDef s) where
|
instance (SingI s) => PrettyPrint (FunctionDef s) where
|
||||||
ppCode :: forall r. (Members '[ExactPrint, Reader Options] r) => FunctionDef s -> Sem r ()
|
ppCode :: forall r. (Members '[ExactPrint, Reader Options] r) => FunctionDef s -> Sem r ()
|
||||||
ppCode fun@FunctionDef {..} = do
|
ppCode fun@FunctionDef {..} = do
|
||||||
let doc' :: Maybe (Sem r ()) = ppCode <$> _signDoc
|
let doc' :: Maybe (Sem r ()) = ppCode <$> _functionDefDoc
|
||||||
pragmas' :: Maybe (Sem r ()) = ppCode <$> _signPragmas
|
pragmas' :: Maybe (Sem r ()) = ppCode <$> _functionDefPragmas
|
||||||
sig' = ppCode (functionDefLhs fun)
|
sig' = ppCode (fun ^. functionDefLhs)
|
||||||
body' = case _signBody of
|
body' = case _functionDefBody of
|
||||||
SigBodyExpression e -> space <> ppCode Kw.kwAssign <> oneLineOrNext (ppTopExpressionType e)
|
SigBodyExpression e -> space <> ppCode Kw.kwAssign <> oneLineOrNext (ppTopExpressionType e)
|
||||||
SigBodyClauses k -> ppPipeBranches False Top ppFunctionClause k
|
SigBodyClauses k -> ppPipeBranches False Top ppFunctionClause k
|
||||||
doc'
|
doc'
|
||||||
|
@ -439,7 +439,7 @@ reserveFunctionLikeSymbol ::
|
|||||||
Sem r ()
|
Sem r ()
|
||||||
reserveFunctionLikeSymbol f =
|
reserveFunctionLikeSymbol f =
|
||||||
when (P.isFunctionLike f) $
|
when (P.isFunctionLike f) $
|
||||||
void (reserveFunctionSymbol (functionDefLhs f))
|
void (reserveFunctionSymbol (f ^. functionDefLhs))
|
||||||
|
|
||||||
bindFixitySymbol ::
|
bindFixitySymbol ::
|
||||||
(Members '[Error ScoperError, NameIdGen, State ScoperSyntax, State Scope, InfoTableBuilder, Reader InfoTable, State ScoperState, Reader BindingStrategy] r) =>
|
(Members '[Error ScoperError, NameIdGen, State ScoperSyntax, State Scope, InfoTableBuilder, Reader InfoTable, State ScoperState, Reader BindingStrategy] r) =>
|
||||||
@ -1129,7 +1129,7 @@ checkDeriving Deriving {..} = do
|
|||||||
| otherwise -> reserveFunctionSymbol lhs
|
| otherwise -> reserveFunctionSymbol lhs
|
||||||
let defname' =
|
let defname' =
|
||||||
FunctionDefNameScoped
|
FunctionDefNameScoped
|
||||||
{ _functionDefName = name',
|
{ _functionDefNameScoped = name',
|
||||||
_functionDefNamePattern = Nothing
|
_functionDefNamePattern = Nothing
|
||||||
}
|
}
|
||||||
let lhs' =
|
let lhs' =
|
||||||
@ -1192,21 +1192,22 @@ checkFunctionDef ::
|
|||||||
FunctionDef 'Parsed ->
|
FunctionDef 'Parsed ->
|
||||||
Sem r (FunctionDef 'Scoped)
|
Sem r (FunctionDef 'Scoped)
|
||||||
checkFunctionDef fdef@FunctionDef {..} = do
|
checkFunctionDef fdef@FunctionDef {..} = do
|
||||||
sigDoc' <- mapM checkJudoc _signDoc
|
let FunctionLhs {..} = _functionDefLhs
|
||||||
|
sigDoc' <- mapM checkJudoc _functionDefDoc
|
||||||
(sig', sigBody') <- withLocalScope $ do
|
(sig', sigBody') <- withLocalScope $ do
|
||||||
a' <- checkTypeSig _signTypeSig
|
a' <- checkTypeSig _funLhsTypeSig
|
||||||
b' <- checkBody
|
b' <- checkBody
|
||||||
return (a', b')
|
return (a', b')
|
||||||
whenJust (functionSymbolPattern _signName) reservePatternFunctionSymbols
|
whenJust (functionSymbolPattern _funLhsName) reservePatternFunctionSymbols
|
||||||
sigName' <- case _signName of
|
sigName' <- case _funLhsName of
|
||||||
FunctionDefName name -> do
|
FunctionDefName name -> do
|
||||||
name' <-
|
name' <-
|
||||||
if
|
if
|
||||||
| P.isFunctionLike fdef -> getReservedDefinitionSymbol name
|
| P.isFunctionLike fdef -> getReservedDefinitionSymbol name
|
||||||
| otherwise -> reserveFunctionSymbol (functionDefLhs fdef)
|
| otherwise -> reserveFunctionSymbol (fdef ^. functionDefLhs)
|
||||||
return
|
return
|
||||||
FunctionDefNameScoped
|
FunctionDefNameScoped
|
||||||
{ _functionDefName = name',
|
{ _functionDefNameScoped = name',
|
||||||
_functionDefNamePattern = Nothing
|
_functionDefNamePattern = Nothing
|
||||||
}
|
}
|
||||||
FunctionDefNamePattern p -> do
|
FunctionDefNamePattern p -> do
|
||||||
@ -1214,22 +1215,27 @@ checkFunctionDef fdef@FunctionDef {..} = do
|
|||||||
p' <- runReader PatternNamesKindFunctions (checkParsePatternAtom p)
|
p' <- runReader PatternNamesKindFunctions (checkParsePatternAtom p)
|
||||||
return
|
return
|
||||||
FunctionDefNameScoped
|
FunctionDefNameScoped
|
||||||
{ _functionDefName = name',
|
{ _functionDefNameScoped = name',
|
||||||
_functionDefNamePattern = Just p'
|
_functionDefNamePattern = Just p'
|
||||||
}
|
}
|
||||||
let def =
|
let lhs' =
|
||||||
FunctionDef
|
FunctionLhs
|
||||||
{ _signName = sigName',
|
{ _funLhsName = sigName',
|
||||||
_signDoc = sigDoc',
|
_funLhsTypeSig = sig',
|
||||||
_signBody = sigBody',
|
|
||||||
_signTypeSig = sig',
|
|
||||||
..
|
..
|
||||||
}
|
}
|
||||||
registerNameSignature (sigName' ^. functionDefName . S.nameId) def
|
def =
|
||||||
|
FunctionDef
|
||||||
|
{ _functionDefLhs = lhs',
|
||||||
|
_functionDefDoc = sigDoc',
|
||||||
|
_functionDefBody = sigBody',
|
||||||
|
..
|
||||||
|
}
|
||||||
|
registerNameSignature (sigName' ^. functionDefNameScoped . S.nameId) def
|
||||||
registerFunctionDef @$> def
|
registerFunctionDef @$> def
|
||||||
where
|
where
|
||||||
checkBody :: Sem r (FunctionDefBody 'Scoped)
|
checkBody :: Sem r (FunctionDefBody 'Scoped)
|
||||||
checkBody = case _signBody of
|
checkBody = case _functionDefBody of
|
||||||
SigBodyExpression e -> SigBodyExpression <$> checkParseExpressionAtoms e
|
SigBodyExpression e -> SigBodyExpression <$> checkParseExpressionAtoms e
|
||||||
SigBodyClauses cls -> SigBodyClauses <$> mapM checkClause cls
|
SigBodyClauses cls -> SigBodyClauses <$> mapM checkClause cls
|
||||||
|
|
||||||
|
@ -1431,31 +1431,26 @@ functionDefinition ::
|
|||||||
FunctionSyntaxOptions ->
|
FunctionSyntaxOptions ->
|
||||||
Maybe (WithLoc BuiltinFunction) ->
|
Maybe (WithLoc BuiltinFunction) ->
|
||||||
ParsecS r (FunctionDef 'Parsed)
|
ParsecS r (FunctionDef 'Parsed)
|
||||||
functionDefinition opts _signBuiltin = P.label "<function definition>" $ do
|
functionDefinition opts _functionDefBuiltin = P.label "<function definition>" $ do
|
||||||
off0 <- P.getOffset
|
off0 <- P.getOffset
|
||||||
FunctionLhs {..} <- functionDefinitionLhs opts _signBuiltin
|
lhs <- functionDefinitionLhs opts _functionDefBuiltin
|
||||||
off <- P.getOffset
|
off <- P.getOffset
|
||||||
_signDoc <- getJudoc
|
_functionDefDoc <- getJudoc
|
||||||
_signPragmas <- getPragmas
|
_functionDefPragmas <- getPragmas
|
||||||
_signBody <- parseBody
|
_functionDefBody <- parseBody
|
||||||
unless
|
unless
|
||||||
( isJust (_funLhsTypeSig ^. typeSigColonKw . unIrrelevant)
|
( isJust (lhs ^. funLhsTypeSig . typeSigColonKw . unIrrelevant)
|
||||||
|| (P.isBodyExpression _signBody && null (_funLhsTypeSig ^. typeSigArgs))
|
|| (P.isBodyExpression _functionDefBody && null (lhs ^. funLhsTypeSig . typeSigArgs))
|
||||||
)
|
)
|
||||||
$ parseFailure off "expected result type"
|
$ parseFailure off "expected result type"
|
||||||
let fdef =
|
let fdef =
|
||||||
FunctionDef
|
FunctionDef
|
||||||
{ _signName = _funLhsName,
|
{ _functionDefLhs = lhs,
|
||||||
_signTypeSig = _funLhsTypeSig,
|
_functionDefDoc,
|
||||||
_signTerminating = _funLhsTerminating,
|
_functionDefPragmas,
|
||||||
_signInstance = _funLhsInstance,
|
_functionDefBody
|
||||||
_signCoercion = _funLhsCoercion,
|
|
||||||
_signBuiltin = _funLhsBuiltin,
|
|
||||||
_signDoc,
|
|
||||||
_signPragmas,
|
|
||||||
_signBody
|
|
||||||
}
|
}
|
||||||
when (isNothing (_funLhsName ^? _FunctionDefName) && P.isFunctionLike fdef) $
|
when (isNothing (lhs ^? funLhsName . _FunctionDefName) && P.isFunctionLike fdef) $
|
||||||
parseFailure off0 "expected function name"
|
parseFailure off0 "expected function name"
|
||||||
return fdef
|
return fdef
|
||||||
where
|
where
|
||||||
|
@ -433,7 +433,7 @@ goDeriving ::
|
|||||||
Sem r Internal.FunctionDef
|
Sem r Internal.FunctionDef
|
||||||
goDeriving Deriving {..} = do
|
goDeriving Deriving {..} = do
|
||||||
let FunctionLhs {..} = _derivingFunLhs
|
let FunctionLhs {..} = _derivingFunLhs
|
||||||
name = goSymbol (_funLhsName ^. functionDefName)
|
name = goSymbol (_funLhsName ^. functionDefNameScoped)
|
||||||
(funArgs, ret) <- Internal.unfoldFunType <$> goDefType _derivingFunLhs
|
(funArgs, ret) <- Internal.unfoldFunType <$> goDefType _derivingFunLhs
|
||||||
let (mtrait, traitArgs) = Internal.unfoldExpressionApp ret
|
let (mtrait, traitArgs) = Internal.unfoldExpressionApp ret
|
||||||
(n, der) <- findDerivingTrait mtrait
|
(n, der) <- findDerivingTrait mtrait
|
||||||
@ -893,22 +893,22 @@ goFunctionDef ::
|
|||||||
FunctionDef 'Scoped ->
|
FunctionDef 'Scoped ->
|
||||||
Sem r [Internal.FunctionDef]
|
Sem r [Internal.FunctionDef]
|
||||||
goFunctionDef def@FunctionDef {..} = do
|
goFunctionDef def@FunctionDef {..} = do
|
||||||
let _funDefName = goSymbol (_signName ^. functionDefName)
|
let _funDefName = goSymbol (def ^. functionDefName . functionDefNameScoped)
|
||||||
_funDefTerminating = isJust _signTerminating
|
_funDefTerminating = isJust (def ^. functionDefTerminating)
|
||||||
_funDefIsInstanceCoercion
|
_funDefIsInstanceCoercion
|
||||||
| isJust _signCoercion = Just Internal.IsInstanceCoercionCoercion
|
| isJust (def ^. functionDefCoercion) = Just Internal.IsInstanceCoercionCoercion
|
||||||
| isJust _signInstance = Just Internal.IsInstanceCoercionInstance
|
| isJust (def ^. functionDefInstance) = Just Internal.IsInstanceCoercionInstance
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
_funDefCoercion = isJust _signCoercion
|
_funDefCoercion = isJust (def ^. functionDefCoercion)
|
||||||
_funDefBuiltin = (^. withLocParam) <$> _signBuiltin
|
_funDefBuiltin = (^. withLocParam) <$> (def ^. functionDefBuiltin)
|
||||||
_funDefType <- goDefType (functionDefLhs def)
|
_funDefType <- goDefType (def ^. functionDefLhs)
|
||||||
_funDefPragmas <- goPragmas _signPragmas
|
_funDefPragmas <- goPragmas _functionDefPragmas
|
||||||
_funDefBody <- goBody
|
_funDefBody <- goBody
|
||||||
_funDefArgsInfo <- goArgsInfo _funDefName
|
_funDefArgsInfo <- goArgsInfo _funDefName
|
||||||
let _funDefDocComment = fmap ppPrintJudoc _signDoc
|
let _funDefDocComment = fmap ppPrintJudoc _functionDefDoc
|
||||||
fun = Internal.FunctionDef {..}
|
fun = Internal.FunctionDef {..}
|
||||||
whenJust _signBuiltin (checkBuiltinFunction fun . (^. withLocParam))
|
whenJust (def ^. functionDefBuiltin) (checkBuiltinFunction fun . (^. withLocParam))
|
||||||
case _signName ^. functionDefNamePattern of
|
case def ^. functionDefName . functionDefNamePattern of
|
||||||
Just pat -> do
|
Just pat -> do
|
||||||
pat' <- goPatternArg pat
|
pat' <- goPatternArg pat
|
||||||
(fun :) <$> Internal.genPatternDefs _funDefName pat'
|
(fun :) <$> Internal.genPatternDefs _funDefName pat'
|
||||||
@ -917,14 +917,14 @@ goFunctionDef def@FunctionDef {..} = do
|
|||||||
where
|
where
|
||||||
goBody :: Sem r Internal.Expression
|
goBody :: Sem r Internal.Expression
|
||||||
goBody = do
|
goBody = do
|
||||||
commonPatterns <- concatMapM (fmap toList . argToPattern) (_signTypeSig ^. typeSigArgs)
|
commonPatterns <- concatMapM (fmap toList . argToPattern) (def ^. functionDefTypeSig . typeSigArgs)
|
||||||
let goClause :: FunctionClause 'Scoped -> Sem r Internal.LambdaClause
|
let goClause :: FunctionClause 'Scoped -> Sem r Internal.LambdaClause
|
||||||
goClause FunctionClause {..} = do
|
goClause FunctionClause {..} = do
|
||||||
_lambdaBody <- goExpression _clausenBody
|
_lambdaBody <- goExpression _clausenBody
|
||||||
extraPatterns <- mapM goPatternArg _clausenPatterns
|
extraPatterns <- mapM goPatternArg _clausenPatterns
|
||||||
let _lambdaPatterns = prependList commonPatterns extraPatterns
|
let _lambdaPatterns = prependList commonPatterns extraPatterns
|
||||||
return Internal.LambdaClause {..}
|
return Internal.LambdaClause {..}
|
||||||
case _signBody of
|
case _functionDefBody of
|
||||||
SigBodyExpression body -> do
|
SigBodyExpression body -> do
|
||||||
body' <- goExpression body
|
body' <- goExpression body
|
||||||
return $ case nonEmpty commonPatterns of
|
return $ case nonEmpty commonPatterns of
|
||||||
@ -1319,7 +1319,7 @@ createArgumentBlocks appargs =
|
|||||||
where
|
where
|
||||||
namedArgumentRefSymbol :: NamedArgumentNew 'Scoped -> S.Symbol
|
namedArgumentRefSymbol :: NamedArgumentNew 'Scoped -> S.Symbol
|
||||||
namedArgumentRefSymbol = \case
|
namedArgumentRefSymbol = \case
|
||||||
NamedArgumentNewFunction p -> p ^. namedArgumentFunctionDef . signName . functionDefName
|
NamedArgumentNewFunction p -> p ^. namedArgumentFunctionDef . functionDefName . functionDefNameScoped
|
||||||
NamedArgumentItemPun p -> over S.nameConcrete fromUnqualified' (p ^. namedArgumentReferencedSymbol . scopedIdenFinal)
|
NamedArgumentItemPun p -> over S.nameConcrete fromUnqualified' (p ^. namedArgumentReferencedSymbol . scopedIdenFinal)
|
||||||
args0 :: HashSet S.Symbol = hashSet (namedArgumentRefSymbol <$> appargs)
|
args0 :: HashSet S.Symbol = hashSet (namedArgumentRefSymbol <$> appargs)
|
||||||
goBlock ::
|
goBlock ::
|
||||||
@ -1416,8 +1416,8 @@ goExpression = \case
|
|||||||
funs
|
funs
|
||||||
^.. each
|
^.. each
|
||||||
. namedArgumentFunctionDef
|
. namedArgumentFunctionDef
|
||||||
. signName
|
|
||||||
. functionDefName
|
. functionDefName
|
||||||
|
. functionDefNameScoped
|
||||||
. to goSymbol
|
. to goSymbol
|
||||||
-- changes the kind from Variable to Function
|
-- changes the kind from Variable to Function
|
||||||
updateKind :: Internal.Subs = Internal.subsKind funsNames KNameFunction
|
updateKind :: Internal.Subs = Internal.subsKind funsNames KNameFunction
|
||||||
|
@ -83,25 +83,29 @@ toConcrete t p = run . runReader l $ do
|
|||||||
_typeSigRetType <- Just <$> expressionAtoms' (packageTypeIdentifier :| [])
|
_typeSigRetType <- Just <$> expressionAtoms' (packageTypeIdentifier :| [])
|
||||||
name' <- symbol Str.package
|
name' <- symbol Str.package
|
||||||
_typeSigColonKw <- Irrelevant . Just <$> kw kwColon
|
_typeSigColonKw <- Irrelevant . Just <$> kw kwColon
|
||||||
let _signBody = (t ^. packageDescriptionTypeTransform) p
|
let _functionDefBody = (t ^. packageDescriptionTypeTransform) p
|
||||||
_signTypeSig =
|
_funLhsTypeSig =
|
||||||
TypeSig
|
TypeSig
|
||||||
{ _typeSigArgs = [],
|
{ _typeSigArgs = [],
|
||||||
_typeSigRetType,
|
_typeSigRetType,
|
||||||
_typeSigColonKw
|
_typeSigColonKw
|
||||||
}
|
}
|
||||||
|
lhs =
|
||||||
|
FunctionLhs
|
||||||
|
{ _funLhsTerminating = Nothing,
|
||||||
|
_funLhsCoercion = Nothing,
|
||||||
|
_funLhsBuiltin = Nothing,
|
||||||
|
_funLhsName = FunctionDefName name',
|
||||||
|
_funLhsInstance = Nothing,
|
||||||
|
_funLhsTypeSig
|
||||||
|
}
|
||||||
return
|
return
|
||||||
( StatementFunctionDef
|
( StatementFunctionDef
|
||||||
FunctionDef
|
FunctionDef
|
||||||
{ _signTerminating = Nothing,
|
{ _functionDefPragmas = Nothing,
|
||||||
_signPragmas = Nothing,
|
_functionDefLhs = lhs,
|
||||||
_signInstance = Nothing,
|
_functionDefDoc = Nothing,
|
||||||
_signDoc = Nothing,
|
_functionDefBody
|
||||||
_signCoercion = Nothing,
|
|
||||||
_signBuiltin = Nothing,
|
|
||||||
_signName = FunctionDefName name',
|
|
||||||
_signBody,
|
|
||||||
_signTypeSig
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user