BAM Weblog

Ringneck - PASM to JS

Brian McKenna2011-08-07

Parrot is designed to be a general purpose virtual machine for dynamic languages. It started as the virtual machine for Perl 6 but many languages are able to target it. I really love that it's high level enough to have awesome interoperability - for example, you should be able to write a class in Python but subclass it in Ruby.

December of last year I started work on a Parrot Assembly Language (PASM) to JavaScript compiler called Ringneck. Last week I found it again and now I'm releasing it. The idea was that if many languages compile to PASM, I could get many languages to compile to the web just by compiling PASM to JavaScript.

Ringneck takes PASM like this:

  set     I1, 1
  if      I1, TRUE
  print   "False!\n"

  branch  END
  print   "True!\n"

And compiles to something like this:

var label;
while(true) {
switch(label) {
    opcodes.core.set.apply(null, [{"type":1,"text":"I1","reg":"I","index":1},{"type":2,"text":"1","value":1}]);
    if(regs["I"][1].value != 0) {label = "TRUE"; break;}, [{"type":4,"text":"\"False!\\n\"","value":"False!\n"}]);
    label = "END"; break;
case "TRUE":, [{"type":4,"text":"\"True!\\n\"","value":"True!\n"}]);
case "END":
    flush(); return;

I've put a demo up. Feel free to clone the Bitbucket repo.

Please enable JavaScript to view the comments powered by Disqus.