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 ソースコードの歩き方
Search
Nao Minami
June 21, 2017
Programming
7
910
Ruby ソースコードの歩き方
第4回 meguro.rb LT で Ruby のソースコードの読み方について話しました
https://megurorb.connpass.com/event/59459/
Nao Minami
June 21, 2017
Tweet
Share
More Decks by Nao Minami
See All by Nao Minami
Real World Migration from HTTP to gRPC #CNDT2020
south37
3
5.7k
Real World Migration from HTTP to gRPC in Ruby #grpcconf
south37
2
4.3k
Getting Things Done をベースにした仕事の進め方 / How to Work with Getting Things Done
south37
8
7.7k
Web API に秩序を与える Protocol Buffers / Protocol Buffers for Web API #builderscon
south37
18
16k
puma v4 では SIGTERM での worker process ゾンビ化に気をつけよう / Be aware of zombie processes in puma v4
south37
0
3.7k
理想的なマイクロサービスアーキテクチャを目指す継続的改善 / Re-architecturing of Microservices #CNDT2019
south37
10
14k
gcpc: Google Cloud Pub/Sub Client for Ruby #tqrk13
south37
1
770
実行計画から学ぶ PostgreSQL の内部動作とクエリ最適化 / Learn PostgreSQL from Explain
south37
8
39k
学びを得るための新卒 ISUCON / New Grad ISUCON for Learning
south37
4
42k
Other Decks in Programming
See All in Programming
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
Beyond ORM
77web
3
460
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
Go の GC の不得意な部分を克服したい
taiyow
2
770
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
1
170
MCP with Cloudflare Workers
yusukebe
2
220
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
4
1.1k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
GitHub's CSS Performance
jonrohan
1030
460k
Documentation Writing (for coders)
carmenintech
66
4.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building an army of robots
kneath
302
44k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Adopting Sorbet at Scale
ufuk
73
9.1k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Music & Morning Musume
bryan
46
6.2k
Speed Design
sergeychernyshev
25
670
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Transcript
3VCZιʔείʔυͷา͖ํ /BP.JOBNJ !TPVUI
ࣗݾհ
/BP.JOBNJ!TPVUI !NJOBNJP 4PGUXBSFFOHJOFFS !8BOUFEMZ *OD
3VCZΛιʔείʔυ͔Βཧղ͍ͨ͠ʂ
None
τοϓϨϕϧͰϑΝΠϧɺσΟϨΫτϦ
ʜͲ͔͜ΒಡΜͩΒྑ͍͔͕͔Βͳ͍
Ͱɺߏ֓ཁΛ͍ͬͯΕ ͣͬͱಡΈ͘͢ͳΔͣ
3VCZιʔείʔυͷ֓ཁΛΔ Ͱɺߏ֓ཁΛ͍ͬͯΕ ͣͬͱಡΈ͘͢ͳΔͣ
w 3VCZιʔείʔυͷ֓ཁΛΔ w 3VCZ࣮ߦ࣌ͷڍಈ w ·ͱΊ ࠓ͢༰
w 3VCZιʔείʔυͷ֓ཁΛΔ w 3VCZ࣮ߦ࣌ͷڍಈ w ·ͱΊ ࠓ͢༰
3VCZιʔείʔυͷ֓ཁΛΔ w 3VCZϨϙδτϦ w τοϓϨϕϧͰϑΝΠϧɺσΟϨΫτϦ w NBLFͰϏϧυɺNBLFJOTUBMMͰΠϯετʔϧ w ओཁͳϑΝΠϧ࣮ଟ͘ͳ͍ w
ಛʹɺQBSTFZ DPNQJMFD JOTOTEFG͕ॏཁ
3VCZॲཧܥͷ֓ཁ w QBSTFʜSVCZίʔυ͔Β"45Λੜ w DPNQJMFʜ"45͔Β:"37໋ྩྻΛੜ w SVOUJNFʜ:"37໋ྩΛ࣮ߦ 3VCZଟ͘ͷݴޠॲཧܥͱಉ༷ɺεςοϓ͕ଘࡏ ͦΕͧΕͷεςοϓͲ͜ͰͲ͏࣮͞Ε͍ͯΔͷ͔ʁ
QBSTF w QBSTFʜSVCZίʔυ͔Β"45Λੜ w DPNQJMFʜ"45͔Β:"37໋ྩྻΛੜ w SVOUJNFʜ:"37໋ྩΛ࣮ߦ
QBSTF puts 2 + 2 3VCZίʔυ UPLFOྻ NODE_CALL + NODE_LIT
2 identifier puts integer 2 integer 2 op + NODE_LIT 2 NODE_FCALL puts "45 நߏจ
QBSTF w QBSTFZͰఆٛ w ߦ͋ΔڊେϑΝΠϧ w CJTPOͷ༷ͳQBSTFSHFOFSBUPSʹ৯Θ͢QBSTFD w #/'Ͱهड़ɺBDUJPOͦͷଞͷ෦$Ͱهड़
w UPLFOEFGTLFZXPSETͰఆٛ 3VCZͷจ๏Λ࿔Γ͔ͨͬͨΒQBSTFZΛݟΕྑ͍
DPNQJMF w QBSTFʜSVCZίʔυ͔Β"45Λੜ w DPNQJMFʜ"45͔Β:"37໋ྩྻΛੜ w SVOUJNFʜ:"37໋ྩΛ࣮ߦ
DPNQJMF "45͔ΒDPNQJMFͯ͠:"37໋ྩྻੜ NODE_CALL + NODE_LIT 2 NODE_LIT 2 NODE_FCALL puts
"45 putself putobject 2 putobject 2 opt_plus opt_send_simple <callinfo!mid:puts, argc:2…> :"37໋ྩྻ
DPNQJMF w DPNQJMFDͰఆٛ w ߦ͋ΔڊେϑΝΠϧ w "45Λࠪͯ͠:"37໋ྩ JTFR Λੜ
w ASC@JTFR@DPNQJMF@OPEF SC@JTFR@U JTFR /0%& OPEF A͕ݺΕΔ "45͕มΘͬͨΒɺDPNQJMFDमਖ਼
SVOUJNF w QBSTFʜSVCZίʔυ͔Β"45Λੜ w DPNQJMFʜ"45͔Β:"37໋ྩྻΛੜ w SVOUJNFʜ:"37໋ྩΛ࣮ߦ
putself putobject 2 putobject 2 opt_plus opt_send_simple <callinfo!mid:puts, argc:2…> :"37໋ྩྻΛॱ൪ʹ࣮ߦ
SVOUJNF 4UBDL1PJOUFS 41 :"37ͷ෦ελοΫ 1SPHSBN$PVOUFS 1$
SVOUJNF:"37໋ྩͷఆٛ :"37໋ྩͷఆٛͲ͜ʁ
SVOUJNF:"37໋ྩͷఆٛ w JOTOTEFGͰ:"37໋ྩΛఆٛ w QVUTFMG QVUPCKFDU TFOE FUDͷఆٛΛهࡌ w !@LPʹΑΔ%4-
w ΄΅$͕ͩɺڞ௨෦ল͍ͯΔ w UPPMJOTOTWNSCͱ͍͏SVCZεΫϦϓτͰ JOTOTEFG͔ΒίʔυੜΛߦ͏WNJOD :"37໋ྩΛग़ൃʹಡΉ߹JOTOTEFGΛݟΔͱྑ͍
ͦͷଞͷϑΝΠϧ QBSTFZ DPNQJMFD JOTOTEFGҎ֎ͷ ϑΝΠϧԿʹΘΕΔʁ
ͦͷଞͷϑΝΠϧ w QBSTFZ DPNQJMFD JOTOTEFG͔Βݺͼग़͞ΕΔॲཧ w QBSTF DPNQJMFͷݺͼग़͠ɺWNͷॲཧ w ϏϧτΠϯͷΫϥε
0CKFDU "SSBZ 4USJOH FUDʜ w υΩϡϝϯτ େମҎԼͷͭͷͲΕ͔
ಡΈํ͕͔Ε ɹ3VCZͷιʔείʔυා͘ͳ͍ʂ
w 3VCZιʔείʔυͷߏΛΔ w 3VCZ࣮ߦ࣌ͷڍಈ w ·ͱΊ ࠓ͢༰
$ ruby -e ‘print “Hello World!”’ Hellow World! 3VCZΛUFSNJOBM͔Β࣮ߦ 3VCZΛUFSNJOBM͔Β࣮ߦ
int main(int argc, char **argv) { . . . {
. . . return ruby_run_node(ruby_options(argc, argv)); } } w 3VCZ࣮ߦ࣌ANBJOA͕ؔΤϯτϦʔϙΠϯτ w ASVCZ@PQUJPOTAͰQBSTF DPNQJMF w ASVCZ@SVO@OPEFA͕:"37໋ྩྻΛ࣮ߦ 3VCZͷNBJOؔ
SVCZ@PQUJPOT void * ruby_options(int argc, char **argv) { . .
. if ((state = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); } else { . . iseq = (void *)INT2FIX(state); } . . . return iseq; } w JTFR :"37໋ྩྻ Λฦ͢ w ॲཧΛ͏ͱɺQBSTFZͰఆٛ͞ΕͨAZZQBSTFA DPNQJMFDͰఆٛ͞ΕͨASC@JTFR@DPNQJMF@OPEFAΛར༻
SVCZ@PQUJPOT void * ruby_options(int argc, char **argv) { . .
. if ((state = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); } else { . . iseq = (void *)INT2FIX(state); } . . . return iseq; } w JTFR :"37໋ྩྻ Λฦ͢ w ॲཧΛ͏ͱɺQBSTFZͰఆٛ͞ΕͨAZZQBSTFA DPNQJMFDͰఆٛ͞ΕͨASC@JTFR@OFX@NBJOAΛར༻ QBSTFZ DPNQJMFD ʹḷΓண͍ͨʂ
SVCZ@SVO@OPEF w JTFR :"37໋ྩྻ Λ࣮ߦ͢Δ w ॲཧΛ͏ͱɺAWN@FYFD@DPSFA͕࣮ߦ͞ΕΔ w JOTOTEFG͔Βੜͨ͠Dίʔυ͕ຒΊࠐ·ΕͯΔ static
VALUE vm_exec_core(rb_thread_t *th, VALUE initial) { . . . first: INSN_DISPATCH(); /*****************/ #include "vm.inc" /*****************/ END_INSNS_DISPATCH(); . . . }
SVCZ@SVO@OPEF w JTFR :"37໋ྩྻ Λ࣮ߦ͢Δ w ॲཧΛ͏ͱɺJOTOTEFG͔Βੜͨ͠Dίʔυ͕ ຒΊࠐ·ΕͨAWN@FYFD@DPSFA͕࣮ߦ͞ΕΔ static VALUE
vm_exec_core(rb_thread_t *th, VALUE initial) { . . . first: INSN_DISPATCH(); /*****************/ #include "vm.inc" /*****************/ END_INSNS_DISPATCH(); . . . } JOTOTEFGʹḷΓண͍ͨʂ
͔֬ʹɺQBSTFZ DPNQJMFD JOTOTEFG Λԡ͑͞Ε3VCZΛཧղͰ͖ͦ͏
w 3VCZιʔείʔυͷߏΛΔ w 3VCZ࣮ߦ࣌ͷڍಈ w ·ͱΊ ࠓ͢༰
·ͱΊ w 3VCZͷιʔείʔυා͘ͳ͍ w QBSTF DPNQJMF SVOUJNFͷͦΕͧΕͷεςοϓͷ ओཁͳϑΝΠϧΛೖΓޱʹ͢ΔͱಡΈ͍͢ w NBJO͔ؔΒಡΈ࢝ΊΔͷָ͍͠
3VCZΛιʔείʔυ͔Βཧղͯ͠ɺ ָ͍͠3VCZϥΠϑΛૹΖ͏ʂ