Klang is the compiler and runtime for K, a statically typed, native-compiled systems programming language with C/C++-inspired syntax.
Status: Working draft. K and its tooling are under active development.
K combines explicit types, value-oriented aggregates, object-oriented
programming, deterministic resource management, templates, and compilation to
native code through LLVM. Its compiler driver is klangc; the repository also
contains libk, the K standard library, and libkdi, the metadata format and
tooling used for inter-module APIs.
module hello;
main() : int {
k::io::stdout.println("Hello, K!");
return 0;
}The base standard library is compiler-managed, so k::io is available without
an explicit import k;.
Configure and build the project:
cmake -S . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug
cmake --build cmake-build-debugCompile and run a K source file:
./cmake-build-debug/klang/klangc hello.k -o hello
./helloTo compile the included sample:
./cmake-build-debug/klang/klangc samples/fibo.k -o fibo
./fiboklangc also produces object files (-c), shared libraries (--dyn-lib),
static libraries (--static-lib), and KDI interface descriptors for
libraries. See the compiler manual and the
CMake integration guide for
library builds, imports, linker paths, and external projects.
Building Klang requires:
- CMake 3.17 or newer
- A C++20 compiler and a C/C++ linker toolchain
- LLVM development files discoverable by CMake
pkg-configandlibcbor- Catch2, nlohmann_json, fmt, and Boost (components: program_options, system, filesystem)
On Linux, liburing is optional. When available, asynchronous I/O in libk
uses io_uring; otherwise it uses the POSIX fallback.
- Learn K — progressive tutorials from a first program through modules and templates
- Subsystem guides — in-depth technical guides (Date and Time, ...)
- Language reference — complete language rules and grammar
- Standard library reference — public
libkAPIs - How-to guides — CMake integration and debugging
- Compiler manual —
klangccommand-line options
| Path | Contents |
|---|---|
klang/ |
K compiler implementation and compiler tests |
libk/ |
K standard library and native runtime support |
libkdi/ |
KDI descriptors, codecs, and tools |
doc/ |
Tutorials, language and KDI specifications, manuals, and guides |
samples/ |
Small K programs |
After building, run the test suite from the build directory:
cd cmake-build-debug
ctest --output-on-failureContributions are welcome. Please keep changes focused, add regression tests for behavioral fixes, and update the relevant documentation when changing K, the standard library, or KDI behavior. Open an issue to discuss substantial design changes before implementing them.
Klang is licensed under the Apache License, Version 2.0.