HJMP: JIT-Compiled HQ9+ Interpreter

You’re a HQ9+ program­mer. You’re sick of slow HQ9+ imple­men­ta­tions writ­ten in unstruc­tured, messy code. You’re tired of running HQ9+ inter­preters inside of those “better” script­ing languages, taunt­ing you with their “features” and “perfor­mance.” You want more.

Intro­duc­ing HJMP (pronounced “HIGH-JUMP”), also known as the Fastest HQ9+ Inter­preter in the World. HJMP is a C++ imple­men­ta­tion of HQ9+ that uses Just In Time (JIT) compi­la­tion to dynam­i­cally compile HQ9+ source into machine code and execute it.

HJMP features a clean object-oriented design that allows the user to easily config­ure HJMP for differ­ent HQ9+ imple­men­ta­tion back­ends and runtime detec­tion of plat­form, allow­ing it to target the machine code for maxi­mum compat­i­bil­ity and perfor­mance. Adding a new target plat­form requires only the knowl­edge of the platform’s call­ing conven­tions, regis­ter clob­ber­ing, and assem­bly instruc­tion set, which almost all HQ9+ program­mers have anyways.

HJMP is cross-plat­form. With JIT compi­la­tion enabled, it works on all *nix AMD64 systems, all Windows AMD64 systems, and all x86 systems that use cdecl as its C/C++ call­ing conven­tion. With JIT compi­la­tion disabled, HJMP is still func­tional as a inter­preter that executes HQ9+ source directly.

Download

Source: http://github.com/GHF/hjmp (down­load archive or git clone http://github.com/GHF/hjmp.git; *nix Make­file and build instruc­tions included)
Windows 64-bit bina­ries (produced by MinGW-w64 GCC 4.5.0): //geekshavefeelings.com/files/hjmp/hjmp_bin_win64.zip
Windows 32-bit bina­ries (produced by TDM MinGW 4.4.1-2): //geekshavefeelings.com/files/hjmp/hjmp_bin_win32.zip

Notes

HJMP is, of course, more or less tongue-in-cheek. It is my exper­i­ment with using an object-oriented approach to dynamic machine code gener­a­tion (JIT compi­la­tion). Its purpose was not so much to run HQ9+ code, but to explore runtime detec­tion and target­ing of code emit­ters, as well as call­ing conven­tions and assem­bly language on differ­ent plat­forms.

At the time of writ­ing (early 2010), 64-bit computer systems have not yet fully satu­rated the soft­ware market, and we are still in a tran­si­tory period between 32-bit and 64-bit. So, HJMP has proved a valu­able exer­cise towards the under­stand­ing of the new ISA and its OS-specific details. After all, I say, if you haven’t writ­ten machine code or worse, a struc­tured machine code gener­a­tor for your plat­form, you don’t fully under­stand your computer.

Links

  • HQ9+ – the orig­i­nal HQ9+ spec­i­fi­ca­tions by Cliff L. Biffle
  • HQ9+ at Esolang – HQ9+ descrip­tion, vari­ants, and other imple­men­ta­tions
  • AsmJit – JIT code gener­a­tor for x86 and x64 assem­bly, used in HJMP
  • More HJMP – my blog post on this project