Ruby YARV bytecode

AST:

[ruby]
require ‘ripper’
require ‘pp’

code = <<SRC
a = 1
SRC

pp Ripper.sexp(code)
[/ruby]

[:program,
[[:assign, [:var_field, [:@ident, "a", [1, 0]]], [:@int, "1", [1, 4]]]]]

Bytecode:

[ruby]
code = <<SRC
a = 1
SRC
is = RubyVM::InstructionSequence.compile(code)
puts is.disasm
[/ruby]

== disasm: <RubyVM::InstructionSequence:@>==========
local table (size: 2, argc: 0 [opts: 0, rest: -1, post: 0, block: -1] s1)
[ 2] a          
0000 trace            1                                               (   1)
0002 putobject        1
0004 dup              
0005 setlocal         a
0007 leave

YARV VM instruction set
Parser in JS
Rubinius VM instruction set and documentation and description

Long version

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s