[MLton-user] Mac OS X on Intel

Matthew Fluet fluet@cs.cornell.edu
Thu, 20 Apr 2006 10:00:55 -0400 (EDT)


>> I doubt the binary packages will run on an Intel Mac, as I'm confident
>> that they were compiled for a PowerPC Mac.
>
> They will, Mac OS X on Intel includes PowerPC emulation, same as
> Power macs ran 68000 binaries (obviously, otherwise nobody would
> buy something which can't run any existing software!).

Oh, that's very nice.  Then I'd say give it a try and report your 
experience.  You will probably have to tweak
   /usr/local/lib/mlton/platform
to have it report a PowerPC arch, otherwise MLton will complain of an 
unknown os/arch pair.  If you are lucky, that will get you to the point 
where
   /usr/local/bin/mlton
will actually do something interesting, rather than bailing.

The entire front-end and middle-end of the compiler ought to be agnostic 
to the new platform.  I would expect that you could get to the point where 
MLton dumps .c files and calls gcc to compile and link.  Here, you will 
almost certainly have more problems, because I suspect that gcc on Intel 
Macs defaults to compiling to x86 binaries.  You'll have issues when gcc 
tries linking those x86 object files with the PowerPC libmlton.a libary. 
(I'm guessing that the PowerPC emulation doesn't extend to mixed 
architectures within a single binary.)  If the gcc available on Intel Macs 
is configured to have cross-compilation to Intel PowerPC platform, then 
you can probably hack the
   /usr/local/bin/mlton
script to pass the appropriate flags to gcc for compiling and linking as 
PowerPC.  (See, for example, the  '-target-* amd64'  where we pass '-m32' 
to treat amd64 as a 32 bit platform.)  Unfortunately, I note that we don't 
have a way to set target options for arch/os pairs, so there isn't a way 
to set a darwin-x86 option that doesn't impact either darwin-powerpc or 
linux-x86.

That just might let you get to the point where you can compile and run the 
resulting executable, but everything will be PowerPC architecture.

> But it will be worth rebuilding to get better performance.

Certainly.  You're probably best off following the PortingMLton guidelines 
on the website.  (If the above works, you might be able to simplify 
things a little bit since you won't need as complicated cross 
compilation, but it will nonetheless be a delicate bootstrap operation.)

You'll need to configure the darwin-x86 platform to use the C-codegen, 
since I understand that Intel Macs use a slightly different assembler 
syntax and calling convention than other Intel platforms.