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
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
850
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
Jakarta EE meets AI
ivargrimstad
0
260
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
270
情報漏洩させないための設計
kubotak
3
340
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
1
150
MCP with Cloudflare Workers
yusukebe
2
220
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
Zoneless Testing
rainerhahnekamp
0
120
Featured
See All Featured
The Language of Interfaces
destraynor
154
24k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Six Lessons from altMBA
skipperchong
27
3.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
How STYLIGHT went responsive
nonsquared
95
5.2k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Code Review Best Practice
trishagee
65
17k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
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ϥΠϑΛૹΖ͏ʂ