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
See all the way through ruby -e 'p 1'
Search
ujihisa
September 27, 2018
Programming
290
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
See all the way through ruby -e 'p 1'
at meguro.rb #19
https://megurorb.connpass.com/event/100401/
ujihisa
September 27, 2018
More Decks by ujihisa
See All by ujihisa
13 Vim plugins I use every day
ujihisa
0
600
"雑" / Almost Microservices
ujihisa
4
6.1k
Modes / VimConf 2018
ujihisa
4
4.4k
.vimconf.swp 2018
ujihisa
0
700
:|┃ / tokyu rubykaigi 12
ujihisa
0
210
Vim / vim-railsdm-2018-07
ujihisa
1
810
Other Decks in Programming
See All in Programming
The NotImplementedError Problem in Ruby
koic
1
850
Inside Stream API
skrb
1
740
New "Type" system on PicoRuby
pocke
1
980
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
560
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.3k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
270
AI 輔助遺留系統現代化的經驗分享
jame2408
1
810
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
110
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.4k
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Designing Experiences People Love
moore
143
24k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
730
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
430
Design in an AI World
tapps
1
250
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
600
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Transcript
ruby -e 'p 1'を ぜんぶ見る meguro.rb 2018-09-27 ujihisa
はじめてのCRubyのソースコードの読み方 • 興味あるXの実装から ◦ メソッド ◦ parser ◦ GC •
mainから実行順 ◦ 静的 ◦ 動的 • ソースコードのファイル名アルファベット順に全部
はじめてのCRubyのソースコードの読み方 • 興味あるXの実装から ◦ メソッド ←僕は長らくこれで読んでた ◦ parser ←めっちゃ楽しい (そしてつらい) ◦
GC ←挫折 (nariさんの本読んで完全に理解 ) • mainから実行順 ◦ 静的 ←事例けっこうあるぽい? ◦ 動的 ←本発表 • ソースコードのファイル名アルファベット順に全部
-e command Specifies script from command-line while telling Ruby not
to search the rest of the arguments for a script file name.
Demo with GDB Linux • RUBY_CFLAGS="-ggdb3" RUBY_OPTFLAGS='-O0' rbenv install -k
2.6.0-dev • gdb `rbenv which ruby` -q --tui • :execute 'Termdebug' trim(system('rbenv which ruby')) • start -e 'p 123' • call rb_p(ばりゅー) • おまけ ◦ mrkn/vim-cruby ◦ ctags -R Mac • 後述
(gvimとtermdebug.vimによるデモ)
用語集 • iseq ◦ instruction sequence ◦ (みんなが日常的に会話に出すやつ) • ec
◦ current execution context (vm_eval.c) • cfp ◦ Control Frame Pointer (doc/yarvarch.ja) ◦ pcとspとselfを持つ • pc ◦ Program Counter (doc/yarvarch.ja) • sp ◦ Stack Pointer • ep ◦ Environment Pointer
VALUE逆引き表 include/ruby/ruby.h enum ruby_value_type { RUBY_T_NONE = 0x00, RUBY_T_OBJECT =
0x01, RUBY_T_CLASS = 0x02, RUBY_T_MODULE = 0x03, RUBY_T_FLOAT = 0x04, RUBY_T_STRING = 0x05, RUBY_T_REGEXP = 0x06, RUBY_T_ARRAY = 0x07, RUBY_T_HASH = 0x08, RUBY_T_STRUCT = 0x09, RUBY_T_BIGNUM = 0x0a, RUBY_T_FILE = 0x0b, RUBY_T_DATA = 0x0c, RUBY_T_MATCH = 0x0d, RUBY_T_COMPLEX = 0x0e, RUBY_T_RATIONAL = 0x0f, RUBY_T_NIL = 0x11, RUBY_T_TRUE = 0x12, RUBY_T_FALSE = 0x13, RUBY_T_SYMBOL = 0x14, RUBY_T_FIXNUM = 0x15, RUBY_T_UNDEF = 0x16, RUBY_T_IMEMO = 0x1a, /*!< @see imemo_type */ RUBY_T_NODE = 0x1b, RUBY_T_ICLASS = 0x1c, RUBY_T_ZOMBIE = 0x1d,
今回説明を省いた点 • insns.def ◦ insns.def - YARV instruction definitions ◦
YARV命令の実装 (putselfとかそういうやつ) ◦ CだけどCに見えないと噂 • vm.inc ◦ コンパイル時にinsns.defからRubyで生成される
ujihisa • @ujm • Quipper社 2018-09-01から ◦ Rails • Fablic社
2017-01-01から ◦ Rails • Hootsuite社 2010から ◦ 非Ruby • 今月オススメの魚 ◦ 秋刀魚 • 最近の活動 ◦ VimConf 2018 の主催 ◦ https://vimconf.org/2018
おまけ: macOS High Sierraでgdbを使う方法 おすすめ • Gentoo Linuxなど、便利なLinux distributionを入れ、そこで行う 遅いけど結構おすすめ
• VirtualboxとかDockerとかそれ系でなんかのLinuxを使えるようにし、それで行う 一応あり • 古いMac OSXで上書きインストール
おまけ: macOS High Sierraでgdbを使う方法 絶対におすすめしない最悪の方法 • macOS High Sierraでgdbを使う •
17ステップぐらいある ◦ gdbのダウングレード、バージョン固定 ◦ https://gist.github.com/danisfermi/17d6c0078a2fd4c6ee818c954d2de13c ▪ GUIでぽちぽちしたり再起動したりいろいろつらい想いをする ▪ リカバリモードで起動とか ▪ だいたい失敗するので何度も再挑戦する ▪ つらい、不毛、非生産的な作業の連続