English | 简体中文
KCP is a compiler project for the KCP programming language. The repository contains the language design, frontend, semantic analysis, IR and LLVM lowering, runtime support, standard library, examples, documentation, and CLion integration.
The compiler is organized as a staged native-code toolchain:
source,preprocessor, andlexerpreserve source locations and produce diagnostics-friendly token streams.parserbuilds the KCP syntax tree from modules, declarations, statements, expressions, and types.semanticresolves names, checks types, instantiates generics, validates concepts, and lowers language rules into typed compiler state.codegentranslates checked programs through IR and LLVM.runtimedefines the ABI surface used by generated programs.stdprovides the first standard library modules written in KCP.
The project also includes a documentation site, runnable examples, regression tests, and an IntelliJ/CLion language plugin.
KCP publishes Linux packages and a CLion language plugin from tagged releases. The current release page is:
https://github.com/kkkzbh/KCP/releases/tag/0.1.0
The compiler package installs:
/usr/bin/kcp/usr/lib/kcp/libcp_runtime.a/usr/lib/kcp/std
The installed compiler is configured to find the packaged runtime and standard library automatically. Generated binaries still use clang for object generation and linking, so install clang if your package manager does not pull it in.
Use the Fedora repository:
sudo curl -L -o /etc/yum.repos.d/kcp.repo \
https://raw.githubusercontent.com/kkkzbh/KCP/master/docs/install/kcp-fedora.repo
sudo dnf install kcpOr install the RPM directly from a release:
sudo dnf install ./kcp-0.1.0-1.fc44.x86_64.rpmDownload the .deb from the release page, then install it:
sudo apt install ./kcp_0.1.0-1_amd64.debDownload the pacman package from the release page, then install it:
sudo pacman -U ./kcp-0.1.0-1-x86_64.pkg.tar.zstThe plugin is available on JetBrains Marketplace:
https://plugins.jetbrains.com/plugin/32138-kcp-language-support
It provides .cp file type support, syntax highlighting, semantic diagnostics, navigation, rename support, type hints, and run configurations backed by the bundled native KCP tools.
The release ZIP is also attached to GitHub releases as kcp-clion-plugin-<version>.zip.
Create hello.cp:
import std;
main() -> i32
{
println("hello from {}", "KCP");
return 0;
}Build and run it:
kcp hello.cp -o hello
./helloUseful compiler options:
kcp --help
kcp hello.cp --emit ll -o hello.ll
kcp hello.cp --emit obj -o hello.o
kcp hello.cp --release -o hello
kcp hello.cp --verbose -o helloFor multi-file modules, pass the entry file and let the compiler resolve imports from the current directory, the input file directories, and the installed standard library:
kcp main.cp -o appIf you are using an unpacked custom standard library or runtime, override the installed paths:
CP_STDLIB_ROOT_PATH=/path/to/std \
CP_RUNTIME_LIBRARY_PATH=/path/to/libcp_runtime.a \
kcp main.cp -o appKCP is a statically typed systems language with explicit modules, value-oriented aggregates, generic programming, and predictable low-level interop.
Current language areas include:
- modules, imports, exports, and name visibility
- structs, impl blocks, constructors, destructors, member functions, and UFCS
- strong integer enums, variants, payload cases, and
match - references, pointers, arrays, tuples, ownership, move, and
like& - lambdas, function values, captures, and closure checks
- generic functions, generic types, parameter packs, and
template for - concepts, associated types, default implementations, and constrained APIs
- operator overloading, explicit casts, opaque aliases, and
extern "C"
Example:
import std.core.option;
variant event {
quit;
key(char);
resize(i32, i32);
}
score(value: event) -> i32
{
return match value {
.resize(width, height) => width + height,
.key(code) => 1,
.quit => 0,
};
}
main() -> i32
{
let some = optional<i32>::some(20);
let none = optional<i32>::none;
return some.value_or(0) + none.value_or(10) + score(event::resize(5, 7));
}More examples are available under design/examples/.
The standard library is implemented as ordinary KCP modules. It currently includes:
std.core:optional,expected, iterator protocolsstd.memory: raw buffers and spansstd.collections:vector, orderedmap, orderedsetstd.text:strand owningstringstd.ranges: sources, lazy adapters, and terminalsstd.meta: type queries and callable conceptsstd.compare: comparison categories and ordering objectsstd.algorithm: sorting algorithmsstd.io: formatting and outputstd.fs: synchronous file IO
| Path | Contents |
|---|---|
compiler/ |
command-line compiler entry points |
source/ |
source text, spans, and location utilities |
preprocessor/ |
source normalization before lexing |
lexer/ |
tokenization and lexical diagnostics |
parser/ |
parser, syntax tree, and parse diagnostics |
semantic/ |
semantic analysis, types, generics, and language rules |
codegen/ |
IR and LLVM code generation |
runtime/ |
runtime ABI documentation and support |
std/ |
KCP standard library source |
design/ |
language documentation and examples |
clion-plugin/ |
CLion plugin for KCP language support |
test/ |
compiler, library, parser, lexer, and integration tests |
cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failureBuild only the compiler:
cmake --build build --target kcpBuild release packages from an already configured CMake tree:
scripts/package-linux.sh \
--build-dir build \
--version 0.1.0 \
--out-dir dist/releaseRun the deterministic style checks:
python3 .codex/skills/cp-code-style/scripts/check_cp_style.pyThe public language documentation is available at:
The source for the documentation site lives in design/ and can be previewed locally:
cd design
npm run devUseful entry points:
