Translation (program code ကို ဘာသာပြန်ခြင်း)

A1.4.1 (HL): Evaluate the translation processes of interpreters and compilers
မြန်မာလို: interpreter (code ကို တစ်ကြောင်းချင်း ဘာသာပြန်ပြီး run တဲ့ program) နဲ့ compiler (code တစ်ခုလုံးကို ကြိုတင် ဘာသာပြန်တဲ့ program) တွေရဲ့ ဘာသာပြန်ပုံ လုပ်ငန်းစဉ်တွေကို evaluate (အားသာချက်နဲ့ အားနည်းချက်တွေကို ချိန်ဆပြီး အကဲဖြတ်) လုပ်နိုင်ရပါမယ်။

ဒီစာမျက်နှာက Higher Level မှာပဲ အကဲဖြတ်တဲ့ အကြောင်းအရာ ဖြစ်ပါတယ်။ SL (Standard Level) နဲ့ HL (Higher Level) ဆိုတာ IB Computer Science (နိုင်ငံတကာ ကျောင်းတွေမှာ သင်တဲ့ ကွန်ပျူတာသိပ္ပံ သင်ရိုး) သင်တန်းရဲ့ အဆင့်နှစ်ဆင့်ဖြစ်ပြီး HL အပိုင်းတွေက ပိုနက်နက်ရှိုင်းရှိုင်း လေ့လာရတဲ့ အပိုင်းတွေပါ။


အဓိက အယူအဆများ

Translation ဆိုတာ ဘာလဲ (A1.4.1)

ကွန်ပျူတာတွေက machine code ကိုပဲ execute (run) လုပ်နိုင်ပါတယ်: machine code ဆိုတာ processor အမျိုးအစား တစ်ခုအတွက် သီးသန့် ဖြစ်တဲ့ binary (0 နဲ့ 1 ကိုပဲ သုံးတဲ့ ဂဏန်းစနစ်) ညွှန်ကြားချက်တွေပါ။ ဒါပေမယ့် programmer တွေက လူ ဖတ်ရ နားလည်ရလွယ်တဲ့ high-level language (လူ ဖတ်ရလွယ်တဲ့ programming language) တွေ (Java, Python, C) နဲ့ ရေးကြပါတယ်။ Translator ဆိုတာ source code (programmer ရေးထားတဲ့ မူရင်း code) ကို ကွန်ပျူတာ run နိုင်တဲ့ ပုံစံ ဖြစ်အောင် ပြောင်းပေးတဲ့ software ပါ။ ဒါကြောင့် ဒီစာမျက်နှာမှာ “translation” (ဘာသာပြန်ခြင်း) ဆိုတာ လူပြောတဲ့ ဘာသာစကားတွေကို ဘာသာပြန်တာ မဟုတ်ဘဲ program code ကို ကွန်ပျူတာ run နိုင်တဲ့ ပုံစံ ပြောင်းတာကို ဆိုလိုပါတယ်။

Translator အမျိုးအစား သုံးမျိုး ရှိပါတယ်:

Translator Input Output အလုပ်လုပ်ပုံ
Compiler High-level source code Machine code (object code: compile လုပ်ပြီး ထွက်လာတဲ့ machine code) Program တစ်ခုလုံးကို run မလုပ်ခင် ဘာသာပြန်ပါတယ်
Interpreter High-level source code တိုက်ရိုက် run ပါတယ် တစ်ကြောင်းချင်း ဘာသာပြန်ပြီး run ပါတယ်
Assembler (assembly language ကို machine code ပြောင်းပေးတဲ့ program) Assembly language (machine code ညွှန်ကြားချက်တွေကို စကားလုံးတိုတွေနဲ့ ရေးတဲ့ language) Machine code Mnemonic (ညွှန်ကြားချက်တွေအတွက် မှတ်ရလွယ်တဲ့ စကားလုံးတို) တစ်ခုကို binary ညွှန်ကြားချက် တစ်ခုနဲ့ တစ်ခုချင်း ကိုက် ဘာသာပြန်ပါတယ်

Compilers (code တစ်ခုလုံးကို ကြိုတင် ဘာသာပြန်တဲ့ program များ)

Compiler က source code တစ်ခုလုံးကို program မ run ခင် machine code (object code) အဖြစ် တစ်ခါတည်း ဘာသာပြန်ပါတယ်။

  1. Programmer က source code ကို ရေးပါတယ် (ဥပမာ program.c)
  2. Compiler က file တစ်ခုလုံးကို ဘာသာပြန်ရင်း syntax error (code ရေးထုံး မှားခြင်း) တွေကို စစ်ပါတယ်
  3. Error တွေ တွေ့ရင် တွေ့ခဲ့တဲ့ error အားလုံးကို စာရင်းပြုစုထားတဲ့ error report (အမှား စာရင်း) ကို ထုတ်ပေးပါတယ်: program ကို compile မလုပ်ပေးပါဘူး
  4. အောင်မြင်ရင် သီးခြား run လို့ရတဲ့ executable file (တိုက်ရိုက် run လို့ရတဲ့ file၊ object code) ကို ထုတ်ပေးပါတယ်
  5. Executable ကို compiler ဒါမှမဟုတ် source code မပါဘဲ ဖြန့်ဝေပြီး run နိုင်ပါတယ်

အဓိက လက္ခဏာများ:

  • Error တွေကို program မ run ခင် (compile time (compile လုပ်နေချိန်) မှာ) တွေ့ပါတယ်
  • ဘာသာပြန်တာ ပြီးပြီးသား ဖြစ်လို့ compile လုပ်ထားတဲ့ executable က မြန်မြန် run ပါတယ်
  • Source code ကို ပြင်တိုင်း ပြန် compile လုပ်ရပါတယ်
  • Executable က platform-specific (platform တစ်မျိုးတည်းအတွက်ပဲ ဖြစ်တဲ့) ဖြစ်ပါတယ်: processor/OS (operating system: ကွန်ပျူတာကို စီမံတဲ့ အဓိက software) အမျိုးအစား တစ်ခုအတွက်ပဲ compile လုပ်ထားတာပါ

