-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RawType code generation via ghc-exactprint (#215)
Separated out HsRawType out of HsFrontend. implemented mkData, mkNewtype, mkDeriving etc. so that RawType can be generated and tested. * separate out HsRawType * mkData, mkNewtype. HsRawType is almost converted. * now no missing part in HsRawType * mkDeriving * mkTypeFamInst * generated code formatting correctly. now it works! * ormolu
- Loading branch information
Showing
8 changed files
with
288 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module FFICXX.Generate.Code.HsRawType | ||
( hsClassRawType, | ||
) | ||
where | ||
|
||
import FFICXX.Generate.Name (hsClassName) | ||
import FFICXX.Generate.Type.Class (Class (..)) | ||
import FFICXX.Generate.Util.GHCExactPrint | ||
( con, | ||
conDecl, | ||
cxEmpty, | ||
instD, | ||
mkBind1, | ||
mkData, | ||
mkDeriving, | ||
mkInstance, | ||
mkNewtype, | ||
mkPVar, | ||
mkTypeFamInst, | ||
mkVar, | ||
pApp, | ||
parP, | ||
tyPtr, | ||
tyapp, | ||
tycon, | ||
) | ||
import GHC.Hs (GhcPs) | ||
import Language.Haskell.Syntax | ||
( HsDecl (TyClD), | ||
noExtField, | ||
) | ||
|
||
hsClassRawType :: Class -> [HsDecl GhcPs] | ||
hsClassRawType c = | ||
[ TyClD noExtField (mkData rawname [] []), | ||
TyClD | ||
noExtField | ||
( mkNewtype | ||
highname | ||
(conDecl highname [tyapp tyPtr rawtype]) | ||
deriv | ||
), | ||
instD $ | ||
mkInstance | ||
cxEmpty | ||
"FPtr" | ||
[hightype] | ||
[ mkTypeFamInst "Raw" [hightype] rawtype | ||
] | ||
[ mkBind1 | ||
"get_fptr" | ||
[parP (pApp highname [mkPVar "ptr"])] | ||
(mkVar "ptr") | ||
Nothing, | ||
mkBind1 "cast_fptr_to_obj" [] (con highname) Nothing | ||
] | ||
] | ||
where | ||
(highname, rawname) = hsClassName c | ||
hightype = tycon highname | ||
rawtype = tycon rawname | ||
deriv = mkDeriving [tycon "Eq", tycon "Ord", tycon "Show"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.