Skip to content

Commit

Permalink
translate comments to Isabelle
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Aug 14, 2024
1 parent 0c6d8a6 commit e4a254b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
18 changes: 12 additions & 6 deletions src/Juvix/Compiler/Backend/Isabelle/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ data Statement
data Definition = Definition
{ _definitionName :: Name,
_definitionType :: Type,
_definitionBody :: Expression
_definitionBody :: Expression,
_definitionComment :: Maybe Text
}

data Function = Function
{ _functionName :: Name,
_functionType :: Type,
_functionClauses :: NonEmpty Clause
_functionClauses :: NonEmpty Clause,
_functionComment :: Maybe Text
}

data Clause = Clause
Expand All @@ -176,23 +178,27 @@ data Synonym = Synonym
data Datatype = Datatype
{ _datatypeName :: Name,
_datatypeParams :: [TypeVar],
_datatypeConstructors :: [Constructor]
_datatypeConstructors :: [Constructor],
_datatypeComment :: Maybe Text
}

data Constructor = Constructor
{ _constructorName :: Name,
_constructorArgTypes :: [Type]
_constructorArgTypes :: [Type],
_constructorComment :: Maybe Text
}

data Record = Record
{ _recordName :: Name,
_recordParams :: [TypeVar],
_recordFields :: [RecordField]
_recordFields :: [RecordField],
_recordComment :: Maybe Text
}

data RecordField = RecordField
{ _recordFieldName :: Name,
_recordFieldType :: Type
_recordFieldType :: Type,
_recordFieldComment :: Maybe Text
}

makeLenses ''Definition
Expand Down
26 changes: 16 additions & 10 deletions src/Juvix/Compiler/Backend/Isabelle/Translation/FromTyped.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ goModule onlyTypes infoTable Internal.Module {..} =
Record
{ _recordName = _inductiveName,
_recordParams = params,
_recordFields = map goRecordField tyargs
_recordFields = map goRecordField tyargs,
_recordComment = _inductiveComment
}
| otherwise =
StmtDatatype
Datatype
{ _datatypeName = _inductiveName,
_datatypeParams = params,
_datatypeConstructors = map goConstructorDef _inductiveConstructors
_datatypeConstructors = map goConstructorDef _inductiveConstructors,
_datatypeComment = _inductiveComment
}
where
params = map goInductiveParameter _inductiveParameters
Expand All @@ -111,20 +113,22 @@ goModule onlyTypes infoTable Internal.Module {..} =
goRecordField Internal.FunctionParameter {..} =
RecordField
{ _recordFieldName = fromMaybe (defaultName "_") _paramName,
_recordFieldType = goType _paramType
_recordFieldType = goType _paramType,
_recordFieldComment = Nothing
}

goConstructorDef :: Internal.ConstructorDef -> Constructor
goConstructorDef Internal.ConstructorDef {..} =
Constructor
{ _constructorName = _inductiveConstructorName,
_constructorArgTypes = tyargs
_constructorArgTypes = tyargs,
_constructorComment = _inductiveConstructorComment
}
where
tyargs = map (goType . (^. Internal.paramType)) (fst $ Internal.unfoldFunType _inductiveConstructorType)

goDef :: Name -> Internal.Expression -> [Internal.ArgInfo] -> Maybe Internal.Expression -> Statement
goDef name ty argsInfo body = case ty of
goDef :: Name -> Internal.Expression -> [Internal.ArgInfo] -> Maybe Internal.Expression -> Maybe Text -> Statement
goDef name ty argsInfo body comment = case ty of
Internal.ExpressionUniverse {} ->
StmtSynonym
Synonym
Expand All @@ -137,14 +141,16 @@ goModule onlyTypes infoTable Internal.Module {..} =
Function
{ _functionName = name',
_functionType = goType ty,
_functionClauses = goBody argnames ty body
_functionClauses = goBody argnames ty body,
_functionComment = comment
}
| otherwise ->
StmtDefinition
Definition
{ _definitionName = name',
_definitionType = goType ty,
_definitionBody = maybe ExprUndefined goExpression' body
_definitionBody = maybe ExprUndefined goExpression' body,
_definitionComment = comment
}
where
argnames =
Expand Down Expand Up @@ -191,10 +197,10 @@ goModule onlyTypes infoTable Internal.Module {..} =
(pats, nset', nmap') = goPatternArgs'' (filterTypeArgs 0 ty (toList _lambdaPatterns))

goFunctionDef :: Internal.FunctionDef -> Statement
goFunctionDef Internal.FunctionDef {..} = goDef _funDefName _funDefType _funDefArgsInfo (Just _funDefBody)
goFunctionDef Internal.FunctionDef {..} = goDef _funDefName _funDefType _funDefArgsInfo (Just _funDefBody) _funDefComment

goAxiomDef :: Internal.AxiomDef -> Statement
goAxiomDef Internal.AxiomDef {..} = goDef _axiomName _axiomType [] Nothing
goAxiomDef Internal.AxiomDef {..} = goDef _axiomName _axiomType [] Nothing _axiomComment

goType :: Internal.Expression -> Type
goType ty = case ty of
Expand Down
3 changes: 2 additions & 1 deletion src/Juvix/Compiler/Internal/Extra/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ instance HasExpressions ConstructorDef where
{ _inductiveConstructorType = ty',
_inductiveConstructorName,
_inductiveConstructorIsRecord,
_inductiveConstructorPragmas
_inductiveConstructorPragmas,
_inductiveConstructorComment
}

typeAbstraction :: IsImplicit -> Name -> FunctionParameter
Expand Down
3 changes: 2 additions & 1 deletion src/Juvix/Compiler/Internal/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ data ConstructorDef = ConstructorDef
{ _inductiveConstructorName :: ConstrName,
_inductiveConstructorType :: Expression,
_inductiveConstructorIsRecord :: Bool,
_inductiveConstructorPragmas :: Pragmas
_inductiveConstructorPragmas :: Pragmas,
_inductiveConstructorComment :: Maybe Text
}
deriving stock (Data)

Expand Down
3 changes: 2 additions & 1 deletion src/Juvix/Compiler/Internal/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ goConstructorDef retTy ConstructorDef {..} = do
{ _inductiveConstructorType = ty',
_inductiveConstructorName = goSymbol _constructorName,
_inductiveConstructorIsRecord = isRhsRecord _constructorRhs,
_inductiveConstructorPragmas = pragmas'
_inductiveConstructorPragmas = pragmas',
_inductiveConstructorComment = fmap ppPrint _constructorDoc
}
where
goAdtType :: Concrete.RhsAdt 'Scoped -> Sem r Internal.Expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ checkInductiveDef InductiveDef {..} = runInferenceDef $ do
{ _inductiveConstructorType = cty',
_inductiveConstructorName,
_inductiveConstructorIsRecord,
_inductiveConstructorPragmas
_inductiveConstructorPragmas,
_inductiveConstructorComment
}
registerConstructor c'
return c'
Expand Down

0 comments on commit e4a254b

Please sign in to comment.