[MLton] Documentation on _export

Matthew Fluet fluet@cs.cornell.edu
Fri, 23 Sep 2005 10:14:10 -0400 (EDT)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--1417689696-305866168-1127484850=:1241
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE


> Matthew Fluet wrote:
>> Jens Axel S=F8gard wrote
>>>  _export "C function name" attr... : cFuncTy -> unit;
>>>=20
>>>  Denotes a function that must be applied to a SML function f and
>>>  arranges for the exported C function to call the SML function.
>
>>> This suggests that the export happens when the denoted function
>>> is called, in other words that the export happends at runtime.
>>> That can't be right? What would an improved wording look like?
>
>> I think the wording is correct.  _export "foo"  ensures that there is a=
=20
>> symbol "foo" which may be called as a C function.  However, calling the=
=20
>> exported function before applying the "cFuncTy -> unit" denoted function=
 to=20
>> an SML function will result in an exception at runtime claiming that the=
=20
>> exported function hasn't yet been initialized.
>
> I see. The explicit explanation is thus:
>
>  _export "Cfunc" attr... : cFuncTy -> unit;
>
>  Exports a C function with the name "Cfunc" that can be used
>  to call an ML function of the type cFuncTy.
>  Before Cfunc is called from C, the function denoted by
>      _export "Cfunc" attr... : cFuncTy -> unit;
>  must be called with an SML function f whose (unfolded) type
>  is cFuncTy.

Yes, that is a good explaination of what is going on.

> Is it possible to call the function denoted _export ...
> twice and thus use the exported Cfunc to call different
> functions at different times?

Yes.
--1417689696-305866168-1127484850=:1241--