.net-coreclrcoreclrboo

Compiler for CLR


I am working towards building a small language or dst that makes use of .net/clr. Aside from reading a lot the most progress I made is a C# program that takes some basic input (no ebnf actual lexing or fancy parsing) and used ILgenerator to create a hellow world program with opcodes.

This is obviously not a compiler but I thought calling the opcodes on the vm is what a compiler would do.

Researching the subject I noticed ILgenerator is not supported from netcore 3.0 and up (ms 'wants' to support it again in the future).

I looked into Boo looked promising but noticed it's stuck on .net with some blocking issues atm.

What I am wondering is,

  1. For a actual compiler would you also jsut call opcodes or how do I interact with clr without ILgenerator. Do I need to generate CIL/MSIL by hand?
  2. What are nice tools/languages to define a compiler for CLR without it doing all of the work for you.
  3. Do I need to target coreCLR nowadays instead of just clr ?

I try to center these topics around .net/C# since it's what I use at work atm and want to learn about the CLR /compilers.


Solution

  • Boo maintainer here.

    Researching the subject I noticed ILgenerator is not supported from netcore 3.0 and up (ms 'wants' to support it again in the future).

    I looked into Boo looked promising but noticed it's stuck on .net with some blocking issues atm.

    This is actually the same thing: the "blocking issue" is the inability to save assemblies, as Boo when was originally written, Reflection.Emit was basically the only game in town. There are better tools today but rewriting the IL generator to use them is a long, laborious process.

    For a actual compiler would you also jsut call opcodes or how do I interact with clr without ILgenerator. Do I need to generate CIL/MSIL by hand?

    Use better tools. These days it's generally recommended to use System.Reflection.Metadata for assembly generation. Roslyn (Microsoft's C# compiler) has its own internal system that appears to be based on CCI, even though CCI is officially deprecated and not recommended for anyone else to use.

    What are nice tools/languages to define a compiler for CLR without it doing all of the work for you.

    The bulk of the Boo compiler is written in C#. A few very high-level pieces are written in Boo. Ultimately it would be nice to get the whole thing in Boo, but that's a long-term goal.

    Do I need to target coreCLR nowadays instead of just clr ?

    Yes. .NET Framework 4 is officially a dead end according to the .NET Foundation, and the way forward is .NET Core, which they are simply calling ".NET" these days. The current version is named ".NET 6," but it's still the CoreCLR architecture.