simonpj at microsoft.com
Wed Aug 3 09:30:10 CEST 2011
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
| == 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.
| == 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.
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?
| == Packages support ==
| It will be very handy if users can use Cabal to install and build
| packages with GHCJS.
| It should work if I replicate ghc and ghc-pkg command line interface,
| but remaining problem is that
| package index and package directories will be shared with GHC,
I don't know about this. Dunan or Simon may be able to help.
More information about the Glasgow-haskell-users