Latest News >> 2008-11-13

Well, DHH seems to be caught in a lie in his latest blog post on Rails myths so I feel I should correct it. An outright lie that Mongrel caused his 400 restarts/day problem. However, David must have forgotten that I have a full log of the chat where he admitted it, so let’s get into some nice clean truth for a change.

2008-11-11

I’m quickly coming to the end of my first semester in music school and am considering taking a consulting gig for the two month break we have. Not really sure what’s available these days, as I actually haven’t touched a computer for the entire semester.

2008-10-30

In this world there are these weird little dickheads who think that they have some kind of magical powers manipulating others to do their bidding. They spend their days making people around them dance like marionettes in a sick little play that only they find funny. The sad truth about manipulators is their machinations are only powerful and effective in their own mind.

2008-10-28

UPDATE: Read my follow-up post to this where I explain Matt is alright.

EaRing: It All Started As A Joke

This is a small project I tinkered on in my spare time as a joke for the RubyEnRails 2008 conference. You can read all about the joke in the PDF presentation

It was a riot, but the project actually became fun to just work on in its own right.

It works pretty well considering I just hacked on it part-time for a couple weeks between writing my Mongrel book and working on the presentation.

You’ll find many similarities between EaRing and LLVM, except EaRing has fewer features, is kind of weird, runs on fewer platforms, and is tiny by comparison.

I wouldn’t recommend using it in anything serious right now, but it is fun to check it out and see how it was built.

Grab the tarball from the website if you want to try it. See further down for some instructions.

What Is It?

EaRing is a dynamic assembler, think of it as a scripting language that uses a generic CPU-neutral assembly language as the script. It actually does compile your script on the fly to assembler for your platform, so it run at the speed of your CPU.

The important thing about EaRing is that it builds everything on the fly very fast, and then provides a simple data structure you can use to run the code, disassemble it, examine the results, etc. Because everything that gets generated is held in data structures there’s also some things that EaRing can do other assemblers can’t:

  • You can swap the contents of functions or alter them as if they were data.
  • You can plug in any memory management you need.
  • It can open dynamic libraries and run the functions like they are another module.
  • You can ship the code to other machines and they’ll just run it.
  • It’s still fast because, after the first compile, it runs at CPU speed.

I would consider EaRing a tool for learning assembler and not really something you’d do a full blown language on. That’s what I plan on using it for in the future.

Features

  • Simple API with good examples. Look at earing.c
  • Embeddable into your programs (there are no global variables).
  • Simple syntax using a real LR parser with good error messages.
  • Interactive REPL and you can make it a #! script too. Yeah, that’s weird.
  • Constants defined in the assembler are actually not constant.
  • Ability to load .so libs and other .asm files and treat them the same.
  • You can combine modules as long as the functions don’t clash.
  • Valgrind pure, so it doesn’t leak (except for dlopen and readline’s leaks).
  • Fast data structures for handling names based on a Ternary Search Tree.
  • Written for educational purposes, so the code is easy to read (although not commented yet).
  • Uses GNU lightning so runs on a few processors, not tested though.
  • Actually works, which is kind of amazing.
  • The ability to compile your modules, and then disassemble them to the real x86 bytecodes being used.

Platforms

Since this is an initial release, I only really got it to work on a few platforms, but it should run on others:

  • Linux x86-64 AMD.
  • Mac OSX x86-32 Intel.

License

Right now I don’t have a license on it since I’ve got no idea if anyone will use it. Just consider it free to use for educational purposes, and contact me if you have any ideas about the license.

Installation

Quick instructions for trying out Earing. Currently it works great on Linux x86-64 and probably on other Linux, but shoot me feedback.

You need to have a recent version of Python 2.5 installed:

  1. Grab the tarball from the website
  2. python software/ez_setup.py (only do this if you don’t have easy_install already)
  3. easy_install zapps pygments idiopidae vellum
  4. tar -xjvf earing-VERSION.tar.bz2
  5. cd earing-VERSION
  6. vellum software-64 (on non-64bit do: vellum software-others)
  7. vellum build (OSX do: build-OSX)
  8. build/earing samples/linux-64.asm (build/earing samples/osx-32.asm on OSX)
  9. build/earing -h
  10. build/earing -i samples/linux-64.asm
  11. build/earing -d samples/linux-64.asm

Have fun. The big sample script is in samples/linux-64.asm or samples/osx-32.asm and has tons of simple little functions showing off the features.

If you don’t have Python you can still install it, but you’ll have to figure it out yourself. Look at build.vel and software/build.vel for the automation.

There’s a bug in how double/float types are handled on 32-bit vs. 64-bit. Still have to track it down, but you can’t use float on 64-bit, and can’t use double on 32-bit. I probably have to change the size of the values in tokens. Anyway, look at the osx-32.asm to see how libraries are loaded, and check out its main to see how to do float calls to library functions. Look at linux-64.asm for the inverse example.

There was readline support, but readline behaves differently between Linux and OSX so I removed it until I can learn more about it.

Contributing

I have to work on a book for the next month or so, which means I won’t be doing too much with this project until then. If you’re interested in working on it, here’s what I suggest:

  1. I have the Bazaar repository at http://zedshaw.com/repository/earing
  2. Make a branch and start your hacking: brz branch http://zedshaw.com/repository/earing
  3. As you have interesting patches or bug fixes, email them to me at zedshaw@zedshaw.com or tell me where your branch is online.
  4. I’ll periodically do releases that include other people’s stuff.

If people start contributing then I’ll pick an open source license. Otherwise, enjoy the hack and the joke.