Getting started

Install the toolchain, compile a program, and understand what the compiler does with your file.

Requirements

WhatWhy
Linux, x86-64The runtime talks to the kernel with raw syscalls and the generated code is x86-64 only.
A CPU with SSE4.2 and AVX2The runtime's string and memory routines (rt_strlen, rt_simd_memcpy, the allocator's bitmap scan) use SSE/AVX2 instructions unconditionally.
Python ≥ 3.12The reference compiler is written in Python.
binutilsclang 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.

StepInput → outputDone by
1. Precompilerhello.tryc → hello.iThe 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 generationhello.i → hello.llThe 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 assemblyhello.ll → hello.opt.ll → hello.oopt -O2 (loop and SLP vectorisation off) then llc -O2 --frame-pointer=all.
4. Linkhello.o + runtime → helloclang -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

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.