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
300
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.2k
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
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
120
初めての模倣学習とVLA
natsutan
0
320
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
420
業務時間外もAIに働いてもらう話
colorful12
2
8.7k
バグを直したら useEffect が消えた
colorful12
3
770
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
110
まだ間に合う!今年の夏こそSchemeのマクロ展開器を完全理解!
omasanori
0
570
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
780
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
580
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.3k
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.3k
Hono + Inertia + React で LP を構築した話
oukayuka
2
180
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
210
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
300
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
670
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
830
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
670
The untapped power of vector embeddings
frankvandijk
2
1.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
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でぽちぽちしたり再起動したりいろいろつらい想いをする ▪ リカバリモードで起動とか ▪ だいたい失敗するので何度も再挑戦する ▪ つらい、不毛、非生産的な作業の連続