
More compilers from last quarter's class
Technical, School ·Saturday January 9, 2010 @ 18:53 EST (link)
I thought I'd mention and link to Mark McWiggins' "higher level software" page here; he took the CSEP 501 compilers class at the same time I did, and wrote his compiler in Python, which I thought was interesting and probably saved him some time and effort over my C++ offering (which he linked to, and also has a link to a Java offering with perhaps more to come).
Mark's (Python source) archive appears to have all of the hand-written code in two Python files, parser.py and opt.py (there are other files but they appear to be small either external modules, e.g. for multimethod support, or generated code) with very little whitespace or comments—i.e., almost as if it was written to minimize line count. His final report indicates he was not able to compile all the "standard" sample MiniJava programs, one reason being that he couldn't compile calls with more than three parameters (as he said, easily surmountable; presumably time was a factor). His optimizations consist of a few peephole optimizations and the level of abstraction is far less than my compiler's pipeline (see my writeup and final report).
So a straight line count comparison (1800 for his Python code, 8000 for my C++) would certainly not seem to be in order. It's easily possible that the commenting, whitespace, separation of classes into files and code into classes (I had I think around 20 files and possibly 80 classes), plus the increased correctness and number and type of optimizations would easily account for the difference. Use of the STL, while not as convenient as a higher-level language, would probably be comparable to using the built-in dictionaries, etc. in Python. So this project alone is a poor example of "demonstrating the usefulness of [higher level] languages" (but I'd still agree with the claim that HLLs are more efficient; experience and other writing—Frederick Brooks, Paul Graham, to name a few—is persuasive in that regard).
A standard optimizing C++ compiler should have my compiler running faster than most HLLs (algorithms being equal, and we both used well-tuned libraries), and increased optimization should generate smaller and faster programs (a direct comparison is not possible since Mark opted to output MIPS code for the SPIM emulator but I stayed with the default x86 output, although it may be instructive to compare percent lines of code reduction via optimizations for programs that will compile on both). In a high-volume compiler, object code optimizations would win out over compiler speed fairly quickly. (The "standard" as much as there was one, for writing the compiler, was, not unexpectedly, Java, so we both strayed from the beaten path in language choice, getting permission of the instructor to deviate.) It would also be interesting to see if development/test time (all other things being equal) were influenced by language choice (I would believe that HLLs do better, but it would be hard to demonstrate from this sample due to differences in completion, optimizing, and breadth and extent of tests).
Books finished: Twilight, New Moon.DVDs finished: ER: The Complete 10th Season, 12 Monkeys.