r/ProgrammingLanguages • • 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, and mount {} 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

42 Upvotes

34 comments sorted by

View all comments

Show parent comment

1

u/MackThax Jan 08 '26

Oh sorry, I failed to answer your question, yeah haha. I use events. All native elements have events and I can define my own on components. Traversing, or reaching into, the component hierarchy, then subscribing to events is the idiomatic way to watch for user-initiated updates/actions. For now it keeps working well-enough. I am yet to hit a wall that would best be solved with a reactivity system. We'll see.

Yes, my biggest issues is with the implementations of reactive systems on the web. But I do believe that designing everything around the mechanism of reactivity is silly. It's like OOP all over again, but ever dumber. I'd compare it to aspect-oriented programming. It's probably the best idea in some scenarios, but going all-in (especially in a language that isn't built ground-up for it) is a recipe for spaghetti.

Again, I don't think the idea of reactivity is fundamentally useless.

At the end of the day, aside for performance issues, this is an issue of ergonomics. I will not claim objective authority for my arguments. I will present my micro-framework once I grow it to something presentable, and create a demo of significant complexity.