On Thu, Jan 26, 2012 at 2:31 PM, Thomas Schilling
<
nominolo@googlemail.com> wrote:
>
>
> On 26 January 2012 09:24, Christopher Brown <
cmb21@st-andrews.ac.uk> wrote:
>> Hi Thomas,
>>
>> By static semantics I mean use and bind locations for every name in the
>> AST.
>
> Right, that's what the renamer does in GHC. The GHC AST is parameterised
> over the type of identifiers used. The three different identifier types
> are:
>
> RdrName: is the name as it occurred in source code. This is the output of
> the parser.
> Name: is basically RdrName + unique ID, so you can distinguish two "x"s
> bound at different locations (this is what you want). This is the output of
> the renamer.
> Id: is Name + Type information and consequently is the output of the type
> checker.
>
> Diagram:
>
> String --parser--> HsModule RdrName --renamer--> HsModule Name
> --type-checker--> HsBinds Id
>
> Since you can't hook in-between renamer and type checker, it's perhaps more
> accurately depicted as:
>
> String --parser--> HsModule RdrName --renamer+type-checker-->
> (HsModule Name, HsBinds Id)
>
> The main reasons why it's tricky to use the GHC API are:
>
> You need to setup the environment of packages etc. E.g., the renamer needs
> to look up imported modules to correctly resolve imported names (or give a
> error).
> The second is that the current API is not designed for external use. As I
> mentioned, you cannot run renamer and typechecker independently, there are
> dozens of invariants, there are environments being updated by the various
> phases, etc. For example, if you want to generate code it's probably best
> to either generate HsModure RdrName or perhaps the Template Haskell API
> (never tried that path).
>
>