TryC documentation
TryC is a compiled systems language with a Python-like syntax, a scope-based memory model (no free(), no garbage collector) and no dependency on libc: programs talk to the Linux kernel directly, and the same code can target a bare-metal kernel with --noheap --nosyscall.
This documentation, like the comments and the other docs in the codebase, is written by AI. I work on TryC alone, and to move faster I use AI to write the comments and the documentation. The code it describes is mine; if a page and the code disagree, the code is right.
Getting started
Requirements, how to compile and run a program, what the pipeline does with your file.
Read →Compiler options
Every flag of the compiler: output, memory knobs, freestanding targets, the verification runtime.
Read →Language
Types, operators, control flow, functions, strings, arrays, classes, lists and dicts, pointers, macros, inline asm and FFI.
Start →The arena
How memory is allocated and released by scope, what a promotion is, and what escapes a function.
Read →Runtime internals
Pool chunks, bitmaps, the allocation hash table, huge pages, the string builder, scope elision: the algorithms behind the arena.
Read →Memory safety
What is checked today, --check-arena (the arena's address sanitizer), and the roadmap to a memory-safe language.
Standard library
Reference for every libstd module: I/O, strings, lists, dicts, files, processes, threads, sockets, regex, JSON, SQLite, MySQL, X11, Vulkan.
A first look
#include <libstd/stdio>
class Point:
x int
y int
def make_point(px: int, py: int) -> Point:
p = new Point
p.x = px
p.y = py
return p // the arena keeps 'p' alive for the caller
def main() -> int:
p = make_point(3, 4)
total = 0
for i = 0; i < 3; i++:
total = total + i * p.x
print("total = ", total, "\n")
return 0
main()
total = 9
What makes it different
- Scope-based memory. Every function call and every loop iteration opens a scope; whatever is allocated inside is released when the scope closes, unless the compiler promotes it (a returned value, a field store, a global). You never write
free(). See The arena. - No libc. The runtime is written in freestanding C and the standard library wraps Linux syscalls directly. A binary has no dynamic dependencies unless you link a C library with
libextern. - Freestanding targets.
--noheapkeeps all allocations in a fixed BSS pool (nommap),--nosyscallremoves every syscall from the generated code: the same language runs inside a kernel that has not set up its heap yet. - LLVM code generation. The compiler emits LLVM IR and uses
opt/llc/clangfor optimisation, assembly and linking, so generated code benefits from LLVM's optimiser while the runtime stays a small piece of hand-written assembly. - Self-hosting. A second compiler, written in TryC itself, compiles its own source in about 80 ms.
TryC is a personal research project. The language is usable and the standard library is large, but the memory model is not yet memory-safe in the strict sense; the memory safety page states exactly what is guaranteed, what is not, and what is planned.