Compile လုပ်ပြီး သုံးတဲ့ language များ: C, C++, Rust, Go


Interpreters (code ကို တစ်ကြောင်းချင်း ဘာသာပြန်ပြီး run တဲ့ program များ)

Interpreter က source code ကို သီးခြား executable file မထုတ်ဘဲ တစ်ကြောင်းချင်း ဘာသာပြန်ပြီး run ပါတယ်။

  1. Interpreter က source code ရဲ့ ပထမ line ကို ဖတ်ပါတယ်
  2. အဲဒီ line ကို machine code အဖြစ် ဘာသာပြန်ပြီး ချက်ချင်း run ပါတယ်
  3. အဲဒီ line မှာ error တွေ့ရင် run တာ ရပ်သွားပြီး error ကို ပြပါတယ်
  4. Error မရှိရင် နောက် line ကို ဆက်သွားပါတယ်
  5. Program ပြီးတဲ့အထိ ဒါမှမဟုတ် error တစ်ခု တွေ့တဲ့အထိ ဒီလို ထပ်ခါထပ်ခါ လုပ်ပါတယ်

အဓိက လက္ခဏာများ:

  • Error တွေကို run နေစဉ် (runtime (program run နေချိန်) မှာ) တွေ့ပါတယ်: program က ပြဿနာ တစ်ခုနဲ့ မတွေ့မချင်း run နေပါတယ်
  • Executable မထုတ်ပါဘူး: program run တိုင်း source code ကို interpret (ဘာသာပြန်ပြီး run) လုပ်ရပါတယ်
  • ပြင်လိုက်တာက ချက်ချင်း သက်ရောက်ပါတယ်၊ ပြန် compile လုပ်စရာ မလိုပါဘူး
  • Run တိုင်း ဘာသာပြန်ရလို့ run တာ ပိုနှေးပါတယ်
  • Program ကို run မယ့် စက်တိုင်းမှာ interpreter ကို install လုပ်ထားရပါမယ်

Interpret လုပ်ပြီး သုံးတဲ့ language များ: Python, Ruby, PHP, JavaScript (အစဉ်အလာအရ)


Compiler နဲ့ Interpreter နှိုင်းယှဉ်ချက်

အချက် Compiler Interpreter
ဘာသာပြန်ပုံ Program တစ်ခုလုံးကို တစ်ခါတည်း တစ်ကြောင်းချင်း
Run မြန်နှုန်း မြန်ပါတယ် (ဘာသာပြန်ပြီးသား) ပိုနှေးပါတယ် (run တိုင်း ဘာသာပြန်ရ)
Error ရှာပုံ မ run ခင် error အားလုံးကို ပြပါတယ် ပထမဆုံး တွေ့တဲ့ error မှာ ရပ်ပါတယ်
Output Executable file (object code) Executable မထုတ်ပါ
Debugging (program ထဲက အမှားကို ရှာပြီး ပြင်ခြင်း) ပိုခက်ပါတယ်: compile တစ်ခုလုံး ပြီးမှ error တွေကို စာရင်းနဲ့ ပြပါတယ် ပိုလွယ်ပါတယ်: error က line အတိအကျကို ညွှန်ပြပါတယ်
ဖြန့်ဝေပုံ Source မပါဘဲ executable ကို မျှဝေနိုင်ပါတယ် Source code + interpreter ကို မျှဝေရပါတယ်
ပြင်ပြီးနောက် ပြန် compile လုပ်ရပါတယ် ချက်ချင်း run ပါတယ်
Portability (တခြား platform တွေမှာ ပြောင်းသုံးနိုင်ခြင်း) Platform-specific executable Interpreter install လုပ်ထားတဲ့ ဘယ်နေရာမှာမဆို run ပါတယ်
Interpreters and Compilers (Bits and Bytes, Episode 6)
Interpreters and Compilers (Bits and Bytes, Episode 6)

A retro animated introduction to how interpreters and compilers translate programs. (3:35)

Watch on YouTube


Just-In-Time (JIT) Compilation (run နေစဉ် machine code အဖြစ် ပြောင်းခြင်း)

ခေတ်သစ် စနစ် တချို့က JIT compilation ကို သုံးပါတယ်။ JIT compilation ဆိုတာ compilation နဲ့ interpretation နှစ်ခုလုံးရဲ့ အချက်တွေကို ပေါင်းထားတဲ့ hybrid (ရောစပ်) နည်းလမ်းပါ။

  1. Source code ကို အရင်ဆုံး machine code အပြည့် မဟုတ်ဘဲ intermediate form (ကြားခံ ပုံစံ) ဖြစ်တဲ့ bytecode (virtual machine က run တဲ့ ကြားခံ code) အဖြစ် compile လုပ်ပါတယ်
  2. Runtime မှာ JIT compiler က bytecode ထဲက မကြာခဏ သုံးတဲ့ အပိုင်းတွေကို native machine code (ကိုယ့်စက်ရဲ့ processor က တိုက်ရိုက် run နိုင်တဲ့ machine code) အဖြစ် ဘာသာပြန်ပါတယ်
  3. Compile လုပ်ပြီးသား အပိုင်းတွေကို cache လုပ်ထားပါတယ် (ပြန်သုံးဖို့ သိမ်းထားပါတယ်)၊ ဒါကြောင့် နောက်တစ်ခါ ခေါ်တဲ့အခါ ပြန် compile လုပ်စရာ မလိုပါဘူး
  4. မကြာခဏ မသုံးတဲ့ code ကိုတော့ ဆက်ပြီး interpret လုပ်နိုင်ပါတယ်

