hnakamur’s blog

ものすごい勢いで忘れる私のために未整理でもいいからとりあえずメモ

2011-07-20

GHCのCharの定義を調べてみた

ghc-7.0.3-src.tar.bz2のincludeでCharを検索してみた。
$ grep -r Char includes
includes/RtsAPI.h:HaskellObj   rts_mkChar       ( Capability *, HsChar   c );
includes/RtsAPI.h:HsChar       rts_getChar      ( HaskellObj );
includes/Stg.h:typedef StgChar  C_;
includes/rts/storage/Closures.h:} StgIntCharlikeClosure;
includes/HsFFI.h:typedef StgChar   HsChar;
includes/HsFFI.h:/* this should correspond to the type of StgChar in StgTypes.h */
includes/stg/Types.h: StgChar, StgFloat, StgDouble
includes/stg/Types.h:typedef StgWord32          StgChar;
Binary file includes/stg/.Types.h.swp matches
includes/stg/Regs.h:    StgChar        c;
includes/stg/MiscClosures.h:extern DLL_IMPORT_RTS StgIntCharlikeClosure stg_CHARLIKE_closure[];
includes/stg/MiscClosures.h:extern DLL_IMPORT_RTS StgIntCharlikeClosure stg_INTLIKE_closure[];

StgWord32の定義はstg/Types.hにありました。

#if SIZEOF_LONG == 4
typedef signed   long            StgInt32;
typedef unsigned long            StgWord32;
#elif SIZEOF_INT == 4
typedef signed   int             StgInt32;
typedef unsigned int             StgWord32;
#else
#error GHC untested on this architecture: sizeof(int) != 4
#endif

というわけでGHCのCharは32bitです。

ブログ アーカイブ