Demos

Real programs, not just snippets

The tour shows the language one feature at a time. nlvm-demos is a companion repository of small, complete, runnable NL programs — clone it, build with nlc, run with nlvm.

$ git clone https://github.com/nlvm-lang/nlvm-demos
$ cd nlvm-demos/01_hello_world && make

06 · Flagship demo

A multi-threaded HTTP server

One OS thread per connection, via system.thread.Thread — requests are handled in parallel, not queued behind each other. Shared state (a request counter, a connection counter) lives on one Server instance and is guarded by a system.thread.Mutex, because every worker thread shares the same heap object.

The served page polls /api/stats for a live request count, and has a "fire 5 parallel requests" button that hits a deliberately slow endpoint five times via Promise.all. On a single-threaded server that's ~3 s; here it's ~600 ms, because five threads sleep at once instead of one thread sleeping five times — parallelism you can watch happen in a browser tab.

Browse the source →

public void handle(system.net.TcpStream stream,
                    int connId) {
    try {
        byte[] buf = new byte[8192];
        int n = stream.read(buf, 0, buf.length());
        string request =
            system.text.Encoding.decodeUtf8(buf.slice(0, n));
        string[] parts = request.split("\r\n")[0].split(" ");
        string path = parts[1];
        int count = this.recordRequest(); // mutex-guarded

        if (path == "/api/work") {
            // proves requests run in parallel, not queued
            system.thread.Thread.sleep(600);
            this.sendResponse(stream, 200, "OK",
                "application/json; charset=utf-8",
                "{\"worker\": " + connId + "}");
        }
        // ...whitelist-routed static files below
        stream.close();
    } catch (Exception ex) {
        system.Err.println("[worker " + connId + "] " + ex.message);
        stream.close();
    }
}

01 – 05

The rest of the set

Five smaller programs, each isolating one corner of the language.

Run one yourself

Every demo assumes nlc/nlvm are already built — see Get started if you haven't.