Showing posts with label compiler. Show all posts
Showing posts with label compiler. Show all posts

Wednesday, January 20, 2010

A preview of Mach-O file generation

This month I got back into an x86 compiler I started last May. It lives on github.

The code is a bit of a mess but it mostly works. It generates Mach object files that are linked with gcc to produce executable binaries.

The Big Refactoring of January 2010 has come to an end and the tests pass again, even if printing is broken it prints something, and more importantly compiles test/test_huge.code into something that works.

After print is fixed I can clean up the code before implementing anything new. I wasn't sure if I'd get back into this or not and am pretty excited about it. I'm learning a lot from this project.

If you are following the Mach-O posts you might want to look at asm/machofile.rb, a library for creating Mach-O files. Using it is quite straightforward, an example is in asm/binary.rb, in the #output method.

Definitely time for bed now!

Wednesday, September 23, 2009

Yet another compiler posted to github, and first post

Tonight I pushed a pet compiler project I have been working on to github. It's my first code on github and I hadn't really intended on making it public. I'll be quite surprised if anyone is interested in it at the moment, the README doesn't even explain where to start.  Oh well, I will fix it up for public consumption later.  Release early and often.

Every programmer thinks he knows what his perfect language looks like, I am no different. Right now it's little more than turing complete, but it parses a small language and outputs x86 machine code. Only Mach-O binaries on OS X work at the moment but ELF support on Linux is imminent. The assembler is homegrown and done in Ruby but only assembles the subset of x86 needed to compile ... whatever I might call this language in the future.

I'm not sure what the end result will be at all but traits I think a modern language should include are:
  • Immutable data structures
  • Literal notation for hashes, arrays, closures, etc.
  • Multiple block support (possibly io style)
  • Optional OO
  • AOT and JIT compilation to machine code
  • Platform independent, widely ported
  • FFI
  • GC (need I mention this anymore?)
That's it off the top of my head.  Factor, Clojure, Ruby, JavaScript, and C# are languages worth stealing from.  These may overlap but also io, SmallTalk, Python, Java, C, Lisp, Scheme.  I hope to write up some on exactly what I like from each of these languages in the future.  Till then.