Chapterبەش 1 · Lectureوانە 1.3

How Code Becomes a Running Program: Compilers and Interpretersچۆن کۆد دەبێت بە بەرنامەیەک کە کار دەکات: کۆمپایلەرەکان و ئینتەرپرێتەرەکان

Why source code must be translated; how a compiler and an interpreter work, what each is good at, and what happens to a mistake on line 4; and the modern mix used by Java and Python: bytecode, virtual machines and just-in-time compiling.

بۆچی دەبێت وەربگێڕدرێت؛ و چۆن کار دەکەن، هەر یەکێکیان بۆ چی باشە و هەڵەیەک لە دێڕی 4دا چی بەسەر دێت؛ هەروەها تێکەڵە نوێیەکەی Java و Python: ، و .

17 min read18 خولەک خوێندنەوە · 16 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain why a high-level program must be translated before the CPU can run it.
  • Describe how a compiler and an interpreter work, with their strengths and weaknesses.
  • Predict what each does with a mistake in the middle of a program.
  • Explain bytecode, virtual machines and JIT, and how Java and Python use them.
  • ڕوونی بکەیتەوە بۆچی بە دەبێت پێش جێبەجێکردن لەلایەن وەربگێڕدرێت.
  • وەسفی کارکردنی و بکەیت، لەگەڵ خاڵە بەهێز و لاوازەکانیان.
  • پێشبینی بکەیت هەر یەکێکیان چی بە هەڵەیەک لە ناوەڕاستی دەکات.
  • ، و JIT ڕوون بکەیتەوە و بڵێیت Java و Python چۆن بەکاریان دەهێنن.

Why code must be translatedبۆچی کۆد دەبێت وەربگێڕدرێت

You write source code in a high-level language, but the CPU can run only machine code — instructions in binary for its own CPU family (as you saw in What is programming?). So every program written in a high-level language must be translated into machine code before the CPU can carry it out.

تۆ بە دەنووسیت، بەڵام تەنها دەتوانێت جێبەجێ بکات: بۆ خێزانی خۆی (وەک لە بەرنامەسازی چییە؟ بینیت). کەواتە هەموو کە بە نووسرابێت دەبێت پێش ئەوەی جێبەجێی بکات وەربگێڕدرێت بۆ .

Two kinds of program do this translation: a compiler and an interpreter. Both turn a program written in a high-level language into machine code that the computer understands; they differ in when and how much they translate.

دوو جۆر ئەم وەرگێڕانە دەکەن: و . هەردووکیان کە بە نووسراوە دەکەن بە کە لێی تێدەگات؛ جیاوازییان لەوەدایە کەی و چەند وەردەگێڕن.

Quick checkپشکنینی خێراWhy can a CPU not run Java or Python source code directly?بۆچی ناتوانێت ڕاستەوخۆ Java یان Python جێبەجێ بکات؟

Why code must be translatedبۆچی کۆد دەبێت وەربگێڕدرێت

Two ways to translate: an analogyدوو ڕێگای وەرگێڕان: بەراوردێک

A translated book or a live interpreterکتێبی وەرگێڕدراو یان وەرگێڕی ڕاستەوخۆ

Think of a Kurdish novel that a publisher wants to sell in English. A translator can translate the whole book first, print it, and then thousands of people read it without the translator — that is a compiler. Or think of a doctor's visit with an interpreter sitting beside you, translating each sentence as soon as it is spoken — that is an interpreter: nothing is written down, and the interpreter must be there every time.

بیر لە ڕۆمانێکی کوردی بکەرەوە کە بڵاوکەرەوەیەک دەیەوێت بە ئینگلیزی بیفرۆشێت. وەرگێڕێک دەتوانێت سەرەتا هەموو کتێبەکە وەربگێڕێت و چاپی بکات، پاشان هەزاران کەس بەبێ وەرگێڕەکە دەیخوێننەوە: ئەمە . یان بیر لە سەردانی پزیشک بکەرەوە کە وەرگێڕێک لە تەنیشتتەوە دانیشتووە و هەر ڕستەیەک یەکسەر دوای وتنی وەردەگێڕێت: ئەمە ؛ هیچ شتێک نانووسرێتەوە و وەرگێڕەکە دەبێت هەموو جارێک ئامادە بێت.

Where the analogy stops workingسنووری ئەم نموونەیە

A book is translated for people, who could guess a missing word. A compiler or an interpreter must be perfectly exact, and modern languages often mix the two ideas, as you will see.

کتێب بۆ مرۆڤ وەردەگێڕدرێت کە دەتوانێت وشەیەکی ونبوو مەزەندە بکات. یان دەبێت تەواو ورد بێت و زمانە نوێیەکان زۆرجار هەردوو بیرۆکەکە تێکەڵ دەکەن، وەک دواتر دەیبینیت.

Quick checkپشکنینی خێراIn the analogy, which one is like an interpreter?لەم بەراوردەدا کامیان وەک وایە؟

The compiler: translate everything firstکۆمپایلەر: سەرەتا هەمووی وەربگێڕە

A compiler reads the whole program and translates it into machine code before anything runs. The result is usually saved as object code and then as an executable file, such as hello.exe on Windows. After that you run the executable as often as you like — the compiler and the source code are no longer needed.

