Recently being considered to write a Ruby runtime bytecode generation expansion. JIT is more than the cow Oh.



Principle: At call _asm call inside C

BYTE buf[1024];
DWORD by = (DWORD)buf;
...
_asm call by



Ideas: First, put the translation into binary string, and then to a binary function, this function generally took the view that

VALUE run_bytecode(VALUE self, VALUE code) {
  DWORD buf = (DWORD)(StringValueCstr(code));
  _asm call buf
  return Qnil;
}



Reference to be read:

Here should be able to find many useful things.

http://webster.cs.ucr.edu/AsmTools/RollYourOwn/index.html



This guy has written 20 blog, complete with Ruby implementation of the compilation of DSL, the rest is the command -> byte-code and address of the operator.

http://www.hokstad.com/compiler