Skip to content

Latest commit

 

History

1,981 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The cx Programming Language

cx (stylized as lowercase, not to be confused with languages called CX or Cx) is a C-family hybrid low-level/high-level programming language focused on runtime performance and developer productivity (in this order of priority). The language is simple and unopinionated, supporting imperative, generic, data-oriented, functional, and object-oriented programming. It compiles to efficient native code via LLVM or the C backend, with no garbage collection or hidden runtime.

Note

The project is nearing its 0.1 release: there are still some planned features that haven't been implemented yet, and the currently implemented features are subject to change, and there are bugs.

To learn more about the language, visit the website:

cx-language.github.io/cx

For more code samples, see examples.

You can also read the language documentation in Markdown format under docs.

To ask a question or open a discussion, create an issue or join the cx Discord server.

Building from source

Compiling cx requires a C++20 compiler, CMake 3.16 or newer, and LLVM/Clang 23.

Linux

On Ubuntu/Debian, install the prerequisites with:

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 23 all
sudo apt-get install -y cmake g++ python3-pip

On other distributions, install CMake and a C++ compiler with your package manager, then download and extract the pre-built LLVM/Clang 23 binaries (replace X64 with ARM64 on ARM):

curl -L -O https://github.com/llvm/llvm-project/releases/download/llvmorg-23.1.1/LLVM-23.1.1-Linux-X64.tar.xz
tar -xf LLVM-23.1.1-Linux-X64.tar.xz

Then run the following commands, with <llvm dir> set to /usr/lib/llvm-23 for apt installs or the extracted directory for tarball installs:

mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH="<llvm dir>"
cmake --build .

macOS

brew install llvm@23 cmake

Then run the following commands:

mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH="$(brew --prefix llvm@23)"
cmake --build .

Windows

Download and extract LLVM/Clang 23 pre-built binaries from https://github.com/llvm/llvm-project/releases. Then run the following commands:

mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH="C:\path\to\llvm" -DCMAKE_GENERATOR_PLATFORM=x64 -Thost=x64
cmake --build .

The cx and cx-lsp binaries end up in the build directory.

Editor support

For diagnostics, hover, go to definition, completions, find references, and semantic highlighting in any LSP-capable editor, see the language server setup guide. The cx-lsp binary is built alongside cx.

Contributing

Contributions are welcome. See the GitHub issues and the Trello board for the project backlog.

Running tests

Install lit and its optional dependencies via pip:

python3 -m pip install lit psutil

Some examples have extra prerequisites; see the README in each example directory for details.

Then invoke the following from the build directory:

cmake --build . --target check

This runs the full suite via CTest: the lit/compiler tests, the example programs (LLVM and C backends), the documentation snippets, and the language server end-to-end tests. Run a subset from the build directory with e.g. ctest -R 'docs-snippets'. To run a single compiler test file, invoke lit with the flags shown by ctest -N -V.

The C++ code style is enforced by ClangFormat:

  • Run the format CMake target to format the code.
  • Run the lint CMake target to check if the code is formatted.

Website and playground

To work on the browser playground or the website, see wasm/README.md (architecture, building, and testing of the WebAssembly frontend and the in-browser C toolchain). Run website/build-website.sh --serve to develop the website locally.

License

cx is licensed under the MIT license, a permissive free software license. See the file LICENSE.txt for the full license text.

About

cx is a C-family systems programming language for game development and high-performance software: data-oriented, productive, no GC, compiles to native code via LLVM/C.

Topics

Resources

Code of conduct

Stars

146 stars

Watchers

6 watching

Forks

Releases

Contributors

Languages