Monday, February 23, 2015

I've been working on my Compiler

I've been working on my compiler, a little bit, in the half year since I've written here. This isn't going to be a complete summary of everything that's been going on, but a few notes, as much for myself as anyone. I'll get chattier in later posts.

There are a few goals of my language project. These aren't in any priority order, just in me jotting down ideas as they come to me:
  • lightweight language, with a feel like C, with only a little bit of C++'s object-oriented features, without C++'s bulk.
  • targeting platforms ranging from desktops (Linux, Mac, Windows) to mobile (Android, iOS) to the web (HTML5 / JS) to maybe crazy unreasonable stuff like the Apple ][
  • primarily for writing games (interactive, graphical), but maybe command-line stuff is OK (server support?)
  • should be fun to program in
  • should be performant, but this isn't the highest priority. If I can achieve performance through tools, rather than by burdening the developer with decisions, that's nice.
I'm currently using a few tools so that I'm not building everything from scratch:
As I go, I've been building test apps that exercise specific parts of the language and compiler. Many of these are command-line Linux binaries, because that's what makes sense for early work. One larger test is a Pong game. Still not a huge app, but pulling in several pieces that a real game will have to deal with.

WIP, hopefully still around by the time you read this: http://bigdicegames.com/BDGRT/Pong/pong.html

One nice thing about the Pong test is that it's showing me what features I can live without, and what features are painful in their absence. I only had integer variables, and they were all global. This worked, but it was gross, so now I've been adding local variables and float support to the language.

As of this morning, I've got a little sample program that does a Fahrenheit to Celsius conversion using locally allocated float variables. There's a few pieces that I expect from local variables:
  • declared in the function where they're used
  • or, declared in a block (a chunk of code delimited by curly braces, contrasted with a basic block, which is something a little different inside the guts of the compiler)
  • has a well-defined lifetime (it goes away when the allocating block is exited)
  • initialized to something well-defined, by default
  • can be initialized as part of declaration (float x=8.0; #remember, Mallory, x=8)
  • scopes can nest, so a more-specific scope will have priority over a less-specific scope.
So far, I've got the first one of those working. Allocating space on the stack, via LLVM's alloca instruction. Works great.

Also working is reading and writing local variables. I didn't list those, above. Not really variables if you can't assign to and read from them.

The rest of that remains to be done, and I'll post here as I get it working.

No comments:

Post a Comment