On 19/01/2015 04:34, David Topham wrote:
Thanks David for your response.
While searching I found this comment you made earlier:
"The foreign-function interface allows for call-back functions so there is
the mechanism to produce a C function that when called calls an ML
function."
in
http://stackoverflow.com/questions/17580386/shared-libraries-in-poly-ml
Doesn't this indicate a mechanism that allows an SML function to be called
from C?
Yes, but the "main program" still has to be in ML. You can call C
library functions and pass an ML function as an argument.
Actually, I did wonder whether this could be used as a way of exporting
ML functions to create a library that could be called from a C main
program and came to the conclusion that it was going to be too
complicated. Poly/ML uses libffi to interface with C. libffi can build
closures that wrap around ML functions so that these can be passed into
C. The format of the closure it constructs differs markedly depending
on the particular architecture since different architectures have
different calling conventions for C. The closure is a data structure
with pointers in it. Exporting it would require turning the pointers
into relocations that the linker/loader will understand. libffi simply
doesn't provide that information. It's there by implication in the
source code but not explicitly.
David
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml