HJMP: JIT-Compiled HQ9+ Interpreter

You’re a HQ9+ pro­gram­mer. You’re sick of slow HQ9+ imple­men­ta­tions writ­ten in unstruc­tured, messy code. You’re tired of run­ning HQ9+ inter­preters inside of those “bet­ter” script­ing lan­guages, taunt­ing you with their “fea­tures” and “per­for­mance.” You want more.

Intro­duc­ing HJMP (pro­nounced “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) com­pi­la­tion to dynam­i­cal­ly com­pile HQ9+ source into machine code and exe­cute it.

HJMP fea­tures a clean object-ori­ent­ed design that allows the user to eas­i­ly con­fig­ure HJMP for dif­fer­ent HQ9+ imple­men­ta­tion back­ends and run­time detec­tion of plat­form, allow­ing it to tar­get the machine code for max­i­mum com­pat­i­bil­i­ty and per­for­mance. Adding a new tar­get plat­form requires only the knowl­edge of the platform’s call­ing con­ven­tions, reg­is­ter clob­ber­ing, and assem­bly instruc­tion set, which almost all HQ9+ pro­gram­mers have any­ways.

HJMP is cross-plat­form. With JIT com­pi­la­tion enabled, it works on all *nix AMD64 sys­tems, all Win­dows AMD64 sys­tems, and all x86 sys­tems that use cde­cl as its C/C++ call­ing con­ven­tion. With JIT com­pi­la­tion dis­abled, HJMP is still func­tion­al as a inter­preter that exe­cutes HQ9+ source direct­ly.

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 includ­ed)
Win­dows 64-bit bina­ries (pro­duced by MinGW-w64 GCC 4.5.0): //geekshavefeelings.com/files/hjmp/hjmp_bin_win64.zip
Win­dows 32-bit bina­ries (pro­duced 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-ori­ent­ed approach to dynam­ic machine code gen­er­a­tion (JIT com­pi­la­tion). Its pur­pose was not so much to run HQ9+ code, but to explore run­time detec­tion and tar­get­ing of code emit­ters, as well as call­ing con­ven­tions and assem­bly lan­guage on dif­fer­ent plat­forms.

At the time of writ­ing (ear­ly 2010), 64-bit com­put­er sys­tems have not yet ful­ly sat­u­rat­ed the soft­ware mar­ket, and we are still in a tran­si­to­ry peri­od 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-speci­fic details. After all, I say, if you haven’t writ­ten machine code or worse, a struc­tured machine code gen­er­a­tor for your plat­form, you don’t ful­ly under­stand your com­put­er.

Links

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