Slide 1

Slide 1 text

mruby ͷ Hello World 2018/07/20 Fukuoka.rb #100 LT ODA Hirohito

Slide 2

Slide 2 text

mruby ͱ͸Կͧ΍ʁ

Slide 3

Slide 3 text

mruby ͱ͸Կͧ΍ʁ https://github.com/mruby/mruby#what-is-mruby

Slide 4

Slide 4 text

mruby ͱ͸Կͧ΍ʁ ૊ࠐιϑτ΢ΣΞʹ࢖ΘΕΔࣄΛ໨తͱͨ͠
 ܰྔͳߴڃϓϩάϥϛϯάݴޠ

Slide 5

Slide 5 text

Hello World

Slide 6

Slide 6 text

αϯϓϧίʔυ https://github.com/mruby/mruby/wiki/Hello-World#source-code

Slide 7

Slide 7 text

࣮ߦ݁Ռ https://github.com/mruby/mruby/wiki/Hello-World#execution

Slide 8

Slide 8 text

ͪΐͬͱ଴ͬͯʂ

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

ͳΜ͔ίʔυ௕͘ͳ͍ʁ

Slide 11

Slide 11 text

Ruby Ͱॻ͍ͨ Hello World C Ͱॻ͍ͨ Hello World

Slide 12

Slide 12 text

͜ͷίʔυ͸ԿΛ΍͍ͬͯΔʁ

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

puts ͸ C ͷؔ਺

Slide 15

Slide 15 text

͜ΕΒ͕ mruby ͷػೳʢͷ͸ͣʣ

Slide 16

Slide 16 text

͜Ε͸ͻͱ·ͣແࢹ

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠ 5. ޙ࢝຤ ·ͭ΋ͱΏ͖ͻΖ௚఻ ૊ࠐ Rubyʮmrubyʯͷ͢΂ͯ ૯ूฤ ୈ 3 ճ mruby Λ૊ΈࠐΜͩϓϩάϥϜͷڍಈ

Slide 19

Slide 19 text

•mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);
 
 
 •mrb_close(mrb);
 


Slide 20

Slide 20 text

•mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);
 
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏

Slide 21

Slide 21 text

•mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);
 
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏

Slide 22

Slide 22 text

•mrb_state *mrb = mrb_open();
 
 
 •mrb_load_string(mrb, “p ‘hello world!’”);
 
 
 •mrb_close(mrb);
 
 → ϙΠϯλʔม਺ mrb ΛΦʔϓϯͯͦ͠͏ → mrb ΛΫϩʔζͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛ֬อͯͦ͠͏ → mrb ͷϝϞϦʔྖҬΛղ์ͯͦ͠͏ → mrb ʹจࣈྻΛϩʔυ࣮ͯ͠ߦͯͦ͠͏

Slide 23

Slide 23 text

1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠ 5. ޙ࢝຤ ·ͭ΋ͱΏ͖ͻΖ௚఻ ૊ࠐ Rubyʮmrubyʯͷ͢΂ͯ ૯ूฤ ୈ 3 ճ mruby Λ૊ΈࠐΜͩϓϩάϥϜͷڍಈ

Slide 24

Slide 24 text

1. όʔνϟϧϚγϯΛද͢ʮmrb_stateʯͷॳظԽ 2. ϓϩάϥϜݻ༗ͷΫϥεɺϝιουͷఆٛ 3. Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ 4. ඞཁʹԠͯ͡ʢϓϩάϥϜݻ༗ͷʣϝιουͷ ݺͼग़͠ 5. ޙ࢝຤ mruby Λ૊ΈࠐΜͩϓϩάϥϜͷڍಈ → mrb_open() → mrb_close(mrb) → mrb_load_string(mrb, “p ‘hello world!’”)

Slide 25

Slide 25 text

gdb

Slide 26

Slide 26 text

͜͜ʹϒϨΠΫϙΠϯτΛஔ͍ͯ εςοϓΞ΢τ࣮ߦ͢Δ

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

←͜͜Ͱʮhello world!ʯΛग़ྗ

Slide 30

Slide 30 text

←͜͜Ͱʮhello world!ʯΛग़ྗ

Slide 31

Slide 31 text

mrb_load_string_cxt Λ
 ௥͍͔͚ͯΈΔ

Slide 32

Slide 32 text

mrb_load_string_cxt ↓ mrb_load_nstring_cxt ↓ mrb_load_exec ↓ mrb_top_run ↓ mrb_vm_run ↓ mrb_vm_exec

Slide 33

Slide 33 text

mrb_vm_exec ͸໿ 2,000 ߦͷؔ਺

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

mruby ͷ verbose Φϓγϣϯ

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

mrb_vm_exec ؔ਺಺ʹ͋Δ
 ΦϖϥϯυͱࣅͨΑ͏ͳ΋ͷ͕
 ग़ྗ͞Ε͍ͯΔؾ͕͢Δ

Slide 38

Slide 38 text

ͳΜ͔ಡΊΔΑ͏ͳ
 ؾ͕͠ͳ͘΋ͳ͘ͳͬͨʂ

Slide 39

Slide 39 text

ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ ‘hello world!’ Λ୅ೖʢҾ਺Λઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ਺͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ

Slide 40

Slide 40 text

ᶃ Ϩδελʔ R1 ʹ self ΛϩʔυʢϨγʔόʔΛઃఆʣ ᶄ Ϩδελʔ R2 ʹ ‘hello world!’ Λ୅ೖʢҾ਺Λઃఆʣ ᶅ Ϩδελʔ R1 ͷΦϒδΣΫτʹରͯ͠ ‘p’ ϝιουΛ Ҿ਺͕̍ͭͰ࣮ߦ ɾɾɾᶃ ɾɾɾᶄ ɾɾɾᶅ → ݁Ռ “hello world!” Λग़ྗ͢Δ

Slide 41

Slide 41 text

ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) ͸ 1. mruby VM Λද͢ mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹม׵ͯ͠
 ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏΋ͷͰ͸ͳ͍͔ͱ͍͏ਪଌ

Slide 42

Slide 42 text

ͭ·Γ mrb_load_string(mrb, “p ‘hello world!’”) ͸ 1. mruby VM Λද͢ mrb ʹ 2. “p ‘hello world!’” ΛόΠτίʔυʹม׵ͯ͠
 ϩʔυ͠ 3. mruby ͷόΠτίʔυ໋ྩʹै࣮ͬͯߦ͢Δ ͱ͍͏΋ͷͰ͸ͳ͍͔ͱ͍͏ਪଌ → Ruby ϓϩάϥϜͷίϯύΠϧͱ࣮ߦ

Slide 43

Slide 43 text

·ͱΊ • Hello World Ͱ΋ϋοΫ͢ΔͱԞ͕ਂ͍ • Ruby ͷ YARV ΋ࣅͨΑ͏ͳײ͡ʁ

Slide 44

Slide 44 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