هەموو دەخوێنێتەوە و پێش ئەوەی هیچ شتێک جێبەجێ بێت وەری دەگێڕێت بۆ . ئەنجامەکە زۆرجار وەک و پاشان وەک پاشەکەوت دەکرێت، وەک hello.exe لە Windowsـدا. دوای ئەوە چەند جار بتەوێت جێبەجێ دەکەیت؛ ئیتر نە و نە پێویست نین.

A compiler diagram. A source-code file, hello.c, with lines 1 to 5, goes into the compiler, which translates the whole program. Out comes machine code in an executable file, hello.exe. The CPU runs it and gives output. Step 1: compile once; all grammar errors are reported before anything runs. Step 2: run many times without the compiler. The executable works only on the kind of CPU and operating system it was made for.هێڵکارییەکی کۆمپایلەر. فایلی کۆدی سەرچاوە، hello.c، بە دێڕی 1 تا 5، دەچێتە ناو کۆمپایلەرەوە کە هەموو بەرنامەکە وەردەگێڕێت. کۆدی ئامێر لە فایلێکی جێبەجێکراودا دەردەچێت، hello.exe. CPU جێبەجێی دەکات و دەرخستە دەدات. هەنگاوی 1: یەک جار کۆمپایل بکە؛ هەموو هەڵەکانی داڕستن پێش جێبەجێکردنی هەر شتێک ڕادەگەیەنرێن. هەنگاوی 2: چەند جار جێبەجێی بکە بەبێ کۆمپایلەر. فایلە جێبەجێکراوەکە تەنها لەسەر ئەو جۆرە CPU و سیستەمی وەگەڕخەرەی بۆی دروست کراوە کار دەکات.
How a compiler works: source code → compiler → machine code → output. چۆن کار دەکات: ، پاشان ، پاشان ، پاشان .CêIT
  • Fast programs. Compiled programs tend to be faster and more efficient than interpreted ones: the translation is done once, ahead of time, and the compiler can study the whole program and improve the machine code it produces.
  • Errors before running. Grammar mistakes anywhere in the program are reported before any line runs.
  • A wait after every change. You must compile again each time you change the code; big programs can take minutes.
  • One platform per executable. An executable made for Windows on an Intel or AMD processor does not run on an Android phone or a Mac with an Apple chip; you compile again for each platform.
  • خێرا. زۆرجار لە ئینتەرپرێتکراوەکان خێراتر و کاراترن: وەرگێڕان یەک جار و پێشوەختە دەکرێت و دەتوانێت هەموو بخوێنێتەوە و ئەو دروستی دەکات باشتر بکات.
  • هەڵە پێش جێبەجێکردن. لە هەر شوێنێکی بن پێش جێبەجێبوونی هیچ دێڕێک ڕادەگەیەنرێن.
  • چاوەڕوانی دوای هەر گۆڕانکارییەک. هەر جارێک کۆدەکە دەگۆڕیت دەبێت دووبارە کۆمپایلی بکەیتەوە؛ دەکرێت چەند خولەکێک بخایەنن.
  • یەک بۆ هەر . کە بۆ Windows لەسەر پرۆسێسەری Intel یان AMD دروست کرابێت لەسەر مۆبایلێکی Android یان Macـێکی Apple کار ناکات؛ بۆ هەر دووبارە کۆمپایل دەکەیت.
Quick checkپشکنینی خێراAfter a C program has been compiled into an executable, what do you need to run it?دوای ئەوەی C کۆمپایل کرا بۆ ، بۆ جێبەجێکردنی چیت پێویستە؟

How do computers read code?Frame of Essence · Englishئینگلیزی · 3.6M viewsبینین · 167K likesلایک · Partبەشی 3:38–10:39 (ofلە 12:01)

See the difference between source code and machine code, and how a compiler turns what people write into what the CPU runs.

جیاوازیی نێوان و دەبینیت و چۆن ئەوەی مرۆڤ دەینووسێت دەکاتە شتێک کە جێبەجێی دەکات.

Watch 3:38-10:39: a compiler translates source code to machine code, and why that makes programming easier.

لە ⁦3:38⁩ تا ⁦10:39⁩ سەیر بکە: وەردەگێڕێت بۆ و بۆچی ئەمە ئاسانتر دەکات.

The interpreter: one statement at a timeئینتەرپرێتەر: هەر جارە ڕستەیەک

An interpreter translates the program one statement at a time and runs each statement at once. It reads a statement, translates it, runs it, then moves to the next. It does not produce a separate machine-code file: to run the program again, you need the source code and the interpreter.

هەر جارە وەردەگێڕێت و یەکسەر جێبەجێی دەکات. دەخوێنێتەوە، وەری دەگێڕێت، جێبەجێی دەکات، پاشان دەچێتە سەر دواتر. هیچ جیای دروست ناکات: بۆ دووبارە جێبەجێکردنی ، و پێویستە.

