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
390
TRICK 2022 に入選した話
jinroq
0
210
RubyKaigiとMicrosoftと私
jinroq
0
170
msgraph: Microsoft Graph API Client with Ruby
jinroq
0
260
Fukuoka.rb 2019活動報告・2020抱負
jinroq
0
250
福岡の方から参りました Fukuoka.rb です
jinroq
0
1.7k
Microsoft Graph API Client and OpenAPI
jinroq
0
950
Fukuoka.rb #150 LT
jinroq
0
260
5 分で分かるアイキューブドシステムズ
jinroq
0
530
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Typedesign – Prime Four
hannesfritz
40
2.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
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 ࣅͨΑ͏ͳײ͡ʁ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