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
7
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
760
実行計画から学ぶ PostgreSQL の内部動作とクエリ最適化 / Learn PostgreSQL from Explain
south37
8
39k
学びを得るための新卒 ISUCON / New Grad ISUCON for Learning
south37
4
41k
Other Decks in Programming
See All in Programming
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
cmp.Or に感動した
otakakot
3
200
Amazon Qを使ってIaCを触ろう!
maruto
0
410
subpath importsで始めるモック生活
10tera
0
320
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
240
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
RailsConf 2023
tenderlove
29
900
Code Reviewing Like a Champion
maltzj
520
39k
Thoughts on Productivity
jonyablonski
67
4.3k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
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ϥΠϑΛૹΖ͏ʂ