[MLton] Question about Library Calls
Matthew Fluet
fluet at cs.cornell.edu
Wed Nov 1 14:00:13 PST 2006
>> > So... after a long period of trying to debug the Gamma-CFA code that
>> > I've written, I've reached a point where I need to know a little bit
>> > more about MLton. We've gotten it to run on a variety of test cases
>> > involving no application of the standard library (such as a factorial
>> > program that just computes the value of factorial, but doesn't print
>> > it). When run on code that contains a print statement (even just
>> > hello world) it loops forever.
>>
>> What "loops forever"? The Gamma-CFA code or the final executable?
>
> The Gamma-CFA code.
O.k. I'll reiterate that we would be happy to create a Gamma-CFA branch
in the mlton.org repository; many eyes make light work. ;-)
>> > I was wondering what you could tell me about how MLton implements the
>> > library call (such as the print statement), and what operations it
>> > performs that are not present in code that doesn't use any library
>> > calls.
>>
>> Even your factorial function is using the Basis Library, in order to
>> access the definitions of Int.- and Int.*. Nonetheless, these kinds of
>> functions become primitives (Prim.Name.Word_sub, Print.Name.Word_mul) in
>> the compiler ILs. Other Basis Library functions that correspond to
>> interaction with the outside world (e.g., TextIO.print) are implemented
>> via normal SML code plus some external C calls. These external C calls
>> also become primitives in the compiler ILs, but they are of the
>> Prim.Name.FFI variant.
>
> Hmm... ok. So there isn't anything significantly different between
> the factorial function and a similar function with that prints the
> result, except for the FFI call?
The significant differences will be the FFI call and the amount of code to
be analyzed. There is a dead-code pass that runs before the conversion to
the XML IL, that, in the absence of IO in the user program, will discard
vast quantities of the Basis Library implementation.
More information about the MLton
mailing list