Kompilasi Native Binary Phase 6
NusaScript dapat dikompilasi menjadi binary native yang berdiri sendiri — tidak butuh runtime, tidak butuh instalasi apapun di server tujuan.
Interpreter vs Compiler
| Mode | Perintah | Cocok untuk | Kecepatan |
|---|---|---|---|
| 🔄 Interpreter | nusa jalankan app.ns | Development / testing | Standar |
| ⚡ Compiler | nusa kompilasi app.ns | Production / deployment | ~10x lebih cepat! |
Menggunakan Compiler
Terminal
// Kompilasi dengan nama output otomatis (sama dengan nama file)
nusa kompilasi program.ns
// Menghasilkan binary: ./program
// Kompilasi dengan nama output kustom
nusa kompilasi program.ns -o nama_binary
// Menghasilkan binary: ./nama_binary
// Jalankan binary hasil kompilasi
./program
// Deploy ke server — binary berdiri sendiri!
scp program user@server.com:/app/
ssh user@server.com "./app/program"
Proses Kompilasi (4 Langkah)
Output saat kompilasi
⚙ NusaScript Compiler Phase 6
api.ns → native binary
[1/4] Parsing NusaScript...
✓ Parse berhasil
[2/4] Generating Go source...
✓ Source Go berhasil di-generate (29.8 KB)
[3/4] Download dependencies...
✓ Dependencies siap
[4/4] Compiling ke native binary...
✅ Kompilasi berhasil!
Output: ./api (14.0 MB)
Jalankan dengan: ./api
Bagaimana cara kerjanya?
NusaScript → Transpiler → Go source code →
NusaScript → Transpiler → Go source code →
go build → Native binary ARM64/x86-64
Keuntungan Native Binary
| Aspek | Interpreter | Native Binary |
|---|---|---|
| Startup time | ~50ms | <1ms |
| Throughput API | ~5,000 req/s | ~50,000 req/s |
| Memori | Lebih besar | Lebih hemat |
Butuh nusa di server? | Ya | Tidak! |
| Portabilitas | Butuh runtime | Binary standalone |
Contoh: Kompilasi REST API
Terminal — Production Deployment
// 1. Kompilasi
nusa kompilasi contoh/crud_api.ns -o api_server
// 2. Test lokal
./api_server
// 3. Deploy ke server Linux (cross-compile)
GOOS=linux GOARCH=amd64 nusa kompilasi crud_api.ns -o api_linux
// 4. Upload dan jalankan
scp api_linux user@vps.server.com:/var/www/app/
ssh user@vps.server.com "chmod +x /var/www/app/api_linux && /var/www/app/api_linux"
Binary yang dihasilkan bersifat self-contained — tidak memerlukan Go, NusaScript, atau library apapun di server tujuan. Cukup upload binary-nya saja!