ဘာကြောင့် JIT လဲ။ Interpretation ရဲ့ portability နဲ့ compilation ရဲ့ မြန်နှုန်း ကို ပေါင်းဖို့ ရည်ရွယ်ပါတယ်။ ပထမဆုံး run တာ ပိုနှေးပါတယ် (ဘာသာပြန်ရတဲ့ overhead (အပို ကုန်ကျတဲ့ အချိန်နဲ့ အလုပ်) ကြောင့်ပါ)၊ ဒါပေမယ့် JIT-compile လုပ်ပြီးသား code များလာတာနဲ့အမျှ စွမ်းဆောင်ရည် တိုးလာပါတယ်။

ဥပမာ: ခေတ်သစ် JavaScript engine တွေ (Chrome ထဲက V8၊ Firefox ထဲက SpiderMonkey) က JIT compilation ကို သုံးပါတယ်။ JavaScript code ကို အစမှာ interpret လုပ်ပေမယ့် မကြာခဏ run တဲ့ “hot” function (သီးခြား အလုပ်တစ်ခု လုပ်ပေးတဲ့ code အပိုင်း၊ Java မှာ method လို့ ခေါ်ပါတယ်) တွေကို runtime မှာ optimize လုပ်ထားတဲ့ (ပိုမြန်အောင် ပြင်ထားတဲ့) machine code အဖြစ် compile လုပ်ပါတယ်။


Bytecode Interpreters (bytecode ကို run ပေးတဲ့ interpreter များ) နဲ့ JVM

Bytecode ဆိုတာ high-level source code နဲ့ machine code ကြားမှာ ရှိတဲ့ intermediate representation (ကြားခံ ပုံစံ) ပါ။ Hardware က တိုက်ရိုက် run ဖို့ မဟုတ်ဘဲ virtual machine (hardware အစစ်ပေါ်မှာ software နဲ့ တည်ဆောက်ထားတဲ့ ကွန်ပျူတာအတု) က run ဖို့ ဒီဇိုင်းလုပ်ထားတာပါ။

အကျော်ကြားဆုံး ဥပမာက Java နဲ့ Java Virtual Machine (JVM) ပါ:

Your Code (.java)  -->  Compiler (javac)  -->  Bytecode (.class)  -->  JVM  -->  Output

ပုံထဲက “Your Code (.java)” က ကိုယ်ရေးတဲ့ code ကို ဆိုလိုပြီး မြားတွေက code က အဆင့် တစ်ဆင့်ပြီး တစ်ဆင့် ရွေ့သွားပုံကို ပြပါတယ်။

  1. Java compiler (javac) က source code ကို bytecode (.class file တွေ) အဖြစ် compile လုပ်ပါတယ်
  2. Bytecode က platform-independent (ဘယ် platform မှာမဆို သုံးလို့ရတဲ့) ဖြစ်ပါတယ်: ဘယ် processor အတွက်မှ သီးသန့် မဟုတ်ပါဘူး
  3. JVM က bytecode ကို ဖတ်ပြီး ကိုယ့်စက်ပေါ်မှာ run ပါတယ်
  4. ခေတ်သစ် JVM တွေမှာ မြန်အောင် မကြာခဏ သုံးတဲ့ bytecode ကို native machine code အဖြစ် compile လုပ်ပေးတဲ့ JIT compiler ပါပါတယ်

ဘာကြောင့် အဆင့် နှစ်ဆင့်လဲ။ စက်အမျိုးမျိုးမှာ instruction set (processor က နားလည်တဲ့ ညွှန်ကြားချက် အစု) တွေ မတူကြပါဘူး (CPU Architecture မှာ လေ့လာခဲ့တဲ့ CPU (ကွန်ပျူတာရဲ့ အဓိက processor) ဖွဲ့စည်းပုံကို ပြန်သတိရပါ)။ Bytecode အဖြစ် အရင် compile လုပ်ခြင်းအားဖြင့် Java က “write once, run anywhere” (တစ်ခါ ရေးပြီး ဘယ်နေရာမှာမဆို run) ကို ရပါတယ်: JVM install လုပ်ထားသရွေ့ .class file တစ်ခုတည်းက Windows, macOS ဒါမှမဟုတ် Linux ပေါ်မှာ run ပါတယ်။

Programming Fundamentals မှာ Java ကို ပထမဆုံး set up လုပ်တုန်းက ဒါကို လက်တွေ့ မြင်ခဲ့ပြီးပါပြီ: javac command က ကိုယ့် .java file တွေကို compile လုပ်ပြီး java command က bytecode ကို run ဖို့ JVM ကို စဖွင့်ပေးခဲ့ပါတယ်။


Translation နည်းလမ်း ရွေးချယ်ခြင်း: အခြေအနေ သုံးခု

IB syllabus က သတ်မှတ်ထားတဲ့ အခြေအနေတွေမှာ ဘယ် translation နည်းလမ်းက ကိုက်ညီလဲဆိုတာ evaluate လုပ်နိုင်ဖို့ တောင်းဆိုထားပါတယ်။ ဒီ အခြေအနေ သုံးခုကို စဉ်းစားကြည့်ပါ:

အခြေအနေ 1: အမြန် ရေးပြီး စမ်းသပ်ခြင်း

အသင့်တော်ဆုံး: Interpreter (ဒါမှမဟုတ် interpret လုပ်တဲ့ language)

