Getting started
Install the toolchain, compile a program, and understand what the compiler does with your file.
Requirements
| What | Why |
|---|---|
| Linux, x86-64 | The runtime talks to the kernel with raw syscalls and the generated code is x86-64 only. |
| A CPU with SSE4.2 and AVX2 | The runtime's string and memory routines (rt_strlen, rt_simd_memcpy, the allocator's bitmap scan) use SSE/AVX2 instructions unconditionally. |
| Python ≥ 3.12 | The reference compiler is written in Python. |
binutils | clang links with the system ld; objcopy is used by --llvm-static. |
clang, opt, llc (LLVM 13 or newer) | The generated LLVM IR is optimised with opt -O2, compiled with llc, and linked with clang -nostdlib -no-pie. |
llvm-config and the LLVM static archives (the -dev/-devel package) | Only for building the self-hosted compiler, which links LLVM in-process with --llvm-static. |
python3 main.py --first_run installs nasm, LLVM (with its development package) and clang through the distribution's package manager (apt, dnf, pacman, zypper, apk, xbps, emerge; package names verified on apt) and links opt, llc and clang into /usr/local/bin when the distribution installs them under a versioned name only. The compiler's pip requirements are installed by hand.
Hello world
Create hello.tryc:
#include <libstd/stdio>
print("Hello world\n")
Compile and run it (every flag is in Compiler options).
python3 main.py hello.tryc -o hello
./hello
main.py is the compiler's entry point; run it from the compiler's own directory, or through a wrapper script that does.
Hello world
The compiler prints timing information for each phase (precompiler, IR emission, opt, llc, link) and finishes with all works fine.
The pipeline
A source file goes through four steps. The intermediate files are written next to the source (hello.i, hello.ll, hello.opt.ll, hello.o) and are useful when something goes wrong.
| Step | Input → output | Done by |
|---|---|---|
| 1. Precompiler | hello.tryc → hello.i | The precompiler resolves #include, expands #define macros, #ifdef, #for, and copies inline def bodies to their call sites. --dbi stops here and shows the result. |
| 2. Code generation | hello.i → hello.ll | The compiler parses the program, runs its analyses (types, scopes, promotions) and emits LLVM IR. Every function of the program is checked, the ones nothing calls included; only the reachable ones end up in the IR. Errors are reported all together, one per function. |
| 3. Optimisation and assembly | hello.ll → hello.opt.ll → hello.o | opt -O2 (loop and SLP vectorisation off) then llc -O2 --frame-pointer=all. |
| 4. Link | hello.o + runtime → hello | clang -nostdlib -no-pie links your object with the runtime object (the C runtime in runtime/, compiled with llc once per target and cached) and with any libextern library. |
There is no libc anywhere in this chain: _start, the allocator, string routines, the SIGSEGV crash reporter and every syscall wrapper live in the runtime and in libstd.
What is in the repository
- The reference compiler, in Python: the precompiler, the code generator, the argument parser, the C runtime, the standard library, the examples (one directory per language feature, each with its recorded output) and the test suites.
- The self-hosted compiler, written in TryC, with its own build script (it is built by the reference compiler with
--hugepages --llvm-static). - This documentation site and the TryC HTTP server that serves it.
- A freestanding kernel experiment compiled with
--noheap --nosyscall.
Running the test suites
python3 test_llvm.py # 84 programs, compares exit codes
python3 test_automa.py # the examples, compares stdout with the recorded output
Both suites accept extra compiler flags through the environment, which is how the verification runtime is exercised:
TRYC_TEST_EXTRA_ARGS="--check-arena" python3 test_llvm.py
Editor support
The repository includes a VS Code extension with syntax highlighting for .tryc files.