A native ahead-of-time (AOT) and JIT compiler for TypeScript, built on LLVM/MLIR.
It compiles .ts files directly to native executables, shared libraries and WebAssembly, or runs
them on the fly via a built-in JIT — no Node.js or JavaScript runtime required.
Targets: Windows, Linux, Android (arm64-v8a, armeabi-v7a, x86_64), WebAssembly (wasm32, wasm64).
- Quick start
- Memory models
- GPU kernels
- Documentation
- Showcase: native_ts_graphics
- Community · License · Contributing
Download tslang from Releases,
or try it on Compiler Explorer.
File hello.ts:
function main() {
print("Hello World!");
}Run it with the JIT:
tslang hello.tsOr compile it to an executable (on Linux add --relocation-model=pic):
tslang --emit=exe hello.ts
hello.exeHello World!
Start a new project:
tslang --new Test1creates a Visual Studio Code project, and
tslang --cmake Test1a CMake project for mixed C++/TypeScript (see What's new for building it).
More in Running and compiling programs: a larger example, the JIT cache, debugging JIT code with GDB, and the environment variables the linker uses.
How heap memory is managed is selected with -mm=:
| flag | ||
|---|---|---|
-mm=gc |
garbage collection (Boehm) | the default |
-mm=rc |
reference counting - freed as soon as the last reference goes, no collector, no libgc |
does not collect reference cycles |
-mm=none |
nothing is ever freed | short-lived programs |
-mm=own |
single ownership inferred at compile time, like Rust's borrow checker - no collector, no counting | in development; ownership that cannot be proven is a compile error |
See memory-models.md and the -mm=own guide.
-mm=own is Rust-style ownership: the compiler decides at compile time where each object is freed,
so a program runs with no collector and no reference counts, and its speed is close to Rust's
(release builds, ms, lower is better):
| benchmark | -mm=own |
Rust | C++ (clang -O3) |
|---|---|---|---|
ray tracer, classes and switch (Rust: enums and match; Linux) |
50 | 50 | |
| ray tracer, interfaces and closures (Rust: plain values; Windows) | 76 | 56 | 52 |
| array loops: matmul / hash (Linux) | 26.7 / 48.0 | 20.6 / 44.4 | 30.1 / 42.8 |
Written with every object in an Rc (a shared_ptr in C++), as code that shares objects freely must be,
the interface ray tracer takes 500 ms in Rust and 834 ms in C++. The details, the machines and the
other models are in Performance.
A function marked @gpu or @kernel runs on the GPU, one thread per index, on NVIDIA, AMD and Intel GPUs,
both from executables and from the JIT. No GPU SDK is needed to compile or to run: the program loads
the GPU's driver itself.
@gpu
function add(i: int, a: number[], b: number[], c: number[]) {
c[i] = a[i] + b[i];
}
function main() {
const a = [1.0, 2.0, 3.0];
const b = [10.0, 20.0, 30.0];
const c = [0.0, 0.0, 0.0];
add(3, a, b, c);
console.log(c); // [ 11.0, 22.0, 33.0 ]
}The interface ray tracer above, one GPU thread per pixel (rtbench_gpu.ts), renders 512x512 in 1.9 ms on an RTX 5080. See
GPU kernels for gpuMap/gpuReduce/gpuSort, shared memory, atomics and more.
| Topic | Page |
|---|---|
| Running with the JIT, compiling executables, debugging JIT code | docs/running.md |
| Android: cross-compiling and building the runtime libraries | docs/android.md |
| WebAssembly | docs/wasm.md |
Memory models (gc, rc, none) |
docs/memory-models.md |
The -mm=own single-owner model |
docs/own-memory-model.md |
How ready -mm=own is |
docs/own-readiness.md |
| Benchmarks against Rust and C++ | docs/performance.md |
C and C++ bindings with tsbindgen |
docs/tsbindgen.md |
Calling C++ classes (@cpp) |
docs/cpp-classes.md |
JSX in .tsx files: elements as calls of your own factory |
docs/jsx.md |
GPU kernels (@kernel, gpuLaunch) on NVIDIA, AMD and Intel GPUs |
docs/gpu.md |
| Building the compiler from source | docs/building.md |
| What's new and roadmap | docs/whats-new.md |
| JavaScript built-in objects library | Default Library repo |
| How-to guides and more | Wiki |
native_ts_graphics is a set of 25
real-time 3D graphics samples — TypeScript ports of NVIDIA's Donut
samples on Direct3D 12 and Vulkan, from basic_triangle to ray tracing, meshlets and work
graphs — compiled to native code with tslang. .ts files are a first-class CMake language
(TSLANG) linked with the C++ framework through a C interop layer, and the samples run on
Windows and Android.
- GitHub Discussions (preferred)
(legacy)
This project is licensed under the MIT License — see the LICENSE file for details.
Issues and pull requests are welcome. See the Wiki for documentation, build notes, and how-to guides.
