Wednesday, January 12, 2011

Revision 100

On December 16th, I checked the code into a new SVN repository. I had previously used CVS, but even for me some things are too old-fashioned.

And today, I committed revision 100. Some revisions are only 1 or 2 line bug fixes, others are dozens of added lines.

Major achievements since I last posted are:
  • exporting of meta data in the form of java annotations (for the Prelude with its many classes, types and instances some 8000 lines of annotations are written, which causes the compiler to spend  1 or 2 CPU seconds in the pretty printer alone)
  • import of the java compiled meta data from class files. This takes only a few milliseconds.
  • Type checker infers and validates class constraints more or less correct.
The day is not so far anymore when the first real java code line will be written! Up to now, it's only annotations followed by an empty placeholder class.

Incidentally, with revision 100 the compiler can parse and type check its own grammar, which is currently 35798 lines or  225832 tokens. This takes 90 seconds, which is quite long compared to 80 seconds with the old compiler especially when one takes into account that we have no strictness checking and code generation yet.

Apparently, the unoptimized monadic style has its costs. No wonder, as it is essentially a series of tail calls, which are currently implemented with two runtime functions tcLoop and tcGoto that throw and catch TailCallExceptions. It looks like the JIT can't do a very good job in the presence of exceptions.
Hopefully, the new code and runtime will be better suited for tail call intensive code.

Sunday, January 2, 2011

Milestone: Type Checking Works

I implemented type checking over the past days and today I was able to type check the frege/ successfully. These are about 2600 lines of Frege code with the most basic definitions - basic types, list operations, common classes and instances for various types - hence almost all language features are used here.

At the moment, the type checker ignores class constraints. The constraint handling will be very different from version 2, so I will perhaps need lots of tracing while implementing it. I want to avoid doing the tests on the Prelude itself  because the tons of trace output I would get then are not easily manageable.

Therefore, I must be able to compile small test programs that import the Prelude. To import something, I must first generate the meta data (which are custom Java annotations) and compile them to a class file.

Thus, the next milestone will be the GenMeta pass. This will be new territory also. In version 2 I exploited the fact that the javac of Java 5 had a bug that made it let pass recursive annotations, although they are forbidden.
It comes down basically to replacing all recursive fields in patterns, expressions and types with indices into appropriate arrays that hold the atomic elements.