Rabadash8820
Rabadash8820

Reputation: 2554

How is C# Separate From the .NET Framework?

I'm no newb when it comes to the .NET framework, I've been writing C# software that utilizes it for several years. However, a thought occurred to me the other day...how is C# separate from the .NET framework with keywords like lock and object? A statement like object derp = new object(); resolves to System.Object derp = new System.Object();, but System.Object is defined as part of .NET is it not? Even if it is defined in mscorlib, this means that a language feature is dependent on a library. The same goes for lock statements which resolve to calls to Monitor.Enter() and Montior.Exit(). Obviously it would be silly/impossible to write any non-toy program without using .NET features, but how can a language depend on a library that is largely written in that language?

Upvotes: 8

Views: 463

Answers (1)

Hans Passant
Hans Passant

Reputation: 942267

Minimum requirement to implement a language is to have a compiler to convert the language into executable code and a runtime system to execute it. Neither were written in C#, they used C++. Using another language to accomplish this is a traditional and necessary bootstrapping step. The C language is a very common choice for a bootstrapping language, it is small and very easy to port, the approach taken by Mono. C itself had a bootstrapping language, it was B. Which was bootstrapped off BCPL. Which was bootstrapped off CPL. Which was bootstrapped off Atlas2. Gets murky before that, imagine somebody using the toggle switches on the front panel of a very primitive computer.

Once that's in place you can start iterating and improving. Like adding support for the lock keyword, a language feature you don't need to get a compiler and runtime system going. It relies on the Monitor class, still very thin today with the vast majority of its code in C++.

Rewriting the compiler into the target language is often next, took quite a while for C# but now done with Roslyn. Rewriting the runtime system might be considered although that isn't very common. Done as a incubation project inside Microsoft, the secret Midori project. Not just the runtime but an entire operating system. Bootstrapped off the Singularity project.

Upvotes: 7

Related Questions