မကြာခဏ ရေးပြီး စမ်းသပ်နေတဲ့အခါ edit-run cycle (code ပြင်၊ run ပြီး ရလဒ်ကြည့်တဲ့ အသွားအပြန်) က အရေးအကြီးဆုံးပါ။ Interpreter တွေက programmer ကို compile လုပ်တာ စောင့်စရာ မလိုဘဲ ပြင်လိုက်တာနဲ့ ရလဒ်ကို ချက်ချင်း မြင်ရစေပါတယ်။ Data scientist (ဒေတာ ခွဲခြမ်းစိတ်ဖြာသူ) တွေ Python ကို သုံးကြတာ ဒါကြောင့်ပါ: code အပိုင်းအစ (snippet) လေးတွေကို ချက်ချင်း တုံ့ပြန်တဲ့ (interactive) ပုံစံနဲ့ စမ်းပြီး ရလဒ်ကို line တစ်ကြောင်းချင်း ကြည့်နိုင်ပါတယ်။

လက်တွေ့ ဥပမာ: Instagram ရဲ့ backend (user မမြင်ရတဲ့ server ဘက်က အပိုင်း) ကို မူလက Python (Django framework) နဲ့ တည်ဆောက်ခဲ့ပါတယ်။ Python က interpret လုပ်တဲ့ language ဖြစ်လို့ အဖွဲ့ငယ်လေးက ကြာရှည်တဲ့ compile cycle တွေ မလိုဘဲ feature တွေကို prototype (စမ်းသပ် ပုံစံ) အမြန် လုပ်ပြီး user တွေရဲ့ အကြံပြုချက်အရ ထပ်ခါထပ်ခါ ပြင်နိုင်ခဲ့ပါတယ်: အစောပိုင်း အဆင့်မှာ run မြန်နှုန်းထက် ရေးတဲ့ မြန်နှုန်းက ပိုအရေးကြီးခဲ့ပါတယ်။

အခြေအနေ 2: စွမ်းဆောင်ရည် အရေးကြီးတဲ့ Application များ

အသင့်တော်ဆုံး: Compiler (ဒါမှမဟုတ် compile လုပ်တဲ့ language)

Run မြန်နှုန်းက ဦးစားပေး ဖြစ်တဲ့အခါ compile လုပ်ထားတဲ့ code က ပိုသာပါတယ်။ ဘာသာပြန်တာကို တစ်ခါပဲ လုပ်ပြီး ထွက်လာတဲ့ executable က ဘာသာပြန်ရတဲ့ overhead လုံးဝ မပါဘဲ native speed (processor ရဲ့ မူလ မြန်နှုန်း) နဲ့ run ပါတယ်။ Operating system တွေ၊ game engine (game တွေ တည်ဆောက်ဖို့ အခြေခံ software) တွေနဲ့ embedded system (စက်ထဲ ထည့်ထားတဲ့ ကွန်ပျူတာငယ်) တွေကို ပုံမှန်အားဖြင့် compile လုပ်တဲ့ language တွေနဲ့ ရေးကြပါတယ်။

လက်တွေ့ ဥပမာ: Linux kernel (operating system ရဲ့ အဓိက အစိတ်အပိုင်း) ကို C နဲ့ ရေးထားပြီး target platform တစ်ခုစီအတွက် compile လုပ်ပါတယ်။ Compile လုပ်ထားတဲ့ machine code က overhead အနည်းဆုံးနဲ့ run ပါတယ်၊ တစ်စက္ကန့်မှာ task ထောင်ချီကို ကိုင်တွယ်ရတဲ့ operating system အတွက် ဒါက မရှိမဖြစ် လိုအပ်ပါတယ်။

အခြေအနေ 3: Platform အမျိုးမျိုးအတွက် ရေးခြင်း

အသင့်တော်ဆုံး: Bytecode + Virtual Machine (hybrid နည်းလမ်း)

Program တစ်ခုတည်းကို platform အမျိုးမျိုးမှာ run ဖို့ လိုတဲ့အခါ bytecode ကို အခြေခံတဲ့ နည်းလမ်းက platform တစ်ခုစီအတွက် executable သီးခြားစီ compile လုပ်ရတာကို ရှောင်နိုင်ပါတယ်။ Bytecode က portable (တခြား platform တွေမှာ ပြောင်းသုံးနိုင်) ဖြစ်ပါတယ်၊ virtual machine ကပဲ platform-specific ဖြစ်ဖို့ လိုပါတယ်။

လက်တွေ့ ဥပမာ: Java application တွေက JVM ကနေတဆင့် Windows, macOS နဲ့ Linux ပေါ်မှာ run ပါတယ်။ Enterprise software (ကုမ္ပဏီကြီးတွေ သုံးတဲ့ software) တွေမှာ Java ကို မကြာခဏ သုံးကြတာ customer တစ်ယောက်ချင်းရဲ့ platform အတွက် ပြန် compile လုပ်စရာ မလိုလို့ပါပဲ။


အဆင့်ဆင့် ရှင်းပြထားတဲ့ ဥပမာများ

ဥပမာ 1: အခြေအနေနဲ့ ကိုက်တဲ့ Translation ကို ရွေးခြင်း

ပြဿနာ: Game studio တစ်ခုက frame (မျက်နှာပြင်ပေါ် ပြတဲ့ ပုံ တစ်ပုံ) တစ်ခုစီမှာ polygon (3D ပုံတွေကို တည်ဆောက်တဲ့ ပုံသဏ္ဌာန် အသေးလေးတွေ) သန်းချီကို 60 FPS (တစ်စက္ကန့်မှာ frame 60) နဲ့ process လုပ်ရမယ့် 3D game engine တစ်ခုကို တည်ဆောက်နေပါတယ်။ သူတို့ ဘယ် translation နည်းလမ်းကို သုံးသင့်သလဲ။ အဖြေကို အကြောင်းပြချက်နဲ့ ပြပါ။

အဖြေ ကြည့်ရန်

