9

Currently I'm doing a recherche for university about F#. I have a question about the F# interactive Console and the F# compiler.

The F# compiler produces Microsoft Intermediate Language (MSIL) code when its compiling F#-source. This is then translated by the JIT-compiler to machine code, when executing the written program.

But what does the F# Interpreter Console do? Does it also line-per-line translate the F# Code into MSIL, and then JIT that into machine code? Or does it translate the F#-Code directly into machine code?

If it converts it to IL first, then I think there probably will be an IL-interpreter because the JIT-compiler only compiles complete programs. Won't it?

What do you think, how F#-interpreter handles F# code and translates it?

Greetings, Martin

Henk Holterman
  • 236,989
  • 28
  • 287
  • 464
martin
  • 2,797
  • 3
  • 23
  • 42

1 Answers1

15

The F# compiler emits IL using its own library AbsIL. AbsIL is another MSR project which was absorbed by F#.

When compiling for the interactive mode, AbsIL uses the System.Reflection.Emit namespace to emit IL in memory, at runtime, which is in turn compiled to native code by the JIT as it executes the code.

Jb Evain
  • 16,611
  • 2
  • 63
  • 66
  • A quick grep of the source seems to suggest that AbsIL doesn't use System.Reflection.Emit but generates a binary directly to a .NET BinaryWriter stream. In places it also seems to use a custom ByterBuffer defined in bytes.fs. I believe this is because originally AbsIL had to cross compile with OCaml but has moved away from that as the compiler was boot strapped. – Robert Jan 07 '11 at 12:54
  • 1
    @Robert, have a look at the second link of my post, you'll see that it has a SRE backend, as specified in the header: «Write Abstract IL structures at runtime using Reflection.Emit» – Jb Evain Jan 07 '11 at 13:05
  • Also, considering the number of issues that fsi triggered, and is still triggering in Mono's implementation of SRE, I can tell by experience :) – Jb Evain Jan 07 '11 at 13:11
  • I didn't read your answer properly :§, I thought you saying it used SRE for runtime and compile time. D'oh! – Robert Jan 07 '11 at 13:15