10

I just looked at the source of Mono for the first time and I thought I would find a bunch of C or C++ code, instead I found 26,192 .cs files and 7 .cpp files.

I am not totally shocked but it made me think of a quesiton I've always had in the back of my mind:

How does a project end up being written in "itself" like this?

Was an older version of mono more c/c++? Or was there initial effort to create some kind of machine coded compiler...

What's the "trick" here?

Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
  • possible duplicate of [Bootstrapping a language](http://stackoverflow.com/questions/13537/bootstrapping-a-language) – sarnold Nov 07 '11 at 01:47
  • 1
    If you're impressed by mono, you should check out Singularity. It's an OS written almost entirely in C# with just a portion done in Assembly – Michael Brown Nov 07 '11 at 07:05

3 Answers3

10

Mono's compiler is written in C#. You may want to read about compiler bootstrapping.

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142
TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • 4
    Mono had the advantage of using Microsoft's C# compiler in the early days to solve the chicken and egg problem. Now of course it uses a binary of itself to compile itself. – jpobst Nov 07 '11 at 02:36
2

You should be looking for .c files, instead of .cpp files: the mono runtime is written in C, not C++.

lupus
  • 3,963
  • 1
  • 18
  • 13
0

I think it is also important to remember that mono is both a virtual machine runtime (the JIT compiler, garbage collector, etc.) as well as a collection of class libraries that run on this framework (the System.Linq namespace, the XML parsers, etc.).

The majority of the .cs files you see are part of the class libraries. These are basically C# code that run like your own C# code (with some exceptions, but basically it doesn't make sense for everyone to reinvent and re-distribute the wheel over and over, so these are the C# "base" class libraries). This is why you can download complex mono programs as such small file sizes if mono is already installed on the machine.

For mono, the JIT, runtime and garbage collector are largely written in C/C++ as you would expect. If you ever get a low level error, you will often see GNU debug tool dumps as you would in C, just with lots more useful information. The Mono framework is very good at taking any C# code and converting it to CIL code that can run anywhere, and they use whatever toolset is best suited to ensure the code does run anywhere (which in this case meant a C compiler runtime on linux).

evolvedmicrobe
  • 2,672
  • 2
  • 22
  • 30