An interpreter diagram. A source-code file, script.sh, with lines 1 to 5, goes into the interpreter. Inside it three boxes form a loop: read the next statement, translate it, run it at once, and repeat until the last statement. Output comes out on the right. Notes: no separate machine-code file is made; the interpreter must be present every time the program runs.هێڵکارییەکی ئینتەرپرێتەر. فایلی کۆدی سەرچاوە، script.sh، بە دێڕی 1 تا 5، دەچێتە ناو ئینتەرپرێتەرەوە. لە ناویدا سێ چوارگۆشە خولێک پێکدەهێنن: ڕستەی دواتر بخوێنەوە، وەری بگێڕە، یەکسەر جێبەجێی بکە و دووبارە بکەرەوە تا کۆتا ڕستە. دەرخستە لە لای ڕاستەوە دەردەچێت. تێبینی: هیچ فایلێکی جیای کۆدی ئامێر دروست ناکرێت؛ ئینتەرپرێتەرەکە دەبێت هەموو جارێک کە بەرنامەکە جێبەجێ دەبێت ئامادە بێت.
How an interpreter works: source code → interpreter → output, statement by statement. چۆن کار دەکات: ، پاشان ، پاشان ، بە .CêIT
  • Quick to start. An interpreter takes little time to analyse the source code before it starts, so you see results immediately — handy while learning and testing ideas.
  • Slower overall. The total running time is usually longer than for compiled code, because the translating work happens while the program runs — and a statement inside a loop that runs a thousand times may be translated a thousand times.
  • Stops at the first failing statement. Statements before it have already run.
  • دەستپێکردنی خێرا. پێش دەستپێکردن کاتێکی کەم بۆ شیکردنەوەی بەسەر دەبات، بۆیە یەکسەر ئەنجام دەبینیت؛ لە کاتی فێربوون و تاقیکردنەوەی بیرۆکەدا بەسوودە.
  • بە گشتی هێواشتر. کۆی ئەو کاتەی جێبەجێکردن دەیخایەنێت زۆرجار لە کۆدی کۆمپایلکراو زیاترە، چونکە کاری وەرگێڕان لە کاتی کارکردنی ڕوو دەدات و لە ناو کە هەزار جار جێبەجێ دەبێت لەوانەیە هەزار جار وەربگێڕدرێت.
  • لە یەکەم شکستخواردوودا دەوەستێت. پێشووتر پێشتر جێبەجێ بوون.
Quick checkپشکنینی خێراWhy is a purely interpreted program usually slower overall than a compiled one?بۆچی کە تەنها ئینتەرپرێت دەکرێت زۆرجار بە گشتی لە یەکێکی کۆمپایلکراو هێواشترە؟

The interpreter: one statement at a timeئینتەرپرێتەر: هەر جارە ڕستەیەک

A mistake on line 4هەڵەیەک لە دێڕی 4دا

The two classic models behave very differently when the program has a mistake. Here is a five-line program in pseudocode with a typo on line 4: shwo instead of show. Watch what a compiler and an interpreter do with it.

هەردوو مۆدێلە کلاسیکییەکە کاتێک هەڵەی تێدایە زۆر جیاواز ڕەفتار دەکەن. ئەمە پێنج دێڕییە بە کە لە دێڕی 4دا هەڵەیەکی نووسینی تێدایە: shwo لە جیاتی show. سەیر بکە و چی پێ دەکەن.

An animation with two panels, Compiler and Interpreter, both holding the same five lines: show "Silav", x ← 10, show x * 2, shwo x (a typo), show "Done". The compiler reads all five lines first, reports “Error on line 4: unknown word shwo” and runs nothing; its output stays empty. The interpreter runs line 1 (output Silav), line 2, line 3 (output 20), then reaches line 4 and stops. At the end: compiler — 0 lines ran, fix the error and compile again; interpreter — 3 lines ran, then it stopped; fix line 4 and run again.
An animation with two panels, Compiler and Interpreter, both holding the same five lines: show "Silav", x ← 10, show x * 2, shwo x (a typo), show "Done". The compiler reads all five lines first, reports “Error on line 4: unknown word shwo” and runs nothing; its output stays empty. The interpreter runs line 1 (output Silav), line 2, line 3 (output 20), then reaches line 4 and stops. At the end: compiler — 0 lines ran, fix the error and compile again; interpreter — 3 lines ran, then it stopped; fix line 4 and run again.
The same typo: the compiler runs nothing, the interpreter runs three lines first.هەمان هەڵەی نووسین: هیچ جێبەجێ ناکات، سەرەتا سێ دێڕ جێبەجێ دەکات.CêIT
Quick checkپشکنینی خێراA program has a grammar mistake on its last line. What happens with a compiler? لە کۆتا دێڕیدا هەیە. لەگەڵ چی ڕوو دەدات؟

Compiler and interpreter comparedبەراوردی کۆمپایلەر و ئینتەرپرێتەر