အဖြေ: သူတို့ compile လုပ်တဲ့ language (C++ လို) ကို သုံးသင့်ပါတယ်။ Game engine က စွမ်းဆောင်ရည် အရေးကြီးတဲ့ software ပါ: overhead အနည်းဆုံးနဲ့ ဖြစ်နိုင်သမျှ မြန်မြန် run ဖို့ လိုပါတယ်။ Compiler က code ကို native speed နဲ့ run တဲ့ optimize လုပ်ထားတဲ့ machine code အဖြစ် တစ်ခါ ဘာသာပြန်ပေးပါတယ်။ Interpreter ဆိုရင် frame တိုင်းမှာ ဘာသာပြန်ရတဲ့ overhead ထပ်ပေါင်းလာလို့ 60 FPS ကို မရနိုင်တော့ပါဘူး။ ပြင်ပြီးတိုင်း ပြန် compile လုပ်ရလို့ ရေးရတာ ပိုနှေးပေမယ့် နောက်ဆုံး ထုတ်ကုန်အတွက် run စွမ်းဆောင်ရည်က မရှိမဖြစ် လိုအပ်ပါတယ်။


ဥပမာ 2: Trade-off (တစ်ခု ရဖို့ တစ်ခု အလျှော့ပေးရတာ) တွေကို Evaluate လုပ်ခြင်း

ပြဿနာ: တက္ကသိုလ် တစ်ခုက operating system မတူတဲ့ (Windows, macOS, Linux) ကျောင်းသားတွေကို programming assignment အတူတူကို run စေချင်ပါတယ်။ သူတို့ compile လုပ်တဲ့ language၊ interpret လုပ်တဲ့ language ဒါမှမဟုတ် bytecode ကို အခြေခံတဲ့ language ထဲက ဘယ်ဟာကို သုံးသင့်လဲဆိုတာ evaluate လုပ်ပါ။

အဖြေ ကြည့်ရန်

အဖြေ:

  • Compiled (compile လုပ်တဲ့ language၊ ဥပမာ C): ကျောင်းသားတွေက OS တစ်ခုစီမှာ သီးခြားစီ compile လုပ်ရပါမယ်။ Compiler မတူရင် ရလဒ် မတူနိုင်ပါဘူး။ ဖြန့်ဝေတာနဲ့ set up လုပ်တာ ရှုပ်ထွေးပါတယ်။ သိပ် မသင့်တော်ပါ။
  • Interpreted (interpret လုပ်တဲ့ language၊ ဥပမာ Python): ကျောင်းသားတွေက ကိုယ့် OS မှာ Python interpreter ကို install လုပ်ပါတယ်။ .py file အတူတူက နေရာတိုင်းမှာ run ပါတယ်။ Set up လုပ်ရ လွယ်ပါတယ်။ ဒါပေမယ့် run တာ ပိုနှေးပါတယ်။ မြန်နှုန်း သိပ်မအရေးကြီးတဲ့ ပညာရေး ရည်ရွယ်ချက်အတွက် ကောင်းကောင်း ကိုက်ညီပါတယ်။
  • Bytecode + VM (ဥပမာ Java): ကျောင်းသားတွေက JVM ကို install လုပ်ပါတယ်။ .class file အတူတူက platform အားလုံးမှာ run ပါတယ်။ JIT ကြောင့် သက်သက် interpret လုပ်တာထက် ပိုမြန်ပါတယ်။ Set up လုပ်တာ Python ထက် ပိုရှုပ်ပါတယ်။ အထူးသဖြင့် စွမ်းဆောင်ရည် အရေးကြီးရင် ဒါလည်း ကောင်းကောင်း ကိုက်ညီပါတယ်။

အကြံပြုချက်: Interpreted (Python) ဒါမှမဟုတ် bytecode (Java) နှစ်ခုလုံး ကောင်းကောင်း အလုပ်ဖြစ်ပါတယ်။ သင်တန်းက set up လုပ်ရ လွယ်တာ (Python) ကို ဦးစားပေးလား၊ စွမ်းဆောင်ရည်နဲ့ လုပ်ငန်းခွင်မှာ အသုံးဝင်မှု (Java) ကို ဦးစားပေးလား ဆိုတာပေါ် မူတည်ပါတယ်။


ဥပမာ 3: Error ရှာပုံ နှိုင်းယှဉ်ချက်

ပြဿနာ: Programmer တစ်ယောက်က line 500 ပါတဲ့ program တစ်ခု ရေးထားပါတယ်။ Line 120 မှာ variable (တန်ဖိုး သိမ်းထားတဲ့ နာမည်ပေးထားတဲ့ နေရာ) နာမည် တစ်ခု စာလုံးပေါင်း မှားနေပြီး line 380 မှာလည်း နောက်ထပ် တစ်ခု မှားနေပါတယ်။ Compiler နဲ့ interpreter က ဒီ error တွေကို ဘယ်လို ကိုင်တွယ်မလဲဆိုတာ နှိုင်းယှဉ်ပါ။

အဖြေ ကြည့်ရန်

အဖြေ:

  • Compiler: Compiler က program မ run ခင် program တစ်ခုလုံးကို စစ်ပါတယ်။ Error နှစ်ခုလုံး (line 120 နဲ့ line 380) ကို တွေ့ပြီး error စာရင်း တစ်ခုထဲမှာ အတူတူ ပြပါတယ်။ Error နှစ်ခုလုံး ပြင်ပြီး code ကို ပြန် compile မလုပ်မချင်း program က လုံးဝ မ run ပါဘူး။
  • Interpreter: Program က line 1 ကနေ စ run ပါတယ်။ Line 1-119 က အောင်မြင်စွာ run ပါတယ်။ Interpreter က line 120 ကို ရောက်တဲ့အခါ ရပ်ပြီး ပထမ error ကို ပြပါတယ်။ Programmer က အဲဒါကို ပြင်ပြီး program ကို ပြန် run ပါတယ်။ ဒီတစ်ခါ line 1-379 run ပြီးမှ interpreter က line 380 မှာ ရပ်ပြီး ဒုတိယ error ကို ပြပါတယ်။ Error နှစ်ခုလုံးကို ရှာဖို့ သီးခြား run နှစ်ကြိမ် လိုပါတယ်။

