asviraspossible at gmail.com
Wed Aug 3 12:09:15 CEST 2011
On Wed, Aug 3, 2011 at 11:30 AM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:
> GHC is supposed to be extensible, via its API, so your questions are good ones. However, there are things that that the API doesn't support, or supports badly, so it is not cast in stone. Please suggest improvements -- and better still implement them. GHC evolves largely in response to your suggestions and help.
> I imagine that your general plan is:
> - use the GHC API to parse Hasekll, typecheck it, optimise it
> - finishing with a [CoreBind] of optimised definitions
Yes, I'm doing it, but I'm moving slightly fearther
- I convert [CoreBind] to [StgBind] through GHC API.
> | == Command line interface ==
> | This works, but I'm not allowed to parse some custom flags used by
> | GHCJS code and not by GHC API.
> | ParseDynamicFlags throws UsageError if it encounters some unknown flags.
> So perhaps that's the problem. parseDynamicFlags could perfectly well simply return any un-recognised flags. Indeed, I thought it did just that -- it certainly returns a list of un-consumed arguments. If it doesn't perhaps that's a bug.
parseDynamicFlags returns un-consumed arguments if they are something
like filenames, but it throws error if un-consumed argument starts
> | == Foreign Function Interface ==
> | extend FFI declaration syntax.
> | jsalert :: Ptr JSString -> IO ()
> OK, so this is harder. Presumably you want to use an *unmodified* Haskell parser to parse the Haskell programs. Adding *syntactic* extensions is therefore somewhat invasive:
> - change the lexer
> - change the parser
> - change the HsSyn data structure
> - change every function that traverses HsSyn
> However in this particular case maybe things are not so bad. I believe that perhaps *all* you want is to add a new calling convention. See ForeignImport in HsDecls, and CCallConv in ForeignCall. Simply adding a new data constructor to CCallConv, and lexing the token for it, would not be too bad. We could possibly add that part to the mainline compiler. The compiler would largely ignore such decls, and they'd just pop out at the other end for your back end to consume.
This would be cool. I will try to provide patch to add all calling
conventions that backend implementors can use.
But GHC should report errors about unsupported calling conventions
sometime during compilation when should it?
> There might be complications -- see DsForeign in particular -- but I expect they'd be minor.
> | For now I'm using (abusing) ccall calling convention and simple
> | imports works pretty well, but I would like to support
> | exports and static/dynamic wrappers. GHC generates C-code to support
> | stubs. Is it possible at all?
> Well, GHC generates the stub code in its code generator, doesn't it? If you don't call the code generator, because you are using yours instead, then it'll be up to you to generate the stub code, no?
I can access ForeignStubs datatype, but I think it already have
generated C-code in it, havn't it? What step during compilation I
should generate stubs on?
More information about the Glasgow-haskell-users