Calling convention for JavaScript?

Edward Z. Yang ezyang at MIT.EDU
Mon Mar 18 08:34:12 CET 2013


My guess is that you're out of luck without extending FFI to support
another convention.  Here's a possible workaround, however: continue to
use ccall import syntax, but provide the extra information you wanted
to convey in the name out-of-band.

Cheers,
Edward

Excerpts from Luite Stegeman's message of Sun Mar 17 23:55:41 -0700 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