[MLton] Re: i386-darwin external _symbols

Matthew Fluet fluet at tti-c.org
Sat Aug 30 16:08:24 PDT 2008


On Sun, 24 Aug 2008, Wesley W. Terpstra wrote:
> Hey. I've been working on a patch to generate symbol stubs for darwin-i386.
> I can't test it, as I don't have an i386 mac. Also, I'm not sure how to get
> the assembly I generate to end up in the output. The function
> makeDarwinNonLazySymbolPointers needs to be called somewhere to output the
> symbols at the bottom of each assembler file.
>
> Once the patch works, the following should compile (as an executable):
> val f = _import "cos" external: real -> real;
> val g = _import * : MLton.Pointer.t -> real -> real;
> val h = _address "sin" external: MLton.Pointer.t;
> val () = print (Real.toString (f 4.0) ^ "\n")
> val () = print (Real.toString (g h 4.0) ^ "\n")
> As far as I understand it, this will not work currently. That's what my
> patch is attempting to fix.
>
> If you could take a whack on the attached patch when you have some spare
> time, I'd appreciate it.

I've committed your patch plus a few more that gets external functions and 
symbols working on x86-darwin.

The above code works with the native codegen, but not with the C codegen 
--- due to the fact that 'sin' is declared as a function in <math.h> and 
then declared as an untyped extern (defaulting to int; would it be better 
to declare _address symbols as 'extern void'?) in the generated C code.

A somewhat better example than the above might be:

val lgamma = _import "lgamma" external: Real64.real -> Real64.real;
val signgamAddr = _address "signgam" external: MLton.Pointer.t;
val signgam = fn () => MLton.Pointer.getInt32 (signgamAddr, 0)

val () = (print o concat)
    ["lgamma(10.0) = ", Real64.toString (lgamma 10.0), "; ",
     "signgam = ", Int32.toString (signgam ()), "\n"]

which works with the native and C codegens.




More information about the MLton mailing list