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
500
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
410
TRICK 2022 に入選した話
jinroq
0
230
RubyKaigiとMicrosoftと私
jinroq
0
190
msgraph: Microsoft Graph API Client with Ruby
jinroq
0
280
Fukuoka.rb 2019活動報告・2020抱負
jinroq
0
250
福岡の方から参りました Fukuoka.rb です
jinroq
0
1.7k
Microsoft Graph API Client and OpenAPI
jinroq
0
970
Fukuoka.rb #150 LT
jinroq
0
260
5 分で分かるアイキューブドシステムズ
jinroq
0
550
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Writing Fast Ruby
sferik
628
61k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Optimizing for Happiness
mojombo
376
70k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Faster Mobile Websites
deanohume
305
30k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Gamification - CAS2011
davidbonilla
80
5.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building Adaptive Systems
keathley
38
2.4k
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 ࣅͨΑ͏ͳײ͡ʁ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