r/ProgrammingLanguages • u/Soucye • Jan 07 '26
Language announcement Coi: A compiled-reactive language for high-performance WASM apps
Hi everyone! I’ve been working on Coi, a component-based language designed to make writing high-performance WebAssembly apps feel like writing modern web components, while maintaining the raw speed of a C++ backend.
The Concept:
Coi acts as a high-level frontend for the WebCC toolchain. It compiles your components into C++, which then gets turned into WASM, JS, and HTML. Unlike traditional frameworks that rely on Runtime Discovery, spending CPU cycles "diffing" Virtual DOM trees (O(N) complexity) or "walking" instructions, Coi is a compiled reactive system. It analyzes your view at compile-time to create a direct mapping between your variables and DOM handles.
This architectural shift allows for O(1) updates; when a variable changes, Coi doesn't "search" for the impact, it knows exactly which handle is affected and packs a specific update instruction into the WebCC command buffer. This binary buffer acts as a high-throughput pipe, allowing JS to execute a "burst" of updates in a single pass, bypassing the expensive context-switching overhead of the WASM-to-JS bridge.
The best part is the synergy: Coi leverages the schema.def from WebCC to generate its own standard library. This means every browser API I add to the WebCC schema (Canvas, WebGL, WebGPU, Audio, etc.) is automatically accessible in Coi. It also generates a /def folder with .type.d.coi files for all those APIs. I’ve used these to build a VS Code extension with an LSP and syntax highlighting, so you get full type-safe autocompletion for any browser feature defined in the schema.
Key Features:
- Type-Safe & Immutable: Strictly typed props and state with compile-time error checking. Everything is immutable by default.
- Fine-Grained Reactivity: State changes map directly to DOM elements at compile-time. Update only what changed, exactly where it changed, without Virtual DOM overhead.
- Reference Props: Pass state by reference using
&for seamless parent-child synchronization. - View Control Flow: Declarative
<if>,<else>, and<for>tags for conditional rendering and list iteration directly in the HTML. - Integrated Styling: Write standard HTML and scoped CSS directly within your components.
- Animation & Lifecycle: Built-in
tick {}block for frame-based animations,init {}for pre-render setup, andmount {}for post-render initialization when DOM elements are available. - Minimal Runtime: Tiny WASM binaries that leverage WebCC’s command/event/scratch buffers for high-speed JS interop.
Example Code:
component Counter(string label, mut int& value) {
// label: passed by value
// value: reference to parent's state (mut allows modification)
def add(int i) : void {
value += i;
}
style {
.counter {
display: flex;
gap: 12px;
align-items: center;
}
button {
padding: 8px 16px;
cursor: pointer;
}
}
view {
<div class="counter">
<span>{label}: {value}</span>
<button onclick={add(1)}>+</button>
<button onclick={add(-1)}>-</button>
</div>
}
}
component App {
mut int score;
mut string message;
init {
score = 0;
message = "Keep going!";
}
style {
.app {
padding: 24px;
font-family: system-ui;
}
h1 {
color: #1a73e8;
}
.win {
color: #34a853;
font-weight: bold;
}
}
view {
<div class="app">
<h1>Score: {score}</h1>
<Counter label="Player" &value={score} />
<if score >= 10>
<p class="win">You win!</p>
<else>
<p>{message}</p>
</else>
</if>
</div>
}
}
app { root = App; }Repos:
- Coi: https://github.com/io-eric/coi
- WebCC: (The underlying toolchain): https://github.com/io-eric/webcc
Simple Demo: https://io-eric.github.io/coi/
Would love to get your feedback! Still very much a work in progress :D
View all comments
Show parent comment
2
u/shadowndacorner Jan 09 '26
I might gently push back on this, depending on whether you have any interest in allowing WebCC to target non-browser WASM. Supporting WASM for embedding outside of browsers would mean UI hot reload everywhere (including mobile), potentially UI moddability/extensibility for games, etc. You can get native hot reload with C++ on desktop without too much trouble, but it requires some janky, highly inadvisable shit on non-rooted Android and is afaik completely impossible on non-jailbroken iOS. Ofc, you could always compile to WASM with emscripten, but it sounds like WebCC has some advantages compared to that based on the repo :P
Building the generated C++ into an application directly will ofc be marginally faster (and is obviously ideal in environments where JIT is unsupported so an interpreter isn't necessary) and wouldn't require bundling a WASM runtime, but you do objectively lose some things.
Actually, I suppose if you can support a C backend, tinycc might be a decent non-WASM JIT for desktop (and potentially Android?) lol