အဓိက ကွာခြားချက်: Compiler က ဒီ error တွေကို တစ်ခေါက်တည်း စစ်တာနဲ့ ကြိုတင် ဖမ်းမိပါတယ်။ Interpreter ကတော့ run အကြိမ်ကြိမ်မှာ တစ်ခုချင်း ပြပါတယ်။

Syntax error အကြောင်း မှတ်ချက်: ဒီ နှိုင်းယှဉ်ချက်ကို syntax error တွေနဲ့ ရေးလေ့ ရှိပါတယ်။ Shell script (command တွေကို စုရေးထားတဲ့ script) လို တကယ်ပဲ တစ်ကြောင်းချင်း ဖတ်တဲ့ interpreter အတွက်ဆိုရင် အဲဒါ မှန်ပါတယ်။ Python ကတော့ မတူပါဘူး: Python က ဘာကိုမှ မ run ခင် file တစ်ခုလုံးရဲ့ syntax ကို အရင် စစ်တာမို့ line 120 မှာ syntax error ရှိရင် line 1 မ run ခင်ကတည်းက program ရပ်သွားပါတယ်။ Variable နာမည် စာလုံးပေါင်း မှားတာ ဒါမှမဟုတ် သုညနဲ့ စားတာလို program run နေစဉ်မှပဲ ပေါ်လာတဲ့ error တွေကတော့ အပေါ်မှာ ဖော်ပြထားတဲ့အတိုင်း အတိအကျ ဖြစ်ပါတယ်။


Quick Check (အမြန် စစ်ဆေးမေးခွန်း)

Q1. Compiler နဲ့ interpreter ကြားက အဓိက ကွာခြားချက်က ဘာလဲ။

Q2. JIT (Just-In-Time) compilation က ဘာလုပ်သလဲ။

Q3. Program တစ်ခုမှာ line 10 နဲ့ line 50 မှာ runtime error (program run နေစဉ် ဖြစ်တဲ့ error) တွေ ရှိပါတယ် (error တစ်ခုစီက သူ့ line run တဲ့အခါမှပဲ ပေါ်လာပါတယ်)။ Interpreter ကို သုံးရင် ဘာဖြစ်မလဲ။

Q4. Java ကို "write once, run anywhere" (တစ်ခါ ရေးပြီး ဘယ်နေရာမှာမဆို run) လို့ ဘာကြောင့် ပြောကြသလဲ။

Q5. Interpreter သုံးတာရဲ့ အားနည်းချက်က ဘယ်ဟာလဲ။

Q6. အမြန် ရေးပြီး စမ်းသပ်ဖို့ ဘယ် translation နည်းလမ်းက အသင့်တော်ဆုံးလဲ။


Translation Pipeline (ဘာသာပြန်တဲ့ အဆင့်ဆင့် လုပ်ငန်းစဉ်) ကို ဖြည့်ပါ

Java translation pipeline ရဲ့ ပျောက်နေတဲ့ အပိုင်းတွေကို ဖြည့်ပါ။ အဖြေတွေကို English စကားလုံးနဲ့ ရိုက်ထည့်ပါ။

အဆင့်InputTranslatorOutput
1. Compile-time (compile လုပ်ချိန်) HelloWorld.java (source code) (javac) (bytecode)
2. Run-time (run ချိန်) HelloWorld.class (bytecode) Program က ပေါ်မှာ run ပါတယ်

Spot the Error (အမှား ရှာခြင်း)

ဒီ Java program က နှုတ်ဆက်စာ နှစ်ကြောင်း print ထုတ်ရမှာ ဖြစ်ပေမယ့် compile မဖြစ်ပါဘူး။ အမှားပါတဲ့ line ကို ရွေးပါ၊ ပြီးရင် ပြင်နည်းကို ရွေးပါ။

1public class Greeter { 2 public static void main(String[] args) { 3 String name = "Alice" 4 System.out.println("Hello, " + name); 5 System.out.println("Welcome!"); 6 } 7}

ဒီ line အတွက် မှန်ကန်တဲ့ ပြင်နည်းကို ရွေးပါ:

ဒီ error ကို ဘယ်အချိန်မှာ တွေ့သလဲ။ Java က compiler ကို သုံးတာမို့ javac က ပျောက်နေတဲ့ semicolon ကို compile time မှာ ဖမ်းမိပါတယ်။ .class file ကို ဘယ်တော့မှ မထုတ်ပေးတာမို့ line 4 နဲ့ 5 က ဘယ်တော့မှ မ run ပါဘူး။ Interpreter ကို သုံးတဲ့ Python ကတော့ error တွေကို မတူတဲ့ ပုံစံနဲ့ ကိုင်တွယ်ပါတယ်: မသတ်မှတ်ရသေးတဲ့ variable တွေ ဒါမှမဟုတ် သုညနဲ့ စားတာလို runtime error တွေကို run နေစဉ်မှာပဲ တွေ့တာမို့ ပြဿနာ ရှိတဲ့ line မှာ interpreter မရပ်ခင် အရင်က မှန်ကန်တဲ့ line တွေ အရင် run ပါတယ်။


Fill in the Blanks (ကွက်လပ် ဖြည့်ခြင်း)

Translation လုပ်ငန်းစဉ်တွေအကြောင်း အောက်က ဖော်ပြချက်တွေကို ပြည့်စုံအောင် ဖြည့်ပါ။ စာကြောင်းတွေက English လို ဖြစ်လို့ ကွက်လပ်တွေကို English စကားလုံးနဲ့ ရိုက်ထည့်ပါ:

