StarLang
StarLang is a tiny, statically typed, event-driven language and VM for embedded orchestration. It runs on ESP32 and PC with the same bytecode — no OS, no heap fragmentation, no runaway scripts.
What It Does
StarLang scripts orchestrate hardware and network I/O on microcontrollers. Connect to MQTT brokers, handle WebSocket streams, read sensors on timers, react to events — all in a bounded, garbage-collected VM that the host firmware controls.
package main
import "mqtt"
event MqttConnected { conn: i32 }
event MqttMessage { topic: string, payload: string }
fn main(): void {
var conn: i32 = mqtt.open("192.168.1.10", 1883, "sensor-01")
mqtt.on(conn, "connected", MqttConnected)
mqtt.on(conn, "message", MqttMessage)
on MqttConnected fn(e: MqttConnected): void {
mqtt.subscribe(e.conn, "commands/#", 0)
}
on MqttMessage fn(e: MqttMessage): void {
console.log(e.payload)
}
runtime.keepAlive()
}
Design Principles
- Event-driven, not polling —
onhandlers fire when data arrives, zero CPU while idle - Code can die, VM must not — runtime guards (opcode budget, heap limit, event storm) kill scripts cleanly; firmware stays up
- Host owns the floor — guard limits set by firmware are immutable from script; scripts can tighten, never loosen
- No filesystem, no threads, no dynamic loading — scripts are pure computation + I/O events
- Same bytecode, two targets — compile once, run on PC for development, deploy to ESP32 for production
Architecture
| Layer | Role |
|---|---|
| Compiler | Single-pass, static types, emits bytecode + debug info |
| VM | Stack-based, mark-and-sweep GC, cooperative tasks, event loop |
| Native modules | C libraries (mqtt, ws, json, crypto, ...) called via OP_NATIVE_CALL |
| Guards | Opcode budget, heap limit, event storm — enforced in release mode |
| HAL | Platform abstraction — same script on PC and ESP32 |
Status
| Component | Status |
|---|---|
| Compiler | Done |
| VM | Done |
| Event system | Done |
| Runtime guards | Done |
| Concurrency (go/chan/select) | Done |
| Native modules (mqtt, ws, json, crypto, config, ...) | Done |
| Language Server (LSP) | Done |
| DAP Debugger | Done |
| HAL (ESP32) | In Progress |