Skip to content

Commit

Permalink
make ormolu happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Dec 23, 2022
1 parent a944a1c commit ac5cd53
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/Juvix/Compiler/Core/Transformation/NatToInt.hs
Expand Up @@ -17,8 +17,9 @@ convertNode tab = convert [] 0
go levels bl node = case node of
NVar (Var {..}) ->
End' (mkVar _varInfo (_varIndex + length (filter (\x -> x >= bl - _varIndex) levels)))
NApp (App _ (NIdt (Ident {..})) l) | Just _identSymbol == tab ^. infoIntToNat ->
End' (convert levels bl l)
NApp (App _ (NIdt (Ident {..})) l)
| Just _identSymbol == tab ^. infoIntToNat ->
End' (convert levels bl l)
NApp (App _ (NApp (App _ (NIdt (Ident {..})) l)) r) ->
Recur' (levels, convertIdentApp node (\op -> mkBuiltinApp _identInfo op [l, r]) _identSymbol)
NApp (App _ (NIdt (Ident {..})) l) ->
Expand Down Expand Up @@ -97,6 +98,6 @@ natToInt tab = mapT (const (convertNode tab')) tab'
tab' =
case tab ^. infoIntToNat of
Just sym ->
tab{_identContext = HashMap.insert sym (mkLambda' (mkVar' 0)) (tab ^. identContext)}
tab {_identContext = HashMap.insert sym (mkLambda' (mkVar' 0)) (tab ^. identContext)}
Nothing ->
tab
49 changes: 27 additions & 22 deletions src/Juvix/Compiler/Core/Translation/FromInternal.hs
Expand Up @@ -29,32 +29,37 @@ mkIdentIndex :: Name -> Text
mkIdentIndex = show . (^. Internal.nameId . Internal.unNameId)

setupIntToNat :: Symbol -> InfoTable -> InfoTable
setupIntToNat sym tab = tab{
_infoIdentifiers = HashMap.insert sym ii (tab ^. infoIdentifiers),
_identContext = HashMap.insert sym node (tab ^. identContext),
_infoIntToNat = Just sym
}
where
ii = IdentifierInfo {
_identifierSymbol = sym,
_identifierName = "intToNat",
_identifierLocation = Nothing,
_identifierArgsNum = 1,
_identifierArgsInfo = [ArgumentInfo {
_argumentName = "x",
_argumentLocation = Nothing,
_argumentType = mkTypePrim' (PrimInteger $ PrimIntegerInfo Nothing Nothing),
_argumentIsImplicit = Explicit
}],
_identifierType = mkDynamic',
_identifierIsExported = False,
_identifierBuiltin = Nothing
setupIntToNat sym tab =
tab
{ _infoIdentifiers = HashMap.insert sym ii (tab ^. infoIdentifiers),
_identContext = HashMap.insert sym node (tab ^. identContext),
_infoIntToNat = Just sym
}
where
ii =
IdentifierInfo
{ _identifierSymbol = sym,
_identifierName = "intToNat",
_identifierLocation = Nothing,
_identifierArgsNum = 1,
_identifierArgsInfo =
[ ArgumentInfo
{ _argumentName = "x",
_argumentLocation = Nothing,
_argumentType = mkTypePrim' (PrimInteger $ PrimIntegerInfo Nothing Nothing),
_argumentIsImplicit = Explicit
}
],
_identifierType = mkDynamic',
_identifierIsExported = False,
_identifierBuiltin = Nothing
}
node =
case (tagZeroM, tagSucM, boolSymM) of
(Just tagZero, Just tagSuc, Just boolSym) ->
mkLambda' $
mkIf' boolSym
mkIf'
boolSym
(mkBuiltinApp' OpEq [mkVar' 0, mkConstant' (ConstInteger 0)])
(mkConstr (setInfoName "zero" mempty) tagZero [])
(mkConstr (setInfoName "suc" mempty) tagSuc [mkApp' (mkIdent' sym) (mkBuiltinApp' OpIntSub [mkVar' 0, mkConstant' (ConstInteger 1)])])
Expand All @@ -74,7 +79,7 @@ fromInternal i = do
}
where
tab0 :: InfoTable
tab0 = emptyInfoTable{_infoIntToNat = Just intToNatSym, _infoNextSymbol = intToNatSym + 1}
tab0 = emptyInfoTable {_infoIntToNat = Just intToNatSym, _infoNextSymbol = intToNatSym + 1}

intToNatSym :: Symbol
intToNatSym = 0
Expand Down

0 comments on commit ac5cd53

Please sign in to comment.