A small, typed language for games and microcontrollers.
Readable like a scripting language, predictable like a systems one.
Lyn is in early development.
It's closed and invite-only for now, and will become open source once it is
bootstrapped, meaning once Lyn is compiled by a compiler written in Lyn.
Until then it's a proof of concept: a hobby project and a recreational language.
What is Lyn?
Lyn is a statically typed language that runs on a small virtual machine written in portable C. The same script can drive a game, run as a mod inside someone else's program, or control a microcontroller with a few kilobytes of RAM.
import "std.math"
enum Vent {
closed
open(fixed)
}
struct Greenhouse {
name: string
temp: fixed = 21.0
vent: Vent = Vent.closed
}
fn update(g: Greenhouse) {
if g.temp > 28.0 {
g.vent = Vent.open(math.clamp(g.temp - 28.0, 0.0, 1.0))
}
print("{g.name}: {g.temp}°C, vent {g.vent}")
}
east = Greenhouse{ name: "east", temp: 28.5 }
update(east) // east: 28.5°C, vent open(0.5)
What Lyn offers
The language
- Static types, light syntax. Types are inferred where obvious (
hp = 100) and written where they help. - No surprise nulls. Optionals (
string?) with?.and??; errors are values withResult,tryandmatch. - Enums with payloads that match, compare and print properly:
open(0.5), not1. - Fixed-point numbers built in.
fixedandfixed32for microcontrollers without a floating-point unit. - Fixed-size arrays like
[u16; 32]that never touch the heap. - Mistakes stop, not corrupt. Integer overflow and out-of-bounds access fault with the exact line instead of wrapping silently.
- Readable errors. Compiler messages point at the code and suggest a fix, and can also be output as JSON for editors.
Memory and runtime
- A precise garbage collector. Mark-and-sweep, non-moving, and exact about which stack slots hold references, because the bytecode verifier works it out before a program runs. That made values 44% smaller on the stack and 6–11% faster than tagging them.
- Scope blocks. Temporary strings made inside
scope { }are freed together when it ends, and the compiler checks that none of them escape. - Budgets per script. Memory and instruction limits for each VM. An infinite loop gets paused, and running out of memory stops that script, not the program around it.
- Sandboxed by default. Bytecode is verified when it loads, and scripts only reach the files, network or hardware the host grants.
- Tiny and portable. The VM is plain C99, runs without a C library, and fits a Cortex-M0+ in about 56 KB.
- Easy to embed. A small C API to load scripts, call functions and expose your own; usable from C, C++, Zig, Rust or anything with C interop.
On the way
lyn testto run thetestblocks that sit next to your code, withreplaceto fake hardware, andlyn fmt.- A strict memory mode for firmware that rules out the garbage collector after start-up.
- Two real programs to prove it: a small game with raylib, and firmware on a Raspberry Pi Pico.
- A compiler written in Lyn, which is when Lyn becomes open source.
Following along
Progress is written up in the devlog, and small programs end up in the showcase. If you'd like to try Lyn early, write to hello@lynlang.org.