Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今から始める Inline::C 入門

Kei Kamikawa
September 23, 2018

今から始める Inline::C 入門

Okinawa.pm #7 で Inline::C を使ったコードを紹介しながらしゃべりました。

- お気に入りのワンライナー
perl -E 'use Inline C => q{ SV*codehex(char*a,char*b){return newSVpvf("I Love %s and %s",a,b);} }; say codehex+Perl=>Go'

- illguts の PDF
https://st.aticpan.org/source/RURBAN/illguts-0.49/illguts.pdf

Kei Kamikawa

September 23, 2018
Tweet

More Decks by Kei Kamikawa

Other Decks in Programming

Transcript

  1. ࠓ͔Β࢝ΊΔ*OMJOF$ೖ໳
    PLJOBXBQN

    View full-size slide

  2. !DPEFIFY !$PEF)FY
    w .JDSPTFSWJDFTΛ։ൃͯ͠Δ
    w ࠷ۙ͸(P࣌ʑ1FSM
    w ϋΠαΠ0LJOBXBQN

    View full-size slide

  3. *OMJOF$

    ࢖ͬͨ͜ͱ͋Γ·͔͢

    View full-size slide

  4. *OMJOF$
    w $ݴޠͷ$
    w 1FSMͷαϒϧʔνϯΛ$Ͱॻ͘͜ͱ͕Ͱ͖Δ
    w ΋ͪΖΜ$ଆͰ1FSMͷ"1*ͷػೳ΋࢖͑Δ
    w εΫϦϓτ্ʹॻ͚ΔͷͰ1FSM"1*ͷ

    ѻ͍ํͷྑ͍ษڧʹͳΔ

    View full-size slide

  5. ͲΜͳ෩ʹॻ͚Δͷʁʁ

    View full-size slide

  6. Ϟδϡʔϧͷϩʔυ

    View full-size slide

  7. Ϟδϡʔϧͷϩʔυ
    $ͷίʔυΛهड़

    View full-size slide

  8. Ϟδϡʔϧͷϩʔυ
    $ͷίʔυΛهड़
    ؔ਺ݺͼग़͠

    View full-size slide

  9. γϯϓϧʂʂ

    View full-size slide

  10. QFSMFVTF*OMJOF$
    R\WPJETBZ
    \QSJOUG )FMMP
    8PSMEaO
    ^^TBZ

    View full-size slide

  11. ϫϯϥΠφʔͱͯ͠΋ʂʂ

    View full-size slide

  12. ࠓճ঺հ͢Δ΋ͷ
    w 1FSMͰ$Λѻ͏ͨΊʹ
    w 1FSM"1*Ͱ࢖͏࠷௿ݶͷجຊܕΛཧղ͢Δ
    w ܕͷؔ܎ੑΛ஌Δ
    w $͔Β1FSM΁஋Λฦ͢
    w 1FSMͷ஋Λ$΁౉͢
    w ܕม׵ͬͯͲ͏΍ͬͯΔͷʁ

    View full-size slide

  13. 1FSMͷܕΛ஌Ζ͏ʂ
    1FSMͰ$Λѻ͏ͨΊʹ࠷௿ݶඞཁͳܕ

    View full-size slide

  14. 47ܕ
    w 1FSMͰѻΘΕΔ஋͸47ܕ͔Β೿ੜ͍ͯ͠Δ
    w 1FSMͷجຊܕͷશͯ͸47ܕ΁ม׵Ͱ͖Δ
    w "7 )7 (7 $7 37ͳͲͳͲ

    View full-size slide

  15. IUUQTTUBUJDQBOPSHTPVSDF363#"/JMMHVUT
    TWUZQFTQOH

    View full-size slide

  16. ϓϦϛςΟϒͳܕ

    View full-size slide

  17. ϓϦϛςΟϒͳܕ
    w ϓϦϛςΟϒͳܕ͸47͕͍࣋ͬͯΔ
    w εΧϥͳ஋ͷܕΛࢦ͢
    w *7 /7 17 37

    View full-size slide

  18. 17

    NZQWTUSJOH

    View full-size slide

  19. 37

    NZSWaIW

    View full-size slide

  20. *7ʹWPJEͷϙΠϯλ΋

    ֨ೲ͢Δ͜ͱ͕Ͱ͖Δʂ

    View full-size slide

  21. ࢀߟʹͳΔϖʔδ
    w IUUQTTUBUJDQBOPSHTPVSDF363#"/
    JMMHVUTJMMHVUTQEG
    w $ʹΑΔ1FSM֦ுೖ໳

    IUUQYTVCUVUHJUIVCJP

    View full-size slide

  22. $͔Β1FSM΁஋Λฦ͢
    $͔Β1FSM΁஋Λฦؔ͢਺Λఆٛ͢Δ

    View full-size slide

  23. JOUΛฦ͢ίʔυ

    View full-size slide

  24. DIBSΛฦ͢ίʔυ

    View full-size slide

  25. 1FSMͰड͚औΔ࣌
    w $ͷੈքͰ͸JOU΍DIBSͷ··
    w 1FSMͷੈք΁஋͕౉Δ࣌ʹܕ͕ม׵͞ΕΔ
    w ม׵͞ΕΔཧ༝ͱͯ͠UZQFNBQͱ͍͏΋ͷ͕

    ؔΘ͖ͬͯ·͕͢͜Ε͸·ͨޙड़

    View full-size slide

  26. 1FSMͷ஋Λ$΁౉͢
    1FSM͔Β$΁஋Λฦؔ͢਺Λఆٛ͢Δ

    View full-size slide

  27. DIBSΛड͚औΔؔ਺

    View full-size slide

  28. JOUΛड͚औΔؔ਺

    View full-size slide

  29. $Ͱड͚औΔ࣌
    w 1FSMͷੈքͰ͸47ͷ··
    w $ͷੈք΁஋͕౉Δ࣌ʹܕ͕ม׵͞ΕΔ
    w ͜͜Ͱ΋ม׵͞ΕΔཧ༝ͱͯ͠UZQFNBQͱ͍
    ͏΋ͷ͕ؔΘ͖ͬͯ·͢

    View full-size slide

  30. UZQFNBQͬͯԿʁ
    ܕ͕ࣗಈͰม׵͞ΕΔ࢓૊Έ

    View full-size slide

  31. IUUQTHJUIVCDPNJOHZEPUOFUJOMJOFDQNDQFSMCJOEJOHT

    View full-size slide

  32. IUUQTHJUIVCDPN1FSMQFSMCMPCCMFBEMJC&YU6UJMTUZQFNBQ

    View full-size slide

  33. UZQFNBQ
    w JOU͸5@*7Ͱఆٛ͞ΕͯΔม׵ͷ࢓૊ΈΛ࢖͏
    w DIBS͸5@17Ͱఆٛ͞Ε͍ͯΔ࢓૊ΈΛ࢖͏
    w */165 065165ʹͦΕͧΕίϯόʔλʔΛఆٛ
    w */1651FSM$΁ͷίϯόʔλ
    w 065165$1FSM΁ͷίϯόʔλ

    View full-size slide

  34. $ perldoc perlxstypemap

    View full-size slide

  35. JOUͷ৔߹
    w JOU 5@*7
    w */165
    • $var = ($type)SvIV($arg)
    w 065165
    • sv_setiv($arg, (IV)$var);

    View full-size slide

  36. DIBSͷ৔߹
    w DIBS 5@17
    w */165
    • $var = ($type)SvPV_nolen($arg)
    w 065165
    • sv_setpv((SV*)$arg, $var);

    View full-size slide

  37. ·ͱΊ
    w *OMJOF$Λ࢖ͬͯ1FSMͱ΍ΓͱΓ͢Δ؆୯ͳ

    ίʔυΛ࢖ͬͯઆ໌ͨ͠
    w 1FSMʹ΋ܕ͸ଘࡏ͢Δ
    w ݴޠؒͰͷܕม׵๏͸UZQFNBQͰఆٛ͞ΕͯΔ
    w ୯७ͳ৔߹1FSMͷܕΛҙࣝ͢Δඞཁ͸ͳ͍
    w ؆୯ʹॻ͚Δʂʂ

    View full-size slide