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

TypeScript で型検査器を作る / Implementing a type checker with TypeScript

TypeScript で型検査器を作る / Implementing a type checker with TypeScript

E2fc870af7558b22cb90c227dce7b8dd?s=128

katashin

June 09, 2017
Tweet

Transcript

  1. 5ZQF4DSJQUͰܕݕࠪثΛ࡞Δ ܕษڧձ

  2. ܕݕࠪث w ͋Δܭࢉମܥʹ͓͚Δ߲ͷܕΛಋग़͢Δ w ܕ෇͚نଇʹ౰ͯ͸·Βͳ͍߲͕ଘࡏ͢Δ࣌͸
 ΤϥʔΛ౤͛Δ

  3. +BWB4DSJQUͷܕݕࠪثΛ ࡞ͬͯΈΔ w ඞཁʹഭΒΕͨͷͰʜʜ w ߏจ໦͸&TQSJNBͱ͔Λ࢖ͬͯಘΔ͜ͱ͕Ͱ͖Δ w 5ZQF4DSJQUͷܕ৘ใΛదٓ༗ޮ׆༻͢Δ w ؆୯ͷͨΊʹɺ߲͸෭࡞༻Λ࣋ͨͳ͍΋ͷͱ͢Δ

  4. "45&YQMPSFS IUUQTBTUFYQMPSFSOFU

  5. ܕ෇͚نଇͷྫ • true: boolean • t: string ∧ u: U

    → (t + u): string • t: T ∧ u: T → (t === u): boolean • t: { u: U } → t.u: U ˢΛͦͷ··࣮૷͢Ε͹0,
  6. είʔϓ w ݱࡏݕ͍ࠪͯ͠Δ߲Ͱར༻Մೳͳม਺ͷҰཡΛ
 ͓࣋ͬͯ͘ඞཁ͕͋ΔͷͰɺ function typeOf(ast: ESTree.Node, scope: Var[]): Type

    Έ͍ͨͳײ͡ʹͳΔ
  7. ΤϥʔΛूΊΔ w ܕ෇͚نଇʹ౰ͯ͸·Βͳ͍࣌ʹΤϥʔΛ౤͛Δ
 ͷͰ͸ͳ͘ɺจ຺ʹΤϥʔΛ௥Ճ͢Δ w ϝοηʔδ΍ιʔείʔυ্ͷ৔ॴΛ෇༩͢Δͱศར
  ΤσΟλʔͱ͔Ͱ੺ઢΛҾ͚Δ

  8. શମ૾ function typeOf(ast: ESTree.Node, scope: Var[]) { switch (ast.type) {

    case ‘BinaryOperator’: // … case ‘…’: default: this.errors.push({ message: ‘…’, start: …, end: … }) } }