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
コンパイルの違い
Search
nikawa2161
September 16, 2025
11
0
Share
コンパイルの違い
nikawa2161
September 16, 2025
More Decks by nikawa2161
See All by nikawa2161
Node.js Subpath imports
nikawa2161
0
15
Sagaパターン入門(続編)
nikawa2161
0
28
Sagaパターン入門
nikawa2161
0
35
沖縄観光とPostgreSQL排他制約の話
nikawa2161
0
33
20251209_プログラミング原則の学び
nikawa2161
0
22
自分のコードを数年ぶりに読んだら
nikawa2161
0
16
ユーザーインタビュー分析に参加して得られたことと気づき
nikawa2161
0
22
oEmbedとは?
nikawa2161
0
73
はじめまして、にかわです
nikawa2161
0
18
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Paper Plane (Part 1)
katiecoart
PRO
0
7.9k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Building an army of robots
kneath
306
46k
Skip the Path - Find Your Career Trail
mkilby
1
130
How to Talk to Developers About Accessibility
jct
2
210
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
580
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
190
Transcript
TypeScriptのコンパイルは他の言語と少し違う 1
コンパイル方式とインタプリタ方式 2
低水準言語 コンピュータが理解しやすい言語 機械語やアセンブリ言語がこれにあたる。 機械語の例: 01001000 11000111 11000000 00000001 00000000 00000000
00000000 アセンブリ言語の例(C言語の add 関数をコンパイル後に変換したもの): add: mov eax, edi ; 第1 引数 edi add eax, esi ; 第2 引数 esi ret 3
高水準言語 人が理解しやすい自然言語に近い言語 C言語やJavaScriptなど。 例: int add(int a, int b) {
return a + b; } 読みやすく、操作も簡単。普段私たちが使う言語はほとんど高水準言語。 4
翻訳の方法 高水準言語を低水準言語に翻訳する方法には大きく2種類ある。 5
コンパイル方式 プログラム全体を事前に翻訳 → 実行ファイルを作る。 翻訳を行うのが「コンパイラ」 。 特徴: 実行は速いが、ビルドに時間がかかる。 6
インタプリタ方式 1行ずつ翻訳しながら実行。 特徴: 実行前のビルドが不要、修正後すぐ実行できる。ただし速度は遅め。 7
例: PHP <?php for ($i = 1; $i <= 5;
$i++) { if ($i % 2 == 0) { echo "$i: hoge"; } else { echo "$i: huga"; } } ?> php sample.php 8
TypeScript のコンパイルと実行 TypeScript。 特徴的なのは「高水準言語 → 高水準言語」に変換している点。 9
コンパイルの流れ 1. TS ファイル作成 function greet(name: string) { console.log("Hello, "
+ name); } 2. コンパイル実行 tsc src/greet.ts このとき ①型チェック と ②JavaScript への変換 が行われる。 10
① 型チェック greet(123); // $ tsc sample.ts // error TS2345:
Argument of type 'number' is not assignable to parameter of type 'string'. 11
② JavaScript への変換 function greet(name) { console.log("Hello, " + name);
} 12
図解 一般的な「コンパイル」は、低水準言語に翻訳 TypeScriptコンパイルの変わっているのは、JavaScriptなのでまだ「高水準→高水 準」となっている 13
最後に 通常の「コンパイル」は 高水準 → 低水準。 TypeScript のコンパイルは「高水準 → 高水準(TS →
JS) 」 。 実行時は JavaScript エンジン(V8など)が JIT コンパイルを使って処理。 ビルドとランタイムは分離しているため、 型チェックは tsc 変換は esbuild など別ツール を組み合わせて使うことも可能。 tsgo で「コンパイル速度を10倍速くする」こともできる 14