The two classic modelsدوو مۆدێلە کلاسیکییەکە
PointخاڵCompilerInterpreter
Translatesچی وەردەگێڕێتthe whole program, before runningهەموو ، پێش جێبەجێکردنone statement at a time, while runningهەر جارە ، لە
Producesچی دروست دەکاتobject code and an executable file و no separate machine-code fileهیچ جیای
Start-upدەستپێکردنwait for compiling firstسەرەتا چاوەڕێی کۆمپایلکردنstarts at onceیەکسەر دەست پێ دەکات
Running speedخێرایی جێبەجێکردنusually fasterزۆرجار خێراترusually slowerزۆرجار هێواشتر
Grammar errorsall reported before runningهەموویان پێش جێبەجێکردن ڕادەگەیەنرێنfound when that statement is reachedکاتێک دەگاتە ئەو دەدۆزرێتەوە
To share the programبۆ بڵاوکردنەوەی give the executable (one per platform) بدە (یەکێک بۆ هەر )give the source code; users need the interpreter بدە؛ بەکارهێنەران پێویستە
Quick checkپشکنینی خێراWhich statement about interpreters is correct?کام قسە دەربارەی ڕاستە؟

١- چۆن لەگەڵ کۆمپیوتەرەکەمان قسەبکەینSmart Code کۆدی زیرەک · Kurdish (Sorani)کوردی (سۆرانی) · 4K viewsبینین · 153 likesلایک · Partبەشی 3:34–8:32 (ofلە 8:32)

In Kurdish: what a computer language is, what a high-level language is, and the difference between an interpreter and a compiler.

بە کوردی: زمانی چییە، چییە و جیاوازیی نێوان و .

Kurdish video from 3:34: compiler vs interpreter, which is better, languages that use each one or both.

ڤیدیۆیەکی کوردی، لە ⁦3:34⁩ بەدواوە: بەرامبەر ، کامیان باشترە و ئەو زمانانەی یەکێکیان یان هەردووکیان بەکاردەهێنن.

The modern way: bytecode and virtual machinesڕێگای نوێ: بایتکۆد و ئامێرە گریمانەییەکان

Most popular languages today use a third way that mixes the two. A compiler first translates the source code into bytecode: a compact list of simple instructions that is not machine code for any real CPU. Then a virtual machine — a computer made of software — runs the bytecode on the real CPU.

زۆربەی زمانە بەناوبانگەکانی ئەمڕۆ ڕێگایەکی سێیەم بەکار دەهێنن کە هەردووکیان تێکەڵ دەکات. سەرەتا وەردەگێڕێت بۆ : لیستێکی چڕی سادە کە هیچ ڕاستەقینە نییە. پاشان (کۆمپیوتەرێک کە لە دروست کراوە) لەسەر ڕاستەقینە جێبەجێ دەکات.

