Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby YARV Challenge: Build Your Own Bytecode V...
Search
yuhi
April 22, 2026
420
1
Share
Ruby YARV Challenge: Build Your Own Bytecode VM in 7 Steps
RubyKaigi 2026 Lightning Talks
yuhi
April 22, 2026
More Decks by yuhi
See All by yuhi
APIリファレンスを 読み込むと楽しい
yuhisatoxxx
0
540
社内の3名登壇へ貢献した話 〜若手よ生意気になれ〜
yuhisatoxxx
0
710
階層構造を表現するデータ構造とリファクタリング 〜1年で10倍成長したプロダクトの変化と課題〜
yuhisatoxxx
3
1.8k
Wakate.rb #1
yuhisatoxxx
0
37
ひとりぼっちの新卒エンジニアが社外の同期50人と繋った話
yuhisatoxxx
0
310
24th Dev オープニング
yuhisatoxxx
0
270
コミュニティビジョン ~繋がりとキャリア~
yuhisatoxxx
0
310
遅延評価勉強法で良質な学びを
yuhisatoxxx
3
1.3k
Featured
See All Featured
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
140
How to build a perfect <img>
jonoalderson
1
5.5k
Exploring anti-patterns in Rails
aemeredith
3
350
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
ラッコキーワード サービス紹介資料
rakko
1
3.3M
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
800
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
sira's awesome portfolio website redesign presentation
elsirapls
0
240
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
WCS-LA-2024
lcolladotor
0
590
Transcript
Ruby YARV Challenge: Build Your Own Bytecode VM in 7
Steps yuhi(@yuhi_junior) RubyKaigi 2026 Lightning Talks 2026-04-22 #rubykaigiA
2 SmartBank, Inc. Software Engineer yuhi @yuhi_junior @Yuhi-Sato Self Introduction
Get Your Board43! @ HackSpace
• A browser-based workshop • Build simplified YARV bytecode and
compiler in Ruby • Tutorials + hints at every step What’s “Ruby YARV Challenge”?
None
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
Where you implement the code bytecode (ISeq) AST Ruby code
VM Exec parser compiler
Where you implement the code Prism Ruby API bytecode (ISeq)
AST Ruby code VM Exec parser compiler
Where you implement the code yruby bytecode (ISeq) AST Ruby
code VM Exec parser compiler
Where you implement the code Workshop code bytecode (ISeq) AST
Ruby code VM Exec parser compiler
Goal Define and execute recursive Fibonacci on VM
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 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)
Step 2: Addition • bytecode ◦ opt_plus • compile ◦
IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
opt_plus opt_plus 1. pop two values 2. push the sum
1 2
opt_plus opt_plus 1. pop two values 2. push the sum
1 2
opt_plus opt_plus 1. pop two values 2. push the sum
1 2
opt_plus opt_plus 1. pop two values 2. push the sum
3
Compiler CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2]
receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
Demo: Step 2 URL: https://yuhi-sato.github.io/ruby-yarv-challenge
Let’s try! URL: https://yuhi-sato.github.io/ruby-yarv-challenge
None
Workshop UI
Workshop UI: Tutorial left pane
Workshop UI: Code center pane
Workshop UI: Results right pane
Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode
arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode
arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
Step 2: Addition • bytecode ◦ opt_plus • compile ◦
IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode
arguments: [2] receiver arguments putobject 1 putobject 2 opt_plus AST bytecode
Step 2: Addition • bytecode ◦ opt_plus • compile ◦
IntegerNode (Step 1) ◦ ArgumentsNode ◦ CallNode name: +
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
Step 2: Addition CallNode name: + IntegerNode value: 1 ArgumentsNode
arguments: [2] receiver arguments • compile_integer_node (Step 1) • compile_arguments_node • compile_binary_plus
Step 2: Addition • compile_integer_node (Step 1) • compile_arguments_node •
compile_binary_plus CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2] receiver arguments
Step 2: Addition • compile_integer_node (Step 1) • compile_arguments_node •
compile_binary_plus CallNode name: + IntegerNode value: 1 ArgumentsNode arguments: [2] receiver arguments
Inspirations