$30 off During Our Annual Pro Sale. View Details »

Cookpad 2016 Summer Intern: Programming Paradigm

Cookpad 2016 Summer Intern: Programming Paradigm

クックパッド2016夏インターン講義5日目: プログラミングパラダイム

Minero Aoki

August 19, 2016
Tweet

More Decks by Minero Aoki

Other Decks in Technology

Transcript

  1. ϓϩάϥϛϯάύϥμΠϜ
    .JOFSP"PLJ

    View Slide

  2. ࢒೦ͳ͓஌Βͤ

    View Slide

  3. ϓϩάϥϛϯά

    ύϥμΠϜͷ

    ࿩ͳΜͯ

    Ұ੾͠·ͤΜ

    View Slide

  4. ͙͢ʹ໾ʹཱͨͳ͍
    ͜ͱΛֶͿ

    View Slide

  5. ͙͢ʹ໾ཱͭ஌ࣝ͸
    ͙͢໾ʹཱͨͳ͘ͳΔ

    View Slide

  6. ՝୊આ໌

    View Slide

  7. ՝୊
    +BWB4DSJQUίϯύΠϥΛ࣮૷ͤΑ

    View Slide

  8. ʜʜͱ͍͏ͷ͸

    ͕͢͞ʹ࣌ؒతʹແཧͳͷͰɺ

    View Slide

  9. ՝୊
    +BWB4DSJQUίϯύΠϥͷ

    ίʔυδΣωϨʔλʔΛ࣮૷ͤΑ

    View Slide

  10. +BWB4DSJQUʹ͍ͭͯ͸ͪ͜Β
    l&$."4DSJQU-BOHVBHF4QFDJpDBUJPOz
    IUUQXXXFDNBJOUFSOBUJPOBMPSHQVCMJDBUJPOT
    pMFT&$."45&DNBQEG

    View Slide

  11. ࠓ೔࣮૷͢Δػೳ
    w ੔਺Ϧςϥϧʢ ʣ
    w Ճࢉʢʣ
    w ৚݅ԋࢉࢠʢD UFʣͱJGจ
    w ؔ਺ݺͼग़͠ͱҾ਺ͷࢀরɺSFUVSOจ
    w ؆୯ͳ࠷దԽ
    w BOENPSF

    View Slide

  12. ίϯύΠϥͷجૅͱ
    +FU4QJEFS

    View Slide

  13. +FU4QJEFS
    w +FU4QJEFS͸ࠓճͷΠϯλʔϯઐ༻ʹ։ൃͨ͠
    +BWB4DSJQUίϯύΠϥ
    w 'JSFGPYͷ+BWB4DSJQU࣮૷Ͱ͋Δ4QJEFS.POLFZ
    7.༻ͷόΠτίʔυΛੜ੒͢Δ
    w ίϯύΠϥͷKFUTQJEFSίϚϯυͱɺ7.ͷKTWNί
    Ϛϯυ͔Β੒Δ

    View Slide

  14. ΠϯλʔϓϦλʔʹΑΔ࣮ߦ
    ίϯύΠϥʔʹΑΔ࣮ߦ
    ίϯύΠϥʔͱΠϯλϓϦλʔ
    ػցޠίʔυ
    ιʔείʔυ
    ίϯύΠϥʔ
    ίϯϐϡʔλʔ
    ιʔείʔυ
    ධՁث
    ࣮ߦ
    ࣮ߦ

    View Slide

  15. 7.ʹΑΔ࣮ߦ
    όʔνϟϧϚγϯ
    w ιϑτ΢ΣΞͰߏஙͨ͠ί
    ϯϐϡʔλʔ͕όʔνϟϧ
    Ϛγϯʢ7.7JSUVBM
    .BDIJOFʣ
    w +BWB7.͕༗໊͕ͩɺ࠷ۙ
    ͷΠϯλʔϓϦλʔ͸΄΅
    ͜Ε
    w +BWB7.ͷίʔυ͸όΠτ
    ίʔυͱݺ͹ΕΔ
    ಺෦ίʔυ
    ιʔείʔυ
    ίϯύΠϥʔ
    7.
    ࣮ߦ

    View Slide

  16. 4QJEFS.POLFZʢ$ʣ
    ಠࣗʹ࡞ͬͨ෦෼ʢ3VCZ$ʣ
    +FU4QJEFSͷΞʔΩςΫνϟ
    όʔνϟϧϚγϯ
    ίϯύΠϥʔ
    +BWB4DSJQU
    όΠτίʔυ
    KTDϑΝΠϧ
    +BWB4DSJQU
    ίϯύΠϥʔ
    ϩʔμʔ
    KTWNίϚϯυ
    KFUTQJEFSίϚϯυ

    View Slide

  17. +FU4QJEFSͷೖख
    w ҎԼͷϨϙδτϦΛ֎ͷ(JU)VCʢ()&Ͱ͸ͳ͍ʣ
    ͰGPSLɺDMPOF͍ͯͩ͘͠͞
    w IUUQTHJUIVCDPNBBNJOFKFUTQJEFSDPVSTFHJU
    w DMPOFઌʹDEͯ͠CVOEMFJOTUBMM

    View Slide

  18. Φϓγϣϯ͸IFMQʹฉ͚
    % ./bin/jetspider --help
    jetspider [options] {JS_FILE | -e SOURCE}
    --dump-tokens Dumps lexical tokens and quit.
    --dump-ast Dumps AST and quit.
    --dump-semantic Dumps semantic tree and quit.
    --dump-object Dumps object file and quit.
    -e, --source=TEXT Give source code from option.
    --help Prints this message and quit.
    % ./bin/jsvm --help
    Usage: ./bin/jsvm [options] SOURCE
    Options:
    -p, --print Executes source and print the last result.
    -t, --trace Executes source with tracing.
    -d, --disassemble Disassembles source.

    View Slide

  19. ίϯύΠϥͷҰൠతͳߏ੒
    ύʔαʔʢQBSTFSʣ
    ҙຯղੳثʢTFNBOUJDBOBMZ[FSʣ
    ΦϓςΟϚΠβʔʢPQUJNJ[FSʣ
    ίʔυδΣωϨʔλʔʢDPEFHFOFSBUPSʣ
    ιʔείʔυ
    ࣮ߦՄೳίʔυ
    ϑΣΠζߏจղੳ
    ϑΣΠζҙຯղੳ
    ϑΣΠζ࠷దԽ
    ϑΣΠζίʔυੜ੒

    View Slide

  20. +FU4QJEFSͷ࣮૷ঢ়گ
    ύʔαʔʢQBSTFSʣ
    ҙຯղੳثʢTFNBOUJDBOBMZ[FSʣ
    ΦϓςΟϚΠβʔʢPQUJNJ[FSʣ
    ίʔυδΣωϨʔλʔʢDPEFHFOFSBUPSʣ
    +BWB4DSJQUʢKTʣ
    4QJEFS.POLFZόΠτίʔυʢKTDʣ
    ະ׬੒
    ͳ͍

    View Slide

  21. +FU4QJEFSͷιʔεπϦʔ
    w CJO
    w KFUTQJEFSίϯύΠϥʔ
    w KTWN7.
    w MJCKFUTQJEFS
    w DPNQJMFSSCίϯύΠϥυϥΠόʔ
    w QBSTFSSCύʔαʔ
    w SFTPMWFSSCҙຯղੳث
    w DPEF@HFOFSBUPSSCίʔυδΣωϨʔλʔ
    w BTTFNCMFSSCόΠτίʔυ%4-
    w PCKFDU@pMFSC+4$ϑΝΠϧ
    ͜͜Λॻ͘

    View Slide

  22. ίϯύΠϧͷաఔ

    View Slide

  23. ϑΣΠζߏจղੳ
    w ιʔείʔυʢςΩετʣ
    ͷߏจΛνΣοΫ͢Δ
    ͱಉ࣌ʹɺѻ͍΍͍͢
    Α͏πϦʔߏ଄ʢ"45
    "CTUSBDU4ZOUBY5SFFʣ
    ΁ม׵͢Δ
    JG J
    \
    QSJOU J

    ^FMTF\
    J
    ^
    JG
    DBMM
    QSJOU J

    J
    UIFO
    FMTF
    MIT SIT
    GVODUJPO BSHT

    J
    MFGU SJHIU
    DPOE

    View Slide

  24. ࣈ۟ղੳ
    w ߏจղੳͰ͸·ͣιʔε
    ίʔυʢจࣈͷྻʣΛ
    τʔΫϯʢ୯ޠʣͷྻ
    ʹ෼ׂ͢Δ
    w ίϝϯτ΍ۭന͸͜ͷ
    ஈ֊Ͱফͯ͠͠·͏

    ʢ͜ͱ͕ଟ͍ɻ+4΍3VCZʹ͸҉໧ͷจ
    ऴ୺͕͋ΔͨΊվߦͷ৘ใ͸࢒͢ඞཁ
    ͕͋Δɻ+BWB%PD΍42-ώϯτͳͲί
    ϝϯτ͕ඞཁͳ৔߹΋͋Δʣ
    lJG J
    \aOQSJOU J
    aO^FMTF
    \aOJaO^z
    JG lz J

    lz \ laOz
    QSJOU J

    laOz ^ lz FMTF lz
    \ laOl J ll ʜʜ

    View Slide

  25. τʔΫϯྻΛݟΔ
    % ./bin/jetspider js/arith.js --dump-tokens
    FUNCTION function
    S " "
    IDENT f
    ( (
    IDENT x
    ) )
    S " "
    { {
    S "\n "
    RETURN return
    S " "
    NUMBER 1
    S " "
    + +
    S " "
    IDENT x
    S " "
    * *
    S " "
    NUMBER 3
    ; ;
    S "\n"
    } }
    S "\n"
    KFUTQJEFSEVNQUPLFOT'*-&KT
    GVODUJPOG Y
    \
    SFUVSOY
    ^
    ˝ιʔείʔυʢKTBSJUIKTʣ

    View Slide

  26. JGจ

    ؔ਺ݺͼग़͠
    ൺֱࣜ
    ڱٛͷߏจղੳ
    w τʔΫϯྻͷύλʔϯ͔ΒɺΑΓେ͖ͳߏ଄Λൃݟ
    ͍ͯ͘͠
    w ൃݟͨ͠ΒπϦʔʹ͢Δ
    JG J
    \ QSJOU J
    ʜʜ

    View Slide

  27. "45ΛݟΔ
    % ./bin/jetspider --dump-ast js/arith.js
    type: SourceElementsNode
    value:
    - type: FunctionDeclNode
    value: f
    arguments:
    - type: ParameterNode
    value: x
    function_body:
    type: FunctionBodyNode
    value:
    type: SourceElementsNode
    value:
    - type: ReturnNode
    value:
    type: AddNode
    left:
    type: NumberNode
    value: 1
    value:
    type: MultiplyNode
    left:
    type: ResolveNode
    value: x
    value:
    type: NumberNode
    value: 3
    KFUTQJEFSEVNQBTU'*-&KT
    GVODUJPOG Y
    \
    SFUVSOY
    ^
    ˝ιʔείʔυʢKTBSJUIKTʣ
    WBMVF
    "EE/PEF
    /VNCFS/PEF .VMUJQMZ/PEF
    3FTPMWF/PEF /VNCFS/PEF
    3FUVSO/PEF
    WBMVF
    MFGU WBMVF
    MFGU
    WBMVF
    WBMVFY
    WBMVF

    View Slide

  28. ϑΣΠζҙຯղੳ
    w ม਺ࢀরͱม਺એݴΛ݁ͼ͚ͭͨΓɺܕνΣοΫΛ
    ͨ͠Γ͢Δ
    w "45ʹ্هͷ৘ใΛ෇Ճͨ͠σʔλߏ଄ʢதؒίʔ
    υʣΛग़ྗ͢Δɻ"45Λͦͷ··࢖͏৔߹΋͋Ε͹ɺ
    όΠτίʔυʹ͍ۙίʔυΛ࢖͏͜ͱ΋͋Δ
    w +FU4QJEFSͰ͸ࢀর৘ใ෇͖ͷ"45Λग़ྗ͢Δ

    View Slide

  29. தؒίʔυΛݟΔ
    % ./bin/jetspider --dump-sem js/arith.js
    - type: FunctionDeclNode
    value: f
    arguments:
    - type: ParameterNode
    value: x
    function_body:
    type: FunctionBodyNode
    value:
    type: SourceElementsNode
    value:
    - type: ReturnNode
    value:
    type: AddNode
    left:
    type: NumberNode
    value: 1
    value:
    type: MultiplyNode
    left:
    type: ResolveNode
    value: x
    ref: "[function f]:param:x"
    value:
    type: NumberNode
    value: 3
    - type: SourceElementsNode
    value:
    -
    KFUTQJEFSEVNQTFNBOUJD'*-&KT
    "EE/PEF
    /VNCFS/PEF .VMUJQMZ/PEF
    3FTPMWF/PEF /VNCFS/PEF
    3FUVSO/PEF
    WBMVF
    MFGU WBMVF
    MFGU WBMVF
    WBMVF
    WBMVFY
    WBMVF
    WBMVFY
    QBSBNY
    1BSBNFUFS/PEF
    'VODUJPO%FDM/PEF
    BSHVNFOUT 7BSJBCMFΦϒδΣΫτ

    View Slide

  30. ϑΣΠζ࠷దԽ
    w ϓϩάϥϜͷҙຯΛม͑ͣʹ࣮ߦ଎౓Λ଎͘͠
    ͨΓɺ࢖༻ϝϞϦྔΛݮΒ͢ͳͲͷվળΛߦ͏
    w ఻౷తʹ͸ҙຯղੳͱίʔυੜ੒ͷؒʹҐஔ෇͚Β
    ΕΔ͕ɺίϯύΠϧͷ͋ΒΏΔஈ֊Ͱߦ͏͜ͱ͕Ͱ
    ͖Δ
    w ࠷ۙ͸ϦϯΫ࣌࠷దԽͱ͍͏΋ͷ΋͋ΔFH--7.
    w +FU4QJEFSͰ͸࠷దԽΛʢ·ͩʣߦ͍ͬͯͳ͍

    View Slide

  31. ϑΣΠζίʔυੜ੒
    w ҙຯղੳࡁΈͷσʔλ
    Λݩʹɺػցޠ΍7.ίʔ
    υΛੜ੒͢Δ
    w ࣮ࡍ͸ίʔυ͚ͩͰ͸
    ͳ͘ɺγϯϘϧςʔϒϧ
    ʢม਺දʣ΍ϦϯΫ৘
    ใ΋ؚΉΦϒδΣΫτϑΝ
    ΠϧΛੜ੒͢Δ
    "EE/PEF
    /VNCFS/PEF .VMUJQMZ/PEF
    3FTPMWF/PEF /VNCFS/PEF
    3FUVSO/PEF
    WBMVF
    MFGU WBMVF
    MFGU WBMVF
    WBMVF
    WBMVFY
    YQBSBN
    WBMVF
    dd 01 int8 1
    54 00 00 getarg 0
    dd 03 int8 3
    1d mul
    1b add
    05 return

    View Slide

  32. ίϯύΠϧ͢Δ
    KFUTQJEFS'*-&KT
    % ./bin/jetspider js/arith.js
    % ls -l js/arith.jsc
    -rw-r--r-- 1 minero-aoki staff 228 Aug 25 10:59 js/arith.jsc
    w KTϑΝΠϧΛࢦఆ͢Δ͚ͩ
    Ͱ0,
    w ֦ுࢠΛKTDʹม͑ͨϑΝ
    Πϧʢ+4$ϑΝΠϧʣ͕ੜ੒
    ͞ΕΔ

    View Slide

  33. +4$ϑΝΠϧΛݟΔ
    KFUTQJEFSEVNQPCKFDU'*-&KT
    % ./bin/jetspider --dump-obj js/arith.js
    - n_vars: 0
    n_args: 1
    vars:
    - x
    prolog_length: 0
    js_version: 185
    n_fixed: 0
    script_bits: 32
    code:
    - dd 01 int8 1
    - 54 00 00 getarg 0
    - dd 03 int8 3
    - 1d mul
    - 1b add
    - 05 return
    - c5 stop
    srcnotes: ''
    filename: js/arith.js
    lineno: 1
    n_slots: 3
    static_level: 1
    atoms: []
    blocks: []
    upvars: []
    regexps: []
    closed_args: []
    closed_vars: []
    trynotes: []
    consts: []
    - n_vars: 0
    n_args: 0
    ҎԼུ
    w όΠτίʔυ͚ͩͰ͸ͳ͘ɺ
    +4$ϑΝΠϧͷ߲໨͕͢΂ͯ
    දࣔ͞ΕΔ
    w ౰વ͚ͩͲίʔυδΣωϨʔ
    λʔ͕׬੒͍ͯ͠ͳ͍ͱΤ
    ϥʔʹͳͬͯ͠·͏
    w ࣮૷ͨ݁͠ՌΛ֬ೝ͢Δͨ
    Ίʹ࢖༻

    View Slide

  34. +4$ϑΝΠϧͷߏ଄
    w 4QJEFS.POLFZ಺Ͱ͸ؔ਺
    ఆٛͭʹରͯ͠TUSVDU
    +4'VODUJPO͕ͭੜ੒͞Ε
    Δ
    w +4$ϑΝΠϧʹ͸ιʔεϑΝ
    ΠϧͰఆٛ͞Εͨ͢΂ͯͷؔ
    ਺ʹରԠ͢ΔTUSVDU
    +4'VODUJPO͕֨ೲ͞ΕΔ
    w ࠷ޙͷͭ͸ৗʹTUSVDU
    +44DSJQUͰϝϯόʔ͕গͳ͍
    +4$ϑΝΠϧ
    TUSVDU+4'VODUJPO
    TUSVDU+4'VODUJPO
    TUSVDU+44DSJQU UPQMFWFM

    NBHJD Y%&"%#

    ؔ਺ͷ਺ʢ͸τοϓϨϕϧʣ

    View Slide

  35. +FU4QJEFSͰ
    ίʔυΛੜ੒͢Δ

    View Slide

  36. ࿅श໰୊
    w ੔਺ఆ਺ʢ/VNCFS/PEFʣΛ࣮૷ͤΑ
    w KTOVNCFSKT͕ಈ࡞͢ΔΑ͏ʹ࣮૷͠Α͏
    w ූ߸෇͖Ϗοτ੔਺ΛQVTI͢ΔzJOUz໋ྩΛ࢖͏

    View Slide

  37. ՝୊ͷ࣮૷εςοϓ
    ࣮૷͢΂͖+BWB4DSJQUͷίʔυΛ֬ೝ͢Δ

    ʢͰ͖Δ͚ͩγϯϓϧͳ+4ίʔυΛ༻ҙ͠Α͏ʂʣ
    KFUTQJEFSEVNQBTU TFNͰ"45ΛݟΔ
    KTWNE EJTBTTFNCMF
    Ͱʮ౴͑ʯͷόΠτίʔυΛݟΔ
    $PEF(FOFSBUPSͷϝιουΛ࣮૷͢Δ
    KFUTQJEFSEVNQPCKͰग़ྗ݁ՌΛ֬ೝ͢Δ
    ίϯύΠϧ͠ɺKTWNQSJOUͰ࣮ߦ͢Δ

    View Slide

  38. "45ΛݟΔ
    % ./bin/jetspider --dump-ast js/number.js
    type: SourceElementsNode
    value:
    - type: ExpressionStatementNode
    value:
    type: NumberNode
    value: 77
    ʮจʯͷϦετΛද͢ϊʔυ
    ͭͷ͔ࣜΒͳΔ
    ʮจʯͷϊʔυ
    ੔਺Ϧςϥϧ

    ͷϊʔυ

    View Slide

  39. ʮਖ਼ղʯΛݟΔ
    w KTWNE EJTBTTFNCMF
    ίϚϯυͰ4QJEFS.POLFZ
    ʹΑΔίϯύΠϧ݁ՌΛݟΔ͜ͱ͕Ͱ͖Δ
    w τοϓϨϕϧΛٯΞηϯϒϧ
    w ಛఆͷؔ਺ΛٯΞηϯϒϧ
    jsvm -d ϑΝΠϧ໊.js
    jsvm -d ϑΝΠϧ໊.js ؔ਺໊

    View Slide

  40. OVNCFSKTͷٯΞηϯϒϧ
    % ./bin/jsvm -d js/number.js
    main:
    00000: dd 4d int8 77
    00002: 02 popv
    00003: c5 stop
    ‣ Θ͔Βͳ໋͍ྩ͕͋ͬͨΒ(3061"%ͷόΠτ
    ίʔυϦϑΝϨϯεͰ֬ೝ
    /VNCFS/PEFͰग़ྗ͢΂͖෦෼
    &YQSFTTJPO4UBUFNFOU/PEF͕ग़ྗ
    τοϓϨϕϧͱؔ਺ͷ຤ඌͰࣗಈग़ྗ

    View Slide

  41. "45ͷτϥόʔε
    w USBWFSTFπϦʔͷϊʔ
    υΛॱ൪ʹͨͲ͍ͬͯ
    ͘ૢ࡞
    w खଓ͖ܕݴޠͳΒ࠶ؼ
    ݺͼग़͠ɺ001Ͱ͸
    7JTJUPSύλʔϯΛ࢖͏
    ͷ͕ఆੴ
    τϥόʔεʢUSBWFSTFʣ
    "EE/PEF
    /VNCFS/PEF .VMUJQMZ/PEF
    3FTPMWF/PEF /VNCFS/PEF
    3FUVSO/PEF
    ̍
    ̎
    ̏ ̐
    ̑ ̒

    View Slide

  42. 7JTJUPSύλʔϯͰ

    "45Λτϥόʔε͢Δ
    DMBTT"457JTJUPS
    EFGWJTJU@3FUVSO/PEF OPEF

    WJTJUOPEFWBMVFˡSFUVSOจͷࣜΛτϥόʔε
    FOE
    EFGWJTJU@"EE/PEF OPEF

    WJTJUOPEFMFGUˡlzͷࠨଆͷࢬΛτϥόʔε
    WJTJUOPEFWBMVFˡlzͷӈଆͷࢬΛτϥόʔε
    FOE
    EFGWJTJU@/VNCFS/PEF OPEF

    ੔਺Ϧςϥϧʹ͸ͨͲΔࢬ͕ͳ͍ʢMFBGʣ
    FOE
    FOE
    "EE/PEF
    /VNCFS/PEF /VNCFS/PEF
    3FUVSO/PEF

    View Slide

  43. WJTJUϝιουͷ࣮૷
    w ଞͷݴޠͩͱେม͕ͩ3VCZͳΒ@@TFOE@@ͰҰൃ
    EFGWJTJU OPEF

    @@TFOE@@ lWJTJU@\OPEFDMBTT^z

    FOE

    View Slide

  44. όΠτίʔυͷग़ྗ
    w "TTFNCMFSΦϒδΣΫτʹఆٛ͞Ε͍ͯΔɺόΠ
    τίʔυͱಉ໊ͷϝιουΛݺ΂͹Α͍
    w $PEF(FOFSBUPSΫϥε಺Ͱ͸!BTNʹ"TTFNCMFS
    ΦϒδΣΫτ͕ೖ͍ͬͯΔ
    w ྫ
    w !BTNQPQ
    w !BTNHFUBSH

    View Slide

  45. +4$ϑΝΠϧΛ࣮ߦ͢Δ
    w KTWNίϚϯυʹKTDϑΝΠϧΛࢦఆ͢Δͱɺͦͷ
    ίʔυΛ࣮ߦ͢Δ
    w QSJOUΦϓγϣϯ෇͖ͩͱɺ࣮ߦͨ͋͠ͱ࠷ޙͷࣜ
    ͷ஋Λදࣔ͢Δ
    w ؔ਺ݺͼग़͠Λ࣮૷͢Δ·Ͱ͸஋ΛදࣔͰ͖ͳ͍
    ͷͰɺ͜ͷΦϓγϣϯͰ݁ՌΛ֬ೝ͢Δ
    KTWN'*-&KTD
    KTWNQSJOU'*-&KTD

    View Slide

  46. ࿅श໰୊
    w llԋࢉࢠʢ"EE/PEFʣΛ࣮૷ͤΑ
    w KTBEEKT KTBEEKTΛಈ࡞ͤ͞Α͏
    w lzԋࢉࢠʢ4VCUSBDU/PEFʣͷ࣮૷͕ࢀߟʹͳΔ
    w BEEKT BEEKTͰొ৔͢Δάϩʔόϧม਺POF UXP UISFFʹ͸ͦΕͧΕ
    ੔਺ ͕ࣄલʹ୅ೖͯ͋͠ΔʢKTWNͷಠࣗ࢓༷ʣ
    w ͷΑ͏ʹϦςϥϧ͚ͩͷՃࢉͩͱɺ࠷దԽ͞ΕͯՃࢉࣗମ͕ফ໓
    ͯ͠͠·͏ͷͰɺม਺Λ࢖ͬͯ࠷దԽΛճආ͍ͯ͠Δʜʜ

    View Slide

  47. 4QJEFS.POLFZ7.
    ࣮ߦͷ࢓૊ΈʢʣελοΫ
    w 4QJEFS.POLFZͷ7.͸ελο
    ΫϚγϯ
    w ໋֤ྩ͸ɺ7.ελοΫͷઌ
    ಄ʹ஋ΛੵΉʢQVTIʣɺऔ
    Γग़ͯ͠ܭࢉ͢ΔʢQPQʣɺ
    ࢀরͯ͠ܭࢉ͢Δɺͷ͍ͣ
    Ε͔ͷॲཧΛߦ͏ʢ૊Έ߹
    Θͤ΋ΞϦʣ
    w DGϨδελϚγϯ
    int8 5
    add
    int8 3
    return





    QPQ
    QVTI
    QVTI
    QVTI
    HFU

    View Slide

  48. 7.ͷಈ࡞ΛݟΔ
    w KTWNʹUSBDFΦϓγϣ
    ϯΛ෇͚࣮ͯߦ͢ΔͱҎ
    Լͷ಺༰΋ग़ྗͰ͖Δ
    w ࣮ߦ͠Α͏ͱ͍ͯ͠Δ
    όΠτίʔυ
    w QVTIͱQPQ
    w มԽޙͷ7.ελοΫ
    KTWNUSBDF'*-&KTD
    % ./bin/jsvm --trace js/lvar.js
    1: 00000: 00 nop
    stack:
    6: 00001: f1 00 00 callglobal "f"
    stack: function f() {\n var a = 1, b;\n
    p(a);\n} undefined
    6: 00004: 3a 00 00 call 0
    inputs: f, f @ 2
    output: (void 0) @ 0
    stack:
    2: 00000: 3f one
    output: 1 @ 1
    stack: 1
    2: 00001: 57 00 00 setlocal 0
    inputs: 1 @ 1
    output: (void 0) @ 0
    stack:
    2: 00005: 56 00 01 getlocal 1
    output: b @ 1
    stack: undefined
    2: 00008: 51 pop
    inputs: b @ 1
    stack:
    3: 00009: d9 00 00 callgname "p"
    ....

    View Slide

  49. ࿅श໰୊
    w &YQSFTTJPO4UBUFNFOUϊʔυʢͭ·ΓʮจʯʣͰ
    QPQ໋ྩʢQPQW໋ྩʣΛൃߦ͍ͯ͠Δͷ͸Կͷͨ
    Ί͔ʁ
    w QPQ໋ྩΛൃߦ͠ͳ͔ͬͨΒԿ͕ى͖Δͷ͔͔֬Ί
    Α͏

    View Slide

  50. ৚݅෼ذͱ
    δϟϯϓ໋ྩ

    View Slide

  51. ՝୊
    w ৚݅ԋࢉࢠʢB CDʣΛ࣮૷ͤΑ
    w KTDPOEFYQSKTΛಈ͔ͦ͏
    w ͏·͘ॻ͘ͱδϟϯϓ໋ྩʢJGFR HPUPʣͭͰࡁΉ

    View Slide

  52. 4QJEFS.POLFZ7.

    ࣮ߦͷ࢓૊Έʢʣ1$
    w ໋ྩ͸όΠτҎ্ͰɺՄม௕ɻ
    ྫ͑͹͔͚ࢉΛ͢ΔNVM໋ྩ͸
    Y%ͷόΠτ
    w 1$ 1SPHSBN$PVOUFS
    Ϩδε
    λʔ͸ݱࡏ࣮ߦதͷʢ͜Ε͔Β
    ࣮ߦ͢ΔʣόΠτίʔυҐஔΛ
    ࢦ͢
    w 1$͕ࢦ໋͢ྩΛ࣮ߦͯ͠1$Λ
    ࣍ʹਐΊΔɺ͕7.ͷجຊͷಈ͖
    dd 01 int8 1
    54 00 00 getarg 0
    dd 03 int8 3
    1d mul
    1b add
    05 return
    1$
    dd 01 int8 1
    54 00 00 getarg 0
    dd 03 int8 3
    1d mul
    1b add
    05 return
    1$


    HFUBSHΛ࣮ߦ

    View Slide

  53. 4QJEFS.POLFZ7.
    ࣮ߦͷ࢓૊Έʢʣແ৚݅δϟϯϓ
    w ແ৚݅δϟϯϓ໋ྩ
    HPUP͸1$Λมߋ͢Δ
    w ʮHPUPʯ͸

    ʮ1$Λʯ͢ΔޮՌ
    ͕͋Δ
    ....
    07 00 0f ifeq 15
    d9 00 00 callgname 0
    dd 07 int8 7
    3a 00 01 call 1
    51 pop
    06 00 0c goto 12
    d9 00 00 callgname 0
    dd 09 int8 9
    3a 00 01 call 1
    51 pop
    c5 stop
    1$

    ....
    07 00 0f ifeq 15
    d9 00 00 callgname 0
    dd 07 int8 7
    3a 00 01 call 1
    51 pop
    06 00 0c goto 12
    d9 00 00 callgname 0
    dd 09 int8 9
    3a 00 01 call 1
    51 pop
    c5 stop
    1$

    View Slide

  54. 4QJEFS.POLFZ7.
    ࣮ߦͷ࢓૊Έʢʣ৚݅෇͖δϟϯϓ
    w ʮJGFRʯ͸ʮελο
    Ϋઌ಄͕GBMTFͳΒ1$
    Λʯ

    ͨͿΜɺʮUSVFͳΒͦͷ··࣍ͷ໋ྩʹߦ͖ɺGBMTFͳ
    Βඈ΂ʯͱ͍͏ҙਤͩͱࢥ͏͚Ͳʜʜɻ

    ͪͳΈʹJGFRͱ͍͏໊લͷͤ͘ʹ౳Ձൺֱ΋͠ͳ͍ɻ
    ....
    07 00 0f ifeq 15
    d9 00 00 callgname 0
    dd 07 int8 7
    3a 00 01 call 1
    51 pop
    06 00 0c goto 12
    d9 00 00 callgname 0
    dd 09 int8 9
    3a 00 01 call 1
    51 pop
    c5 stop
    1$

    ....
    07 00 0f ifeq 15
    d9 00 00 callgname 0
    dd 07 int8 7
    3a 00 01 call 1
    51 pop
    06 00 0c goto 12
    d9 00 00 callgname 0
    dd 09 int8 9
    3a 00 01 call 1
    51 pop
    c5 stop
    1$

    View Slide

  55. +FU4QJEFSͰͷ
    ٯॱํ޲΁ͷδϟϯϓ
    w ਐߦํ޲ͱٯ΁δϟϯϓ͢Δͱ͖͸ɺ
    !BTNMPDBUJPOΛ࢖͏
    MPD!BTNMPDBUJPO
    ʢͳʹ໋͔ྩʣˡMPD͸͜ͷ໋ྩͷΦϑηοτΛࢦ͢-PDBUJPO

    !BTNHPUPMPDˡMPDͷҐஔ΁δϟϯϓʢ໭Δʣ

    View Slide

  56. +FU4QJEFSͰͷ
    ਐߦํ޲΁ͷδϟϯϓ
    w ਐߦํ޲΁δϟϯϓ͢Δͱ͖͸ɺ·ͩੜ੒͍ͯ͠ͳ͍ίʔ
    υͷҐஔ͕ඞཁʹͳΔ
    w !BTNMB[Z@MPDBUJPOͰ۩ମతͳ஋ͷຒ·͍ͬͯͳ͍
    -PDBUJPOΦϒδΣΫτΛੜ੒͠ɺδϟϯϓ͍ͨ͠ઌͰ
    pY@MPDBUJPOΛݺΜͰ஋ΛຒΊΔ
    MPD!BTNMB[Z@MPDBUJPO

    !BTNHPUPMPDˡMPD΁δϟϯϓ


    !BTNpY@MPDBUJPO MPD
    ˡMPDͷҐஔΛఆٛ

    ʢԿ໋͔ྩʣ

    View Slide

  57. ؔ਺ͷݺͼग़͠

    View Slide

  58. ՝୊
    w ؔ਺ݺͼग़͠ʢ'VODUJPO$BMM/PEFʣΛ࣮૷ͤΑɻ
    ·ͣ͸άϩʔόϧؔ਺ͷΈαϙʔτ͠Α͏ɻ
    w KTGVODBMMKTΛಈ͔ͦ͏ɻ
    w Q͸ࣄલʹఆٛ͞Εͨؔ਺Ͱɺ3VCZͷQͱಉ͘͡ΦϒδΣΫτΛ͍͍ײ͡ʹ
    දࣔ͢Δಇ͖͕͋Δɻ
    w ώϯτ໋ྩͷγʔέϯε͸࣍ͷͱ͓Γɻ
    DBMMHOBNFlؔ਺໊zˡؔ਺Λऔಘͯ͠ελοΫʹϓογϡ
    ୈҾ਺ΛελοΫʹϓογϡ
    ୈҾ਺ΛελοΫʹϓογϡ
    ʜʜ
    DBMMҾ਺ͷ਺

    View Slide

  59. ՝୊
    w Ҿ਺ͷࢀরͱɺSFUVSOจΛ࣮૷ͤΑɻ
    w KTSFUVSOKT KTQBSBNKT͕ಈ࡞͢ΔΑ͏ʹ͠Α͏ɻ
    w ؔ਺ఆٛࣗମ͸͢Ͱʹ࣮૷͞Ε͍ͯΔɻ
    w ϩʔΧϧม਺͸·ͬͨ͘ҧ͏ରԠ͕ඞཁɻ·࣮ͩ૷͠ͳͯ͘Α͍ɻ
    w HFUBSH໋ྩͷҾ਺͸ม਺໊Ͱ͸ͳ͘ύϥϝʔλʔ*%ɻ

    ύϥϝʔλʔ*%͸ɺ3FTPMWF/PEF͔ΒOPEFWBSJBCMFJOEFYͰऔΕΔɻ

    View Slide

  60. ࠷దԽͱ
    ϓϩάϥϜͷҙຯ

    View Slide

  61. ՝୊
    w ੔਺Ϧςϥϧ͕zzͷͱ͖͸JOU໋ྩͰ͸ͳ͘POF
    ໋ྩΛ࢖͏Α͏࠷దԽͤΑ
    w KTPQUPOFKT͕࠷దԽ͞ΕΔΑ͏ʹ͠Α͏
    w lzԋࢉͷఆ਺৞ΈࠐΈΛ࣮૷ͤΑ
    w "45ϨϕϧͰॲཧ͢Δํ๏ͱɺόΠτίʔυϨϕϧͰॲཧ͢Δํ๏ͷͭ
    ͕ߟ͑ΒΕΔɻ"45ϨϕϧͰॲཧͯ͠͠·͏ͷָ͕ɻ
    w KTPQUBEEKTͰBEE໋ྩ͕ൃߦ͞Εͳ͍Α͏ʹ͠Α͏

    View Slide

  62. ୅දతͳ࣮ߦ଎౓࠷దԽ
    w ໋ྩڧ౓ͷ௿ݮ
    w JOU EE
    ˠPOF G

    w YˠY
    w ఆ਺ͷίϯύΠϧ࣌ܭࢉʢఆ਺৞ΈࠐΈʣ
    w QSJOU J
    ˠQSJOU J

    w ॲཧͷϧʔϓ֎΁ͷҠಈ
    w GPS WBSJJJ
    \QSJOU YJ
    ^

    ˣ

    WBSOY

    GPS WBSJJJ
    \QSJOU OJ
    ^

    View Slide

  63. ϓϩάϥϜͷҙຯͱ͸
    w ϓϩάϥϜͷҙຯ͸มΘ͍ͬͯͳ͍Α͏ʹࢥ͑Δ
    w มΘ͍ͬͯͳ͍΋ͷʢ㲈ҙຯʣ
    w ࣜͷ஋ʢʣ
    w ϓϩάϥϜ֎ʹݟ͑ΔมԽʢʮʯͱදࣔ͞ΕΔʣ
    w มΘͬͨ΋ͷʢ㱠ҙຯʣ
    w ܭࢉաఔ
    w ϝϞϦ্ͷ஋ͷมߋύλʔϯ
    QSJOU
    QSJOU

    ࠷దԽͷͨΊ࣍ͷΑ͏ͳఆ਺৞ΈࠐΈΛͨ͠ͱ͢Δ
    ˞ͨͩ͠ݴޠʹΑΓʮҙຯʯ͸ҟͳΔ

    View Slide

  64. ϓϩάϥϜͷҙຯΛ
    ఆٛɾදݱ͢Δͭͷํ๏
    w ૢ࡞తҙຯ࿦ʢ0QFSBUJPOBM4FNBOUJDTʣ
    w ͋ΔݴޠͷදݱΛɺΑΓܗࣜతͳݴޠʹม׵͢Δ͜ͱ
    ͰҙຯΛදݱ͢ΔɻίϯύΠϥʔͷఆٛʹ͍ۙ

    ˠDGνϡʔϦϯάϚγϯɺϥϜμܭࢉ
    w දࣔతҙຯ࿦ʢ%FOPUBUJPOBM4FNBOUJDTʣ
    w ू߹΍ؔ਺ͳͲ਺ֶతͳ֓೦Λ༻͍ͯҙຯΛදݱ͢Δɻ
    ΠϯλϓϦλʔͷఆٛʹ͍ۙɻ
    w ެཧతҙຯ࿦ʢ"YJPNBUJDT4FNBOUJDTʣ
    w ͳΜ͔࿦ཧࣜͰදݱ͢ΔΒ͍͠

    View Slide

  65. ͖ͭͮ͸ຊͰ
    ʰΞϯμʔελϯσΟϯάίϯ
    ϐϡςʔγϣϯʱ
    IUUQXXXBNB[PODPKQEQ
    9

    View Slide

  66. ˞͔͜͜Βઌʹ͸ߨٛ͸
    ͳ͍ͷͰ࣮૷͋ΔͷΈ

    View Slide

  67. ՝୊
    w ූ߸෇͖Ϗοτ੔਺·Ͱѻ͑ΔΑ͏ʹͤΑ
    w จࣈྻϦςϥϧΛ࣮૷ͤΑ

    View Slide

  68. ՝୊
    w XIJMFจΛ࣮૷ͤΑ
    w CSFBLจͱDPOUJOVFจΛ࣮૷ͤΑ

    View Slide

  69. ՝୊
    w ϩʔΧϧม਺ͷࢀরͱ୅ೖΛ࣮૷ͤΑ
    w 3FTPMWF/PEFͷOWBSJBCMFʹ͸7BSJBCMFΦϒδΣΫτ͕ೖ͍ͬͯͯɺͦͷ
    7BSJBCMFΦϒδΣΫτ͔Β͸OWBSJBCMFJOEFYͰϩʔΧϧม਺*%͕औΕΔ

    View Slide

  70. ՝୊
    w ޙஔΠϯΫϦϝϯτʢJʣΛ࣮૷ͤΑ

    View Slide

  71. ՝୊
    w ҎԼͷΦϒδΣΫτࢦ޲ػೳΛ࣮૷ͤΑ
    w OFXࣜ
    w ϓϩύςΟͷಡΈॻ͖
    w PCKQSPQܗ͚ࣜͩͰΑ͍ɻPCK͸ෆཁʢจࣈྻϦςϥϧΛ࣮૷
    ͍ͯ͠ͳ͍ͱҙຯͳ͍ͨΊʣ
    w ϝιουݺͼग़͠
    w ϝιουఆٛ͸͢Ͱʹఆٛ͞Ε͍ͯΔؔ਺ΛϓϩύςΟʹηοτ͢Δ
    ͜ͱͰ୅ସ͢ΔʢԼهࢀরʣͷͰɺݺͼग़͚ͩ͠ͰΑ͍

    GVODUJPOPCK@N
    \SFUVSO^

    PCKNPCK@N

    View Slide

  72. ՝୊
    w ഑ྻϦςϥϧΛ࣮૷ͤΑ

    View Slide

  73. ࠷ऴ՝୊
    w ແ໊ؔ਺Λ࣮૷ͤΑ
    w ͜ͷ՝୊ʹݶΓ$PEF(FOFSBUPSҎ֎ͷίʔυมߋ͕ඞཁͳՄೳੑ͕͋Δ

    View Slide