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.6k
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
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
910
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Click-free releases & the making of a CLI app
oheyadam
2
110
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
Better Code Design in PHP
afilina
PRO
0
120
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Documentation Writing (for coders)
carmenintech
65
4.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
What's new in Ruby 2.0
geeforr
343
31k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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ϥΠϑΛૹΖ͏ʂ