Changes between Version 1 and Version 2 of Commentary/Compiler/CaseStudies/Bool


Ignore:
Timestamp:
Jan 23, 2013 5:01:21 PM (2 years ago)
Author:
jstolarek
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/CaseStudies/Bool

    v1 v2  
    55== Constants for Bool type and data constructors == 
    66 
    7 All data constructors, type constructors and so on have their unique identifier which is needed during the compilation process. For the wired-in types these unique values are defined in the `prelude/PrelNames.lhs`. In case of `Bool` the relevant definitions look like this: 
     7All data constructors, type constructors and so on have their unique identifier which is needed during the compilation process. For the wired-in types these unique values are defined in the [[GhcFile(prelude/PrelNames.lhs)]]. In case of `Bool` the relevant definitions look like this: 
    88 
    99{{{ 
     
    1616=== A side note on generating Unique values === 
    1717 
    18 The `mkPreludeTyConUnique` and `mkPreludeDataConUnique` take care of generating a unique `Unique` value. They are defined in `basicTypes/Unique.lhs`: 
     18The `mkPreludeTyConUnique` and `mkPreludeDataConUnique` take care of generating a unique `Unique` value. They are defined in [[GhcFile(basicTypes/Unique.lhs)]]: 
    1919 
    2020{{{ 
     
    2828}}} 
    2929 
    30 You will find definition of `mkUnique :: Char -> Int -> Unique` at line 135 in `basicTypes/Unique.lhs`. 
     30You will find definition of `mkUnique :: Char -> Int -> Unique` at line 135 in [[GhcFile(basicTypes/Unique.lhs)]]. 
    3131 
    3232== Defining wired-in information about Bool == 
    3333 
    34 All the wired-in information that compiler needs to know about `Bool` is defined in `prelude/TysWiredIn.lhs`. This file exports following functions related to `Bool`: 
     34All the wired-in information that compiler needs to know about `Bool` is defined in [[GhcFile(prelude/TysWiredIn.lhs)]]. This file exports following functions related to `Bool`: 
    3535 
    3636{{{ 
     
    5555}}} 
    5656 
    57 `boolTyConKey`, `falseDataConKey` and `trueDataConKey` are `Unique` values defined earlier. `boolTyCon`, `falseDataCon` and `trueDataCon` are yet undefined. Type of syntax is defined in `basicTypes/Names.lhs`, line 129: 
     57`boolTyConKey`, `falseDataConKey` and `trueDataConKey` are `Unique` values defined earlier. `boolTyCon`, `falseDataCon` and `trueDataCon` are yet undefined. Type of syntax is defined in [[GhcFile(basicTypes/Names.lhs)]], line 129: 
    5858 
    5959{{{ 
     
    6161}}} 
    6262 
    63 `BuiltInSyntax` is used for things like (:), [] and tuples. All other things are `UserSyntax`. `gHC_TYPES` is a module `GHC.Types` to which these type and data constructors get assigned. It is defined in `prelude/PrelNames.lhs`: 
     63`BuiltInSyntax` is used for things like (:), [] and tuples. All other things are `UserSyntax`. `gHC_TYPES` is a module `GHC.Types` to which these type and data constructors get assigned. It is defined in [[GhcFile(prelude/PrelNames.lhs)]]: 
    6464 
    6565{{{ 
     
    7070}}} 
    7171 
    72 `FastString` is a string type based on `ByteStrings` and the `fsLit` function converts a standard Haskell `Strings` to `FastString`. See `utils/FastString.lhs` for more details. 
     72`FastString` is a string type based on `ByteStrings` and the `fsLit` function converts a standard Haskell `Strings` to `FastString`. See [[GhcFile(utils/FastString.lhs)]] for more details. 
    7373 
    7474=== A side note on creating wired-in Names === 
    7575 
    76 `Name` is a data type used across the compiler to give a unique name to something and identify where that thing originated from (see [http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/NameType NameType] for more details): 
     76`Name` is a data type used across the compiler to give a unique name to something and identify where that thing originated from (see [wiki:Commentary/Compiler/NameType NameType] for more details): 
    7777 
    7878{{{ 
     
    9292}}} 
    9393 
    94 The `mkWiredInTyConName` and `mkWiredInDataConName` are functions that create `Name`s for wired in types and data constructors. They are defined in `prelude/TysWiredIn.lhs`, lines 163-173: 
     94The `mkWiredInTyConName` and `mkWiredInDataConName` are functions that create `Name`s for wired in types and data constructors. They are defined in [[GhcFile(prelude/TysWiredIn.lhs)]], lines 163-173: 
    9595 
    9696{{{ 
     
    108108}}} 
    109109 
    110 The `mkWiredInName` is defined in `basicTypes/Names.lhs` (lines 279-283), and it just assigns values to fields of `Name`: 
     110The `mkWiredInName` is defined in [[GhcFile(basicTypes/Names.lhs)]] (lines 279-283), and it just assigns values to fields of `Name`: 
    111111 
    112112{{{ 
     
    120120== !RdrNames for Bool == 
    121121 
    122 Having defined `Name`s for `Bool`, the [http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/RdrNameType RdrName]s can be defined (`prelude/TysWiredIn.lhs`, lines 221-225): 
     122Having defined `Name`s for `Bool`, the [wiki:Commentary/Compiler/RdrNameType RdrName]s can be defined ([[GhcFile(prelude/TysWiredIn.lhs)]], lines 221-225): 
    123123 
    124124{{{ 
     
    158158=== A side note on functions generating type and data constructors === 
    159159 
    160 `types/TypeRep.lhs`, lines 281-282: 
     160[[GhcFile(types/TypeRep.lhs)]], lines 281-282: 
    161161 
    162162{{{ 
     
    165165}}} 
    166166 
    167 `prelude/TysWiredIn.lhs`, 247-257: 
     167[[GhcFile(prelude/TysWiredIn.lhs)]], 247-257: 
    168168 
    169169{{{ 
     
    226226}}} 
    227227 
    228 `falseDataConId` and `trueDataConId` just extract `Id` from previously defined data constructors. These definitions are from `basicTypes/DataCon.lhs`: 
     228`falseDataConId` and `trueDataConId` just extract `Id` from previously defined data constructors. These definitions are from [[GhcFile(basicTypes/DataCon.lhs)]]: 
    229229 
    230230{{{ 
     
    242242== Final remarks == 
    243243 
    244 Remember that all the non-primitive wired-in things are also defined in GHC's libraries. `Bool` is defined in ghc-prim library, `GHC.Types` module: {{{data {-# CTYPE "HsBool" #-} Bool = False | True}}} See [http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/WiredIn Wired-in and known-key things] for more details 
     244Remember that all the non-primitive wired-in things are also defined in GHC's libraries. `Bool` is defined in ghc-prim library, `GHC.Types` module:  
     245 
     246{{{ 
     247data {-# CTYPE "HsBool" #-} Bool = False | True 
     248}}} 
     249 
     250See [wiki:Commentary/Compiler/WiredIn wired-in and known-key things] for more details 
    245251 
    246252= TODO =