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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
610
"雑" / Almost Microservices
ujihisa
4
6.1k
Modes / VimConf 2018
ujihisa
4
4.4k
.vimconf.swp 2018
ujihisa
0
710
:|┃ / tokyu rubykaigi 12
ujihisa
0
210
Vim / vim-railsdm-2018-07
ujihisa
1
820
Other Decks in Programming
See All in Programming
AIが無かった頃の素敵な出会いの話
codmoninc
1
390
テーブルをDELETEした
yuzneri
0
140
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
140
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
480
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
160
メールのエイリアス機能を履き違えない
isshinfunada
0
230
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
180
5分で問診!Composer セキュリティ健康診断
codmoninc
0
910
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
150
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
WENDY [Excerpt]
tessaabrams
11
39k
A Modern Web Designer's Workflow
chriscoyier
698
190k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.7k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
440
Become a Pro
speakerdeck
PRO
31
6.2k
Are puppies a ranking factor?
jonoalderson
1
3.8k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
250
Writing Fast Ruby
sferik
630
63k
Docker and Python
trallard
47
4.1k
Mind Mapping
helmedeiros
PRO
1
300
YesSQL, Process and Tooling at Scale
rocio
174
15k
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でぽちぽちしたり再起動したりいろいろつらい想いをする ▪ リカバリモードで起動とか ▪ だいたい失敗するので何度も再挑戦する ▪ つらい、不毛、非生産的な作業の連続