Latest News >> 2008-10-05

Taking a break from more and more guitar practice I decided to weigh in on the current banking “crisis”.

2008-09-29

I read Obie’s most recent post about his intense passion for Loverboy’s quintessential anthem, “Lovin’ Every Minute Of It”. I find the early 1980’s music is inspiring and uplifting and definitely suited to such important things as corporate culture, recruiting, and motivating the troops to do better. Yes, nothing gets a worker working better than a little Loverboy right in their ear.

2008-09-25

Don’t forget folks, the FU NYC show will be in a few hours (7pm-9pm). I’ll be icecasting this one at http://zedshaw.com:8000/fu_nyc and as usual you can use VLC, mplayer or many other players to play the stream.

2008-09-17

I got into music school last week and I’m going to study guitar exclusively for the next year. This is something I’ve always wanted to do, but just never had the chance. Either I wasn’t good enough (being self-taught for so many years) or I just didn’t have the money. After being laid off and getting a small package I decided to practice my ass off on the guitar, do a few live shows to get ready, and then audition for a school in the city.

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.