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
900
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
38k
学びを得るための新卒 ISUCON / New Grad ISUCON for Learning
south37
4
41k
Other Decks in Programming
See All in Programming
/←このスケジュール表に立ち向かう フロントエンド開発戦略 / A front-end development strategy to tackle a single-slash schedule.
nrslib
1
590
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
430
Tuning GraphQL on Rails
pyama86
2
1k
Vue.js学習の振り返り
hiro_xre
2
130
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
役立つログに取り組もう
irof
26
8.6k
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
Featured
See All Featured
Happy Clients
brianwarren
97
6.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
KATA
mclloyd
29
13k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
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ϥΠϑΛૹΖ͏ʂ