Calling convention for JavaScript?

Luite Stegeman stegeman at gmail.com
Mon Mar 18 07:55:41 CET 2013


hi all,

We've been making some progress with GHCJS [1] recently (preemptive
lightweight threads, async io, black holes and async exceptions work
in the new code generator now), but have run into a problem with FFI
imports.

So far we've been using the ccall import syntax:

foreign import ccall "sin" :: CDouble -> CDouble

This would import the JavaScript function `h$sin` (in order to reduce
clashes with other JavaScript functions in foreign imports of existing
Haskell packages). Other than the ccall name, which is just a minor
niggle, this worked completely fine.

Now we would like to extend this, for example:

foreign import ccall "@cos" :: CDouble -> CDouble
(@ would escape the usual `h$` prefixing)

foreign import ccall "$r = $1.someMethod($2)" :: JSObject -> CDouble -> CDouble
(inline JavaScript macro, similar to Fay and UHC-JS)

Unfortunately GHC rejects these, since they're not valid C
identifiers. What we need is some calling convention that just accepts
any import string, but otherwise behaves like ccall. What would be a
good way of doing this, is it possible without changing GHC? If not,
would it be acceptable to add a calling convention?

Suggestions welcome!

luite

[1] https://github.com/ghcjs/ghcjs/tree/gen2-64-alth



More information about the ghc-devs mailing list