Thursday, July 21, 2005

Types and linkers

The compiler is coming along well. Lately I've been hacking on aggregate types and the linker, along with the usual work on the CIL instruction generation.

Aggregate Types
For the first stage, I've just implemented aggregate types as chunks of memory of the appropriate size. That is, both char foo[28]; and struct X { int i; float f; char s[20]; }; are simply represented in the IL as an object of type "S28", or 28-byte type. I am planning to eventually emit the equivalent CIL types for each 'native' type. This would allow a number of advantages over the current technique: we can probably take advantage of CIL function overload resolution (currently I simply use the mangled names), and we can allow for proper interoperability with other CIL languages. For example, allowing C structs and C++ classes to be used from C#, VB, etc. I had originally planned to implement this from the start, but later realized that it would be difficult to implement correctly with my poor understanding of GCC and the CIL type system, and decided that my time would be better spent getting everything working first.

The Linker
Last week I wrote the first iteration of the linker in Python. The compiler emits "linker annotations" with information on types, methods, strings, global variables, and references to the aforementioned. The linker itself is a fairly simple python script which checks the references, removes duplicates, and rewrites its input. In the near future I plan to add support to the linker to automatically generate P/Invoke declarations for calls to native methods, and do some fixups on function calls where the prototype is not known ahead of time. Once the linker functionality stabilizes a bit, I think I'll reimplement it in C#.

Sunday, July 03, 2005

"OK, so pointers work more or less... I think?"

Today's post's title is from the log message for revision 9. I implemented loads and stores through pointers.

Also did some restructuring and cleaning up of the code and generated code, now that I have a better idea of things thanks to David Hanson's paper on lcc.NET.

I should get rid of those fixed size buffers sometime soon.