Knot is a small numerical language — part of knotkit, a compiler kit written in Rust. Every value is a float or an array; the syntax reads like pseudocode. There is no server: the entire compiler is compiled to WebAssembly and runs in this tab.
What just happened
The knot crate is compiled to a single WebAssembly module
(knot.wasm) that exports two entry points. Run
calls a tree-walking interpreter that evaluates your Knot directly — the same
lexer and parser the real compiler uses, with an evaluator on top, so what
you run is parsed exactly as the compiler sees it. Generated
C calls the actual knotkit C backend and hands back the C99 your
program lowers to. One source, two lowerings, both inside the wasm. The
red squiggles are real too: every pause in typing runs the compiler and maps
its diagnostics (file:line:col plus caret span) onto the editor.
Figures are a one-word convention: show any array and the
IDE plots it; show a scalar and it lands in the workspace strip.
No plotting library in the language — the convention is the API.
This is the other half of the
run-a-real-SCF-in-the-browser
page. There, a single large Knot program — a full Hartree-Fock calculation —
is compiled the canonical way (knot → C → emscripten → wasm),
ahead of time, and the page just runs the result. Here, the compiler
itself is the wasm, so you can throw arbitrary Knot at it live.
What runs, and what to compile
The interpreter covers the core language: numbers, arithmetic, comparisons,
if / while / for, functions and
recursion, print / show, dense arrays
(zeros, indexing, len, elementwise math), and the
libm builtins (sqrt, exp, sin,
cos, …). The heavier scientific machinery — records,
closures, and the higher-order numerics like eig_sym and
simpson — isn't interpreted yet, but Generated
C handles the entire language, so you can always see (and, offline,
compile) what any program lowers to. The interpreter grows from here.
Browse the example programs as annotated source at /code/knot-examples.