March 16, 2005 04:37 am (permalink)

Compiler thoughts

This week, there was some discussion about writing a Pascal Compiler on mono-devel-list. I'm not getting into the "political" debates here, but lemme post a few thoughts about the technical point of view.

First of all, writing a compiler isn't something you can do in a week or two. It's been almost two years now since I started working on GMCS - and I had an already existing and fairly stable codebase (MCS) to start with. You Pascal guys will probably start from scratch. So it doesn't hurt doing some careful planning and discussion first. Having a concrete roadmap may also help getting other people interested in the project.

There are two fundamentally different approaches on writing a new Pascal Compiler:

  • On the one hand, there is already a proprietary, but gratis command-line compiler for Pascal.
    This makes it possible to write the new compiler in Pascal, just like our C# compiler is written in C#.
  • On the other hand, you can also take the existing GMCS codebase and start from there.

I have no idea whether the first idea is feasible or not, so lemme just post a few thoughts about the second one.

At the moment, we already have three compilers:

  • Of course, there's our good old MCS which was there since the beginning
  • There is GMCS, which is based on MCS's codebase and also gets all the recent bug fixes and improvements from MCS since I periodically merge all changes into GMCS.
  • There is BMCS which is a compiler for VB.NET. This one was initially based on GMCS's code base and it also receives all the bug-fixes and improvements from GMCS.

Speaking of GMCS, there are four main tasks which I'm planning to finish till May if everything works fine:

  • Nullable Types - They should be finished by the end of this week.
  • Bug fixing - There are a lot of open bug reports in bugzilla, so I'll do a bug-fixing week next week.
  • Merging - It's been some time since I merged last time from MCS - this is also scheduled for next week.
  • .NET 1.x support - We need some configuration option to tell GMCS to produce 1.x-code only; this'll also tell it to use the 1.x corlib and class libraries, just like MCS does.

Once these tasks are done, GMCS should be ready to become our new production compiler.

After that, we should try to figure out how much the VB.NET guys needed to change from GMCS's original code base and what these changes are. Maybe it's possible to make a part of GMCS a library and share this between the two compilers. I could imagine that we can reuse large parts of GMCS without many modifications, for instance its type lookup system etc.

Such a library could also benefit any new compiler projects like a Pascal compiler - you could use that library, write a parser for your new language and do some language-specific modifications.

Posted by martin at March 16, 2005 04:37 am.

March 05, 2005 1:30 pm (permalink)

More Nullable Types

This week was a really good hacking week for me. I made good progress with Nullable Types and also found the time to do some general GMCS bug fixing. It's really cool that people are now actually using GMCS to compile their applications and file bug reports. The whole generics code is now fairly stable and almost ready for prime time, but I still need more bug reports ....

Regarding Nullable Types, I implemented lifted conversions and lifted operators (unary and binary so far). This means that you can use the "normal" (builtin and user-defined) operators with nullable types:

long? Multiply (int? a, int? b) { return a * b; }

This will return null if either a or b is null.

Next are comparisions with null values, for instance

bool IsNull (int? a) { return a == null; }

I'll also do some more bug fixing next week.

Posted by martin at March 05, 2005 1:30 pm.