KoiVM

KoiVM is an extremely simple prototype Virtual Machine written in Ruby. It was created with learning in mind and is written so that it is easy to understand and play with.

Examples

The standard ‘Hello world!’, KoiVM style:

require 'koi'
include KoiVM

VM.new.run [
  PUSH_STRING, "Hello World!\n",
  PRINT
]

#=> Hello world!

And an old-school ‘Blast off’ example:

require 'koi'
include KoiVM

VM.new.run [
  PUSH_INT, 11,
  PUSH_INT, 1,
  SUBTRACT,
  DUP,
  TO_STRING,
  PRINT,
  PUSH_STRING, ", ",
  PRINT,
  DUP,
  PUSH_INT, 0,
  EQUAL,
  JUMP_UNLESS, -13,
  PUSH_STRING, "Blast Off!\n",
  PRINT
]

#=> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, Blast off!

Author & Credits

Author

Aaron Gough

Copyright © 2010 Aaron Gough (thingsaaronmade.com), released under the MIT license