Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby YARV Challenge: Build Your Own Bytecode V...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for yuhi yuhi
April 22, 2026
28

Ruby YARV Challenge: Build Your Own Bytecode VM in 7 Steps

RubyKaigi 2026 Lightning Talks

Avatar for yuhi

yuhi

April 22, 2026

Transcript

  1. Ruby YARV Challenge: Build Your Own Bytecode VM in 7

    Steps yuhi(@yuhi_junior) RubyKaigi 2026 Lightning Talks 2026-04-22 #rubykaigiA
  2. • A browser-based workshop • Build simplified YARV bytecode and

    compiler in Ruby • Tutorials + hints at every step What’s “Ruby YARV Challenge”?
  3. Motivation • The problem ◦ Stack machines and bytecode are

    unfamiliar concepts. ◦ YARV is written in C — hard to read for many Rubyists. • The solution ◦ Tutorials + hints guide you from zero — no prior VM knowledge needed. ◦ Reimplement YARV-like bytecode and compiler in Ruby — no C required
  4. Where you implement the code Prism Ruby API bytecode (ISeq)

    AST Ruby code VM Exec parser compiler
  5. 7 steps to reach the goal 1. Literal values (putobject)

    2. Addition (opt_plus) 3. Subtraction (opt_minus) 4. Local variables (getlocal, setlocal, dup) 5. Comparison (opt_lt) 6. Control flow (branchunless, jump) 7. Method definition and dispatch (definemethod, opt_send_without_block)
  6. 7 steps to reach the goal 1. Literal values (putobject)

    2. Addition (opt_plus) 3. Subtraction (opt_minus) 4. Local variables (getlocal, setlocal, dup) 5. Comparison (opt_lt) 6. Control flow (branchunless, jump) 7. Method definition and dispatch (definemethod, opt_send_without_block)
  7. Step 2: Addition • bytecode ◦ opt_plus • compile ◦

    IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
  8. Compiler CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2]

    receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
  9. Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode

    arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
  10. Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode

    arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
  11. Step 2: Addition • bytecode ◦ opt_plus • compile ◦

    IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
  12. Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode

    arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
  13. Step 2: Addition • bytecode ◦ opt_plus • compile ◦

    IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
  14. Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode

    arguments: [2] receiver arguments • compile_integer_node (Step 1) • compile_arguments_node • compile_binary_plus putobject 1 putobject 2 opt_plus
  15. Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode

    arguments: [2] receiver arguments • compile_integer_node (Step 1) • compile_arguments_node • compile_binary_plus
  16. Step 2: Addition • compile_integer_node (Step 1) • compile_arguments_node •

    compile_binary_plus CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2] receiver arguments
  17. Step 2: Addition • compile_integer_node (Step 1) • compile_arguments_node •

    compile_binary_plus CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2] receiver arguments