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
YesSQL, Process and Tooling at Scale
rocio
169
14k
Writing Fast Ruby
sferik
628
61k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Producing Creativity
orderedlist
PRO
341
39k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
The Cost Of JavaScript in 2023
addyosmani
45
7k
The Cult of Friendly URLs
andyhume
78
6.1k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Visualization
eitanlees
146
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
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 ࣅͨΑ͏ͳײ͡ʁ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