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
mruby の Hello World
Search
jinroq
July 20, 2018
0
490
mruby の Hello World
2018/07/20 Fukuoka.rb #100 LT
jinroq
July 20, 2018
Tweet
Share
More Decks by jinroq
See All by jinroq
Fukuoka.rb 2023 年度活動報告
jinroq
0
400
TRICK 2022 に入選した話
jinroq
0
220
RubyKaigiとMicrosoftと私
jinroq
0
180
msgraph: Microsoft Graph API Client with Ruby
jinroq
0
270
Fukuoka.rb 2019活動報告・2020抱負
jinroq
0
250
福岡の方から参りました Fukuoka.rb です
jinroq
0
1.7k
Microsoft Graph API Client and OpenAPI
jinroq
0
960
Fukuoka.rb #150 LT
jinroq
0
260
5 分で分かるアイキューブドシステムズ
jinroq
0
540
Featured
See All Featured
It's Worth the Effort
3n
183
28k
How STYLIGHT went responsive
nonsquared
95
5.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
For a Future-Friendly Web
brad_frost
175
9.4k
Code Reviewing Like a Champion
maltzj
520
39k
Facilitating Awesome Meetings
lara
50
6.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How GitHub (no longer) Works
holman
311
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Transcript
mruby ͷ Hello World 2018/07/20 Fukuoka.rb #100 LT ODA Hirohito
mruby ͱԿͧʁ
mruby ͱԿͧʁ https://github.com/mruby/mruby#what-is-mruby
mruby ͱԿͧʁ ࠐιϑτΣΞʹΘΕΔࣄΛతͱͨ͠ ܰྔͳߴڃϓϩάϥϛϯάݴޠ
Hello World
αϯϓϧίʔυ https://github.com/mruby/mruby/wiki/Hello-World#source-code
࣮ߦ݁Ռ https://github.com/mruby/mruby/wiki/Hello-World#execution
ͪΐͬͱͬͯʂ
None
ͳΜ͔ίʔυ͘ͳ͍ʁ
Ruby Ͱॻ͍ͨ Hello World C Ͱॻ͍ͨ Hello World
͜ͷίʔυԿΛ͍ͬͯΔʁ
None
puts C ͷؔ
͜ΕΒ͕ mruby ͷػೳʢͷͣʣ
͜Εͻͱ·ͣແࢹ
None
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ ·ͭͱΏ͖ͻΖ ࠐ Rubyʮmrubyʯͷͯ͢ ૯ूฤ ୈ 3 ճ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb);
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏
•mrb_state *mrb = mrb_open(); •mrb_load_string(mrb, “p ‘hello world!’”);
•mrb_close(mrb); → ϙΠϯλʔม mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυ࣮ͯ͠ߦͯͦ͠͏
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ ·ͭͱΏ͖ͻΖ ࠐ Rubyʮmrubyʯͷͯ͢ ૯ूฤ ୈ 3 ճ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ
1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠
5. ޙ࢝ mruby ΛΈࠐΜͩϓϩάϥϜͷڍಈ → mrb_open() → mrb_close(mrb) → mrb_load_string(mrb, “p ‘hello world!’”)
gdb
͜͜ʹϒϨΠΫϙΠϯτΛஔ͍ͯ εςοϓΞτ࣮ߦ͢Δ
None
None
←͜͜Ͱʮhello world!ʯΛग़ྗ
←͜͜Ͱʮhello world!ʯΛग़ྗ
mrb_load_string_cxt Λ ͍͔͚ͯΈΔ
mrb_load_string_cxt ↓ mrb_load_nstring_cxt ↓ mrb_load_exec ↓ mrb_top_run ↓ mrb_vm_run ↓
mrb_vm_exec
mrb_vm_exec 2,000 ߦͷؔ
None
mruby ͷ verbose Φϓγϣϯ
None
mrb_vm_exec ؔʹ͋Δ ΦϖϥϯυͱࣅͨΑ͏ͳͷ͕ ग़ྗ͞Ε͍ͯΔؾ͕͢Δ
ͳΜ͔ಡΊΔΑ͏ͳ ؾ͕͠ͳ͘ͳ͘ͳͬͨʂ
ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ
‘hello world!’ ΛೖʢҾΛઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ
ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ
‘hello world!’ ΛೖʢҾΛઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ → ݁Ռ “hello world!” Λग़ྗ͢Δ
ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) 1. mruby VM Λද͢
mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹมͯ͠ ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏ͷͰͳ͍͔ͱ͍͏ਪଌ
ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) 1. mruby VM Λද͢
mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹมͯ͠ ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏ͷͰͳ͍͔ͱ͍͏ਪଌ → Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ
·ͱΊ • Hello World ͰϋοΫ͢ΔͱԞ͕ਂ͍ • Ruby ͷ YARV ࣅͨΑ͏ͳײ͡ʁ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