Three lanes. Compiler (C, C++, Go, Rust, Swift): source code → compiler → machine code → CPU. Interpreter (classic BASIC, shell scripts): source code → interpreter that translates and runs each statement → CPU. Bytecode + VM (Java, Kotlin, C#, Python): source code → compiler → bytecode → virtual machine, which runs it and uses JIT → CPU.سێ ڕێڕەو. کۆمپایلەر (C، C++، Go، Rust، Swift): کۆدی سەرچاوە، کۆمپایلەر، کۆدی ئامێر، CPU. ئینتەرپرێتەر (BASICـی کلاسیک، دەسنووسەکانی shell): کۆدی سەرچاوە، ئینتەرپرێتەر کە هەر ڕستەیەک وەردەگێڕێت و جێبەجێی دەکات، CPU. بایتکۆد + VM (Java، Kotlin، C#، Python): کۆدی سەرچاوە، کۆمپایلەر، بایتکۆد، ئامێری گریمانەیی کە جێبەجێی دەکات و JITـیش بەکار دەهێنێت، CPU.
Compiler, interpreter, and the modern mix: bytecode run by a virtual machine.، و تێکەڵە نوێیەکە: کە جێبەجێی دەکات.CêIT
  • Portable. The same bytecode runs on every computer that has the virtual machine, so you do not compile again for each platform.
  • Faster than pure interpreting. The hard part of translation (checking grammar, building instructions) is done once, ahead of time.
  • Even faster with JIT. Many virtual machines watch which parts run most and compile those parts to real machine code while the program runs.
  • گوازراوە. هەمان لەسەر هەموو کە هەبێت کار دەکات، بۆیە بۆ هەر دووبارە کۆمپایل ناکەیت.
  • خێراتر لە ئینتەرپرێتی ڕووت. بەشە قورسەکەی وەرگێڕان (پشکنینی ، دروستکردنی ) یەک جار و پێشوەختە دەکرێت.
  • خێراتریش بە JIT. زۆر سەیر دەکەن کام بەشانە زۆرتر جێبەجێ دەبن و ئەو بەشانە لە کاتی کارکردنی دەکەن بە ڕاستەقینە.
Quick checkپشکنینی خێراWhat does a virtual machine run? چی جێبەجێ دەکات؟

The modern way: bytecode and virtual machinesڕێگای نوێ: بایتکۆد و ئامێرە گریمانەییەکان

Java: compile with javac, run on the JVMJava: بە javac کۆمپایل بکە، لەسەر JVM جێبەجێی بکە

In Java you do the compiling yourself. The command javac Main.java reads the source file and writes the class file Main.class, which contains bytecode. The command java Main starts the Java Virtual Machine (JVM), which runs that bytecode. You can copy the same .class file to Windows, macOS or Linux, and it runs wherever a JVM is installed — Java's slogan “write once, run anywhere”.

لە Javaـدا کۆمپایلکردن خۆت دەیکەیت. javac Main.java سەرچاوەکە دەخوێنێتەوە و Main.class دەنووسێت کە تێدایە. java Main ⁦Java (JVM)⁩ دەست پێ دەکات کە ئەو جێبەجێ دەکات. دەتوانیت هەمان .class بۆ Windows، macOS یان Linux کۆپی بکەیت و لە هەر شوێنێک JVM دامەزرابێت کار دەکات: دروشمی Java «یەک جار بنووسە، لە هەموو شوێنێک جێبەجێی بکە».

Two rows. Java: Main.java (source file) → javac Main.java (you compile it) → Main.class (bytecode file) → java Main (the JVM runs it). Python: main.py (source file) → python main.py (compiles automatically) → bytecode (kept in memory) → Python VM (runs the bytecode). Both languages compile to bytecode; a virtual machine runs it on the real CPU.دوو ڕیز. Java: Main.java (فایلی سەرچاوە)، javac Main.java (خۆت کۆمپایلی دەکەیت)، Main.class (فایلی بایتکۆد)، java Main (JVM جێبەجێی دەکات). Python: main.py (فایلی سەرچاوە)، python main.py (بە خۆکاری کۆمپایل دەکات)، بایتکۆد (لە بیرگەدا دەمێنێتەوە)، Python VM (بایتکۆد جێبەجێ دەکات). هەردوو زمان بۆ بایتکۆد کۆمپایل دەکەن؛ ئامێرێکی گریمانەیی لەسەر CPUـی ڕاستەقینە جێبەجێی دەکات.
Java and Python both use bytecode; Java makes you compile, Python compiles for you.Java و Python هەردووکیان بەکار دەهێنن؛ Java وات لێ دەکات کۆمپایل بکەیت، Python بۆت دەکات.CêIT

The JVM starts by interpreting the bytecode. When it notices that a method has run many times, it compiles that method to machine code with its just-in-time (JIT) compiler, and from then on the method runs at full speed.

JVM بە ئینتەرپرێتکردنی دەست پێ دەکات. کاتێک دەبینێت چەندین جار جێبەجێ بووە، بە ئەو دەکات بە و لەوە بەدواوە بە تەواوی خێرایی جێبەجێ دەبێت.

Quick checkپشکنینی خێراWhat does javac Main.java produce?javac Main.java چی دروست دەکات؟

The modern way: bytecode and virtual machinesڕێگای نوێ: بایتکۆد و ئامێرە گریمانەییەکان

Python: compiled for you, every timePython: هەموو جارێک بۆت کۆمپایل دەکرێت

Python is usually called interpreted, but the standard Python (CPython, the one from python.org) works in two steps. When you run a file, it first compiles the whole file to bytecode — you never see this step. Then the Python virtual machine runs the bytecode. For files that your program imports, CPython saves the bytecode in .pyc files inside a __pycache__ folder, so the next start is faster.

Python زۆرجار پێی دەوترێت ئینتەرپرێتکراو، بەڵام Pythonـی ستاندارد (CPython، ئەوەی لە ⁦python.org⁩) بە دوو هەنگاو کار دەکات. کاتێک جێبەجێ دەکەیت، سەرەتا هەموو بۆ کۆمپایل دەکات؛ تۆ هەرگیز ئەم هەنگاوە نابینیت. پاشان Python جێبەجێ دەکات. بۆ ئەو هاوردەیان دەکات، CPython لە .pyc لە ناو __pycache__ـدا پاشەکەوت دەکات، بۆ ئەوەی جاری داهاتوو خێراتر دەست پێ بکات.

  • Python's bytecode is an internal detail: it can change between Python versions, so you share .py source files, not .pyc files.
  • Since Python 3.13 some CPython builds include an experimental JIT compiler; in Python 3.15 (2026) it is still experimental. Other Pythons, such as PyPy, have used a JIT for years.
  • That is why Python's own glossary says the difference between interpreted and compiled languages “can be blurry”.
  • Python وردەکارییەکی ناوخۆییە: دەکرێت لە نێوان Pythonـدا بگۆڕێت، بۆیە سەرچاوەی .py بڵاو دەکەیتەوە، نەک .pyc.
  • لە ⁦Python 3.13⁩ـەوە هەندێک CPython JITـی تاقیکارییان تێدایە؛ لە ⁦Python 3.15⁩دا ⁦(2026)⁩ هێشتا تاقیکارییە. Pythonـەکانی تر، وەک PyPy، چەندین ساڵە JIT بەکار دەهێنن.
  • بۆیە فەرهەنگۆکی خودی Python دەڵێت جیاوازیی نێوان زمانی ئینتەرپرێتکراو و کۆمپایلکراو «دەکرێت ناڕوون بێت».
Quick checkپشکنینی خێراYou run a Python file. What happens first? Python جێبەجێ دەکەیت. یەکەم شت چی ڕوو دەدات؟

The modern way: bytecode and virtual machinesڕێگای نوێ: بایتکۆد و ئامێرە گریمانەییەکان

Just-in-time compilingکۆمپایلکردنی کاتی جێبەجێکردن

Definitionپێناسە

Turning into while the program is running — for the parts that run most often — so that they run much faster. The Java virtual machine does this, and newer Python versions include an experimental JIT.

گۆڕینی بۆ لە کاتێکدا کار دەکات، بۆ ئەو بەشانەی زۆرتر جێبەجێ دەبن، بۆ ئەوەی زۆر خێراتر کار بکەن. Java ئەمە دەکات و وەشانە نوێیەکانی Pythonـیش JITـێکی تاقیکارییان تێدایە.

The tea-house orderداواکاریی چایخانە

A new waiter in a busy tea house checks with the owner every time someone orders the house special. After the tenth time he writes the recipe on a card and makes it straight away. A JIT compiler does the same: at first the virtual machine interprets the bytecode, but code that runs again and again is compiled once to machine code and then runs fast.

گارسۆنێکی نوێ لە چایخانەیەکی قەرەباڵغ هەر جارێک کەسێک خواردنەوە تایبەتەکەی چایخانەکە داوا دەکات لە خاوەنەکەی دەپرسێت. دوای جاری دەیەم ڕێگای دروستکردنەکەی لەسەر کارتێک دەنووسێت و یەکسەر دروستی دەکات. JIT هەمان کار دەکات: سەرەتا ئینتەرپرێت دەکات، بەڵام ئەو کۆدەی دووبارە و دووبارە جێبەجێ دەبێت یەک جار دەکرێت بە و پاشان خێرا کار دەکات.

Where the analogy stops workingسنووری ئەم نموونەیە

The waiter remembers only the popular orders; a JIT also compiles only the busy parts, because compiling takes time too. Code that runs once is simply interpreted.

گارسۆنەکە تەنها داواکارییە بەناوبانگەکان لەبەر دەکات؛ JITـیش تەنها بەشە زۆربەکارهاتووەکان کۆمپایل دەکات، چونکە کۆمپایلکردنیش کاتی دەوێت. ئەو کۆدەی تەنها یەک جار جێبەجێ دەبێت تەنها ئینتەرپرێت دەکرێت.

Quick checkپشکنینی خێراWhich code does a JIT compiler turn into machine code? JIT کام کۆد دەکات بە ؟

Compiler and Interpreter: Compiled Language vs Interpreted Programming LanguagesCoding Mentors · Englishئینگلیزی · 193K viewsبینین · 6.2K likesلایک · Partبەشی 3:35–6:05 (ofلە 6:05)

The middle way between compiling and interpreting: code becomes an intermediate language that a just-in-time compiler turns into machine code; Java, C# and Python examples.

ڕێگەی ناوەڕاست لە نێوان کۆمپایلکردن و ئینتەرپرێتکردندا: کۆد دەبێتە زمانێکی ناوەندی و پاشان بە دەکرێتە ؛ نموونەکانی ، ⁦C#⁩ و .

Watch from 3:35: the intermediate approach with a JIT compiler, and which languages are compiled, interpreted or hybrid.

لە ⁦3:35⁩ بەدواوە سەیر بکە: ڕێگە ناوەندییەکە بە JIT، پاشان کام زمان کۆمپایل دەکرێت، کام ئینتەرپرێت دەکرێت و کامیان تێکەڵە.

The modern way: bytecode and virtual machinesڕێگای نوێ: بایتکۆد و ئامێرە گریمانەییەکان

Which languages are “interpreted” today?ئەمڕۆ کام زمانانە «ئینتەرپرێتکراو»ن؟

Quick checkپشکنینی خێراWhich sentence about JavaScript, Python and Ruby is true today?کام ڕستە دەربارەی JavaScript، Python و Ruby ئەمڕۆ ڕاستە؟

Online “compilers”کۆمپایلەرە ئۆنلاینەکان

Websites such as programiz.com let you type code in a browser — even on a phone — press Run and see the output, without installing anything. Many call themselves an “online compiler”, even for Python. One site's own heading says “online compiler (interpreter)”, which is honest: your Python code is sent to the website's server (or run inside the browser), where an ordinary Python interpreter compiles it to bytecode and runs it.

وەک ⁦programiz.com⁩ ڕێگەت پێ دەدەن کۆد لە بنووسیت، تەنانەت لەسەر مۆبایل، Run دابگریت و ببینیت، بەبێ هیچ شتێک. زۆریان خۆیان ناو دەنێن « ئۆنلاین»، تەنانەت بۆ Pythonـیش. سەردێڕی یەکێک لە دەڵێت « ئۆنلاین ()»، کە ڕاستگۆیانەیە: کۆدی Pythonـەکەت دەنێردرێت بۆ (یان لە ناو جێبەجێ دەکرێت)، لەوێ ئاسایی Python بۆ کۆمپایلی دەکات و جێبەجێی دەکات.

Quick checkپشکنینی خێراYou press Run on an “online Python compiler”. Where does your code actually run?لەسەر « ئۆنلاینی Python» Run دادەگریت. کۆدەکەت بەڕاستی لە کوێ جێبەجێ دەبێت؟

Common mistakesهەڵە باوەکان

Mistaken ideaبیرۆکەی هەڵەWhat is trueڕاستییەکە
“Python is interpreted, so it never compiles.”«Python ئینتەرپرێت دەکرێت، کەواتە هەرگیز کۆمپایل ناکات.»CPython compiles every file to bytecode before running it.CPython پێش جێبەجێکردن هەموو بۆ کۆمپایل دەکات.
“javac turns Java into machine code.”«javac کۆدی Java دەکات بە .»javac makes bytecode (.class files); the JVM runs it and may JIT-compile parts.javac دروست دەکات ( ⁦.class⁩)؛ JVM جێبەجێی دەکات و لەوانەیە هەندێک بەشی JIT بکات.
“A compiled program cannot have errors.”« کۆمپایلکراو هەڵەی تێدا نابێت.»The compiler finds grammar errors only. Runtime errors and logic errors can still happen. تەنها دەدۆزێتەوە. و هێشتا ڕوو دەدەن.
“An .exe file runs on any computer.”« ⁦.exe⁩ لەسەر هەموو کار دەکات.»It runs only on the CPU type and operating system it was compiled for.تەنها لەسەر ئەو جۆرە و بۆی کۆمپایل کراوە کار دەکات.
“Interpreters always use less memory.”« هەمیشە کەمتر بەکار دەهێنن.»The interpreter itself is in memory while the program runs; there is no such rule. خۆی لە کاتی کارکردنی لە ؛ یاسایەکی وەها نییە.
“Share the .pyc file instead of the .py file.”«لە جیاتی ⁦.py⁩ ⁦.pyc⁩ بڵاو بکەرەوە.».pyc bytecode can change between Python versions. Share the .py source. ⁦.pyc⁩ دەکرێت لە نێوان Pythonـدا بگۆڕێت. سەرچاوەی ⁦.py⁩ بڵاو بکەرەوە.

Exercisesڕاهێنانەکان

ExerciseڕاهێنانWhich model?کام مۆدێل؟

Name the model in each case — compiler, interpreter, or bytecode + virtual machine: (a) A game studio sends players a ready-made .exe file. (b) A shell script is read and run line by line by the system shell. (c) A team copies one .class file to Windows and Linux servers and runs it with java.

لە هەر حاڵەتێکدا ناوی مۆدێلەکە بنووسە: ، یان + : (أ) ستۆدیۆیەکی یاری ئامادەی .exe دەنێرێت بۆ یاریزانان. (ب) shell دێڕ بە دێڕ لەلایەن shellـی سیستەمەکەوە دەخوێنرێتەوە و جێبەجێ دەکرێت. (ج) تیمێک یەک .class بۆ Windows و Linux کۆپی دەکات و بە java جێبەجێی دەکات.

Show answerوەڵامەکە پیشان بدە

(a) compiler — the machine code was made ahead of time; (b) interpreter; (c) bytecode + virtual machine — the same bytecode runs on any JVM.

(أ) : پێشوەختە دروست کراوە؛ (ب) ؛ (ج) + : هەمان لەسەر هەر JVMـێک کار دەکات.

ExerciseڕاهێنانPredict the outputدەرخستە پێشبینی بکە

This pseudocode program has a mistake on line 3 that is found only while it runs (it divides by zero). What does a classic interpreter show? Then imagine line 3 has a grammar mistake instead (shwo): what does a compiler show?

ئەم بە لە دێڕی 3دا هەڵەیەکی تێدایە کە تەنها لە دەدۆزرێتەوە (دابەشکردن بەسەر سفردا). کلاسیک چی پیشان دەدات؟ پاشان وا دابنێ دێڕی 3 لە جیاتی ئەوە هەیە (shwo): چی پیشان دەدات؟

ProgramبەرنامەTEXT
1  show "Start"
2  show 10 / 2
3  show 10 / 0
4  show "End"
Show answerوەڵامەکە پیشان بدە

The interpreter runs lines 1 and 2, so it shows Start and 5, then stops with an error on line 3; End never appears. With a grammar mistake on line 3, the compiler reports the error before running anything, so nothing is shown at all.

دێڕی 1 و 2 جێبەجێ دەکات، بۆیە Start و 5 پیشان دەدات، پاشان بە هەڵەیەک لە دێڕی 3دا دەوەستێت؛ End هەرگیز دەرناکەوێت. ئەگەر لە دێڕی 3دا هەبێت، پێش جێبەجێکردنی هەر شتێک هەڵەکە ڕادەگەیەنێت، بۆیە هیچ شتێک پیشان نادرێت.

ExerciseڕاهێنانWhy not everywhere?بۆچی لە هەموو شوێنێک نا؟

Karwan compiled a C program on his Windows laptop and sent game.exe to Lana, who has a Mac with an Apple chip. It does not run. Explain why, and give two ways to fix it.

کاروان C لەسەر لاپتۆپە Windowsـەکەی کۆمپایل کرد و game.exeـی بۆ لانا نارد کە Macـێکی Appleـی هەیە. کار ناکات. ڕوونی بکەرەوە بۆچی و دوو ڕێگا بۆ چارەسەرکردنی بڵێ.

Show answerوەڵامەکە پیشان بدە

The executable holds machine code for one CPU family and one operating system (Windows on an Intel or AMD processor). The Mac has a different CPU and a different operating system. Fixes: compile the source code again on or for a Mac, or write the program in a bytecode language such as Java, whose single .class file runs on any computer with a JVM.

یەک خێزانی و یەک تێدایە (Windows لەسەر پرۆسێسەری Intel یان ⁦AMD). Mac⁩ و جیاوازی هەیە. چارەسەر: لەسەر Mac یان بۆ Mac دووبارە کۆمپایل بکە، یان بە زمانێکی وەک Java بنووسە کە یەک .classـی لەسەر هەموو کە JVMـی هەبێت کار دەکات.

ExerciseڕاهێنانCorrect the reportڕاپۆرتەکە ڕاست بکەرەوە

Rewrite this sentence so that it is correct: “Interpreters generate no object code, hence they are memory efficient. JavaScript, Python and Ruby use interpreters.”

ئەم ڕستەیە بە شێوەیەکی ڕاست بنووسەرەوە: « هیچ دروست ناکەن، بۆیە بۆ کاران. JavaScript، Python و Ruby بەکار دەهێنن.»

Show answerوەڵامەکە پیشان بدە

For example: “An interpreter saves no separate object-code file, but it must itself be in memory while the program runs, so it does not necessarily use less memory. Today JavaScript, Python and Ruby are usually compiled to bytecode first, and their engines may also use JIT compilers.”

بۆ نموونە: « هیچ جیای پاشەکەوت ناکات، بەڵام خۆی دەبێت لە کاتی کارکردنی لە بێت، بۆیە پێویست نییە کەمتر بەکار بهێنێت. ئەمڕۆ JavaScript، Python و Ruby زۆرجار سەرەتا بۆ کۆمپایل دەکرێن و بزوێنەرەکانیان لەوانەیە JITـیش بەکار بهێنن.»

Summaryپوختە

  • The CPU runs only machine code, so source code must be translated by a compiler or an interpreter.
  • A compiler translates the whole program first into an executable; it runs fast, finds grammar errors early, and works on one platform.
  • An interpreter translates and runs one statement at a time; it starts quickly, runs more slowly and stops at the first failing statement.
  • Java, Kotlin, C# and Python compile to bytecode that a virtual machine runs; JIT compilers speed up the busy parts.
  • Java: javac → .class → JVM. Python: compiled automatically to bytecode (.pyc for imported files) → Python VM.
  • تەنها جێبەجێ دەکات، بۆیە دەبێت لەلایەن یان وەربگێڕدرێت.
  • سەرەتا هەموو وەردەگێڕێت بۆ ؛ خێرا کار دەکات، زوو دەدۆزێتەوە و لەسەر یەک کار دەکات.
  • هەر جارە وەردەگێڕێت و جێبەجێی دەکات؛ خێرا دەست پێ دەکات، هێواشتر کار دەکات و لە یەکەم شکستخواردوودا دەوەستێت.
  • Java، Kotlin، ⁦C#⁩ و Python بۆ کۆمپایل دەکەن کە جێبەجێی دەکات؛ JIT بەشە زۆربەکارهاتووەکان خێرا دەکەن.
  • ⁦Java: javac⁩، پاشان ⁦.class⁩، پاشان ⁦JVM. Python⁩: بە خۆکاری بۆ کۆمپایل دەکرێت (⁦.pyc⁩ بۆ )، پاشان ⁦Python VM⁩.
Review questionsپرسیارەکانی پێداچوونەوە
What is the main difference between a compiler and an interpreter?جیاوازیی سەرەکیی نێوان کۆمپایلەر و ئینتەرپرێتەر چییە؟

A compiler translates the whole program before running it; an interpreter translates and runs one statement at a time.

پێش جێبەجێکردن هەموو وەردەگێڕێت؛ هەر جارە وەردەگێڕێت و جێبەجێی دەکات.

What is bytecode, and what runs it?بایتکۆد چییە و چی جێبەجێی دەکات؟

A compact list of simple instructions made by a compiler, not real machine code; a virtual machine runs it.

لیستێکی چڕی سادەیە کە دروستی دەکات و ڕاستەقینە نییە؛ جێبەجێی دەکات.

Why is Python's interpreted-or-compiled label “blurry”?بۆچی ناوی ئینتەرپرێتکراو یان کۆمپایلکراو بۆ Python «ناڕوونە»؟

Because CPython compiles source code to bytecode and then interprets the bytecode on its virtual machine.

چونکە CPython بۆ کۆمپایل دەکات و پاشان لەسەر ئینتەرپرێت دەکات.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

Compiled vs Interpreted Programming Languages | What’s the Difference?Keep On Coding · Englishئینگلیزی · 86K viewsبینین · 4.2K likesلایک

A translated-book analogy for compilers and interpreters, their pros and cons, and hybrid languages that mix both.

بە نموونەی کتێبێکی وەرگێڕدراو و ڕوون دەکاتەوە، لەگەڵ سوود و کەموکوڕییەکانیان و ئەو زمانە تێکەڵانەی هەردوو ڕێگە بەکاردەهێنن.

Whole video: compiled languages (1:05), interpreted languages, pros and cons, hybrid languages (4:15).

هەموو ڤیدیۆکە: زمانە کۆمپایلکراوەکان ⁦(1:05)⁩، زمانە ئینتەرپرێتکراوەکان، سوود و کەموکوڕییەکان و زمانە تێکەڵەکان ⁦(4:15)⁩.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Algorithms, Pseudocode and Flowchartsئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوت

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.