Translation Types
=================
A  translates the entire program before execution.
An  translates and executes one line at a time.

Java Translation Pipeline
=========================
javac compiles .java files into  (.class files).
The  executes bytecode on any platform.

Hybrid Translation
==================
Java compiles source code to bytecode first, then the JVM translates it further at .
This hybrid approach is called  (Just-In-Time) compilation.

စာကြောင်းတွေရဲ့ အဓိပ္ပာယ် (____ က ကွက်လပ်ပါ):
____ က program တစ်ခုလုံးကို run မလုပ်ခင် ဘာသာပြန်ပါတယ်။
____ က တစ်ကြောင်းချင်း ဘာသာပြန်ပြီး run ပါတယ်။
javac က .java file တွေကို ____ (.class file တွေ) အဖြစ် compile လုပ်ပါတယ်။
____ က ဘယ် platform ပေါ်မှာမဆို bytecode ကို run ပါတယ်။
Java က source code ကို bytecode အဖြစ် အရင် compile လုပ်ပြီးမှ JVM က ____ မှာ ထပ်ပြီး ဘာသာပြန်ပါတယ်။
ဒီ hybrid နည်းလမ်းကို ____ (Just-In-Time) compilation လို့ ခေါ်ပါတယ်။


အခြေအနေအလိုက် စစ်ဆေးမေးခွန်း

Q7. Bytecode ကို platform-independent လို့ ဘာကြောင့် ပြောကြသလဲ။

Q8. ကုမ္ပဏီ တစ်ခုက သူတို့ software ရဲ့ version တစ်ခုတည်းကို Windows, macOS နဲ့ Linux ပေါ်မှာ run စေချင်ပါတယ်။ ဘယ် နည်းလမ်းက ဒါကို အကောင်းဆုံး ထောက်ပံ့သလဲ။


Practice Exercises (လေ့ကျင့်ခန်းများ)

လေ့ကျင့်ခန်း တစ်ခုစီရဲ့ ရှေ့မှာ အဆင့် ([Core] စသဖြင့်)၊ ခေါင်းစဉ် link နဲ့ [4 marks] လို mark allocation (မေးခွန်း တစ်ခုစီအတွက် ပေးတဲ့ အမှတ်) ပါပါတယ်။ အမှတ်တွေက IB စာမေးပွဲ ပုံစံအတိုင်းပါ: IB သင်တန်း မတက်တဲ့သူတွေကတော့ အဖြေကို ဘယ်လောက် အသေးစိတ် ရေးရမလဲ ပြတဲ့ လမ်းညွှန်အဖြစ် သုံးနိုင်ပါတယ်။

Core (အခြေခံ အဆင့်)

  1. [Core] Translation methods [4 marks] Compiler နဲ့ interpreter ကြားက ကွာခြားချက် နှစ်ခုကို State (ဖော်ပြပါ) လုပ်ပါ။ ကွာခြားချက် တစ်ခုစီအတွက် ဘယ်နည်းလမ်းက ပိုကောင်းလဲ၊ ဘာကြောင့်လဲဆိုတာ ရှင်းပြပါ။

  2. [Core] Translation methods [6 marks] အခြေအနေ တစ်ခုစီအတွက် compiler၊ interpreter ဒါမှမဟုတ် bytecode+VM နည်းလမ်း ထဲက ဘယ်ဟာက အသင့်တော်ဆုံးလဲဆိုတာ state လုပ်ပါ။ အဖြေ တစ်ခုစီကို အကြောင်းပြချက်နဲ့ ပြပါ:
    • Server software အတူတူကို Windows နဲ့ Linux စက်တွေပေါ်မှာ တင်သုံးမယ့် ဘဏ် တစ်ခု
    • Code အတိုလေးတွေကို မြန်မြန် စမ်းချင်တဲ့ code ရေးနည်း လေ့လာနေတဲ့ ကျောင်းသား တစ်ယောက်
    • Run မြန်နှုန်း အလွန် အရေးကြီးတဲ့ ဆေးဘက်ဆိုင်ရာ စက်ပစ္စည်း တစ်ခုအတွက် firmware (စက်ပစ္စည်းထဲမှာ ထည့်ထားတဲ့ software) ရေးနေတဲ့ ကုမ္ပဏီ တစ်ခု
  3. [Core] JIT and bytecode (HL) [4 marks] .java file ကနေ program output အထိ Java translation ရဲ့ အဆင့်တွေကို ပြတဲ့ diagram တစ်ခုကို Draw (ပုံ ဆွဲပြပါ) လုပ်ပါ။ အဆင့်တိုင်းကို label တပ်ပြီး အဲဒီ အဆင့်ကို လုပ်ပေးတဲ့ tool ဒါမှမဟုတ် အစိတ်အပိုင်းရဲ့ နာမည်ကို ရေးပါ။

Extension (တိုးချဲ့ အဆင့်)

  1. [Extension] JIT and bytecode (HL) [4 marks] JIT compilation က compilation နဲ့ interpretation ကြားမှာ “the best of both worlds” (နှစ်ဘက်လုံးရဲ့ အကောင်းဆုံး) ကို ဘယ်လို ပေးဖို့ ရည်ရွယ်လဲဆိုတာ Explain (ရှင်းပြပါ) လုပ်ပါ။ သက်သက် compile လုပ်တာနဲ့ နှိုင်းယှဉ်ရင် trade-off တွေက ဘာတွေလဲ။

  2. [Extension] Translation methods [6 marks] Line 200 ပါတဲ့ program တစ်ခုက line 50 မှာ variable နာမည် တစ်ခုကို စာလုံးပေါင်း မှားရေးထားပြီး line 150 မှာလည်း အဲဒီလိုပဲ ထပ်မှားထားပါတယ်။ Compiler နဲ့ interpreter က ဒီ error တွေကို ဘယ်လို ကိုင်တွယ်မလဲဆိုတာ Compare and contrast (နှစ်ခုလုံးကို တစ်လျှောက်လုံး ထည့်ပြီး တူတာတွေနဲ့ ကွာတာတွေကို ဖော်ပြပါ) လုပ်ပါ။ ဘယ်နည်းလမ်းက programmer ကို code ပိုထိထိရောက်ရောက် ပြင်နိုင်အောင် ကူညီမလဲ။ အဖြေကို အကြောင်းပြချက်နဲ့ ပြပါ။

  3. [Extension] Translation evaluation [9 marks] ကုမ္ပဏီ တစ်ခုက Windows အတွက် compile လုပ်ထားတဲ့ C++ executable တွေကို ဖြန့်ဝေပါတယ်။ အခု macOS နဲ့ Linux ကိုပါ ထောက်ပံ့ချင်ပါတယ်။ ဖြစ်နိုင်တဲ့ ဖြေရှင်းနည်း သုံးခုကို Evaluate (အားသာချက်နဲ့ အားနည်းချက်တွေကို ချိန်ဆပြီး အကဲဖြတ်ပါ) လုပ်ပါ: (a) platform တစ်ခုစီအတွက် သီးခြားစီ compile လုပ်ခြင်း၊ (b) Python နဲ့ ပြန်ရေးခြင်း၊ (c) Java နဲ့ ပြန်ရေးခြင်း။ နည်းလမ်း တစ်ခုစီရဲ့ trade-off တွေကို Discuss (အချက်တွေ၊ အမြင်တွေကို ဘက်စုံ ချိန်ဆပြီး ဆွေးနွေးပါ) လုပ်ပါ။

Challenge (စိန်ခေါ်မှု အဆင့်)

  1. [Challenge] Translation evaluation [9 marks] Translation နည်းလမ်း တစ်ခုစီကို သုံးတဲ့ တကယ့် programming language တစ်ခုစီကို ရှာဖွေလေ့လာပါ: (a) သက်သက် compile လုပ်တဲ့ language၊ (b) သက်သက် interpret လုပ်တဲ့ language၊ (c) bytecode + JIT သုံးတဲ့ language။ တစ်ခုစီအတွက် translation နည်းလမ်းက အဲဒီ language ရဲ့ ပုံမှန် အသုံးပြုပုံ၊ စွမ်းဆောင်ရည် လက္ခဏာတွေနဲ့ developer experience (code ရေးသူရဲ့ အတွေ့အကြုံ) ကို ဘယ်လို လွှမ်းမိုးလဲဆိုတာ explain လုပ်ပါ။

  2. [Challenge] Translation evaluation [9 marks] “ခေတ်သစ် language တွေကြောင့် compiler နဲ့ interpreter ကို ခွဲခြားတာ အသုံးမဝင်တော့ဘူး။” ဆိုတဲ့ ပြောဆိုချက်ကို Evaluate လုပ်ပါ။ ဘယ်အတိုင်းအတာအထိ သဘောတူသလဲ။ အဖြေမှာ JIT compilation၊ bytecode interpreter တွေနဲ့ language implementation (language ကို တကယ် run အောင် တည်ဆောက်ထားတဲ့ software) တစ်ခုချင်းကို တိတိကျကျ ကိုးကားပါ။


ဆက်စပ် ခေါင်းစဉ်များ

  • သိပြီးသား အကြောင်းအရာ: Programming Fundamentals မှာ Java source code ကို bytecode အဖြစ် compile လုပ်ဖို့ javac ကို သုံးခဲ့ပြီး run ဖို့ JVM ကို သုံးခဲ့ပါတယ်: ဒါက bytecode + VM နည်းလမ်းကို လက်တွေ့ သုံးတာပါ
  • ဆက်စပ် ခေါင်းစဉ်: CPU Architecture: translator တွေ နောက်ဆုံးမှာ ထုတ်ပေးတဲ့ native machine code ကို CPU က run ပါတယ်။ CPU architecture မတူရင် machine code လည်း မတူဖို့ လိုတာမို့ portability က အရေးကြီးပါတယ်
  • ဆက်စပ် ခေါင်းစဉ်: OS Fundamentals: operating system က ဘာသာပြန်ပြီးသား program တွေ run တာကို စီမံပါတယ်၊ executable တွေကို memory ထဲ ထည့်ပြီး CPU အတွက် scheduling (ဘယ် process ကို CPU အချိန် ပေးမလဲ ဆုံးဖြတ်ခြင်း) လုပ်ပေးပါတယ်
  • နောက်ထပ် လေ့လာမယ့် ခေါင်းစဉ်: Debugging (Programming Fundamentals: Debugging): error တွေကို ဘယ်အချိန်မှာ တွေ့လဲ (compile-time နဲ့ runtime) ဆိုတာ နားလည်တာက compiler နဲ့ interpreter တွေ error တွေကို မတူတဲ့ ပုံစံနဲ့ ကိုင်တွယ်ပုံနဲ့ တိုက်ရိုက် ဆက်စပ်ပါတယ်

© EduCS.me. ကွန်ပျူတာသိပ္ပံ ပညာရေးအတွက် အရင်းအမြစ်တွေ စုထားတဲ့ နေရာပါ။ EduCS is an independent educational resource. It is not affiliated with, or endorsed by, the International Baccalaureate Organization. (EduCS ဟာ သီးခြား ပညာရေး အရင်းအမြစ်တစ်ခုပါ။ International Baccalaureate Organization နဲ့ ဆက်စပ်မှု မရှိသလို သူတို့ရဲ့ ထောက်ခံချက်လည်း မရှိပါဘူး။) ဆက်သွယ်ရန်