This is the compiler for the Flag programming language, my own language, a mix of ideas from lots of programming languages.
- Python-like syntax
- Statically typed
- Built for Data-Oriented Design (lots of features for data structure definitions)
- Manual memory management with
defer, no garbage collector, and arenas that release everything at once, with the same lists, text and maps - Optional Memory-safety at comptime using -memory flag (makes compiling slower)
- Runtime errors and crashes print the chain of calls of your code, and
-debugbuilds for gdb and lldb flagc testruns everyfunc test_name()in a process of its own, in parallel and with a timeout- Errors as values that can carry data, handled with
try,trust,iferroror aswitch, and a dropped error doesn't compile - Tagged unions, narrowed by
isand by the cases of aswitch, and fat pointers built into the syntax - Structs compare and hash themselves, so they work as map keys
- Automatic context management across functions with the
contextkeyword: a context for each thread,inheritedby the threads it starts, orsharedby all of them, and nothing runs beforemain - Threads with
parallel f(x)andwait(t), aLock[T]that wraps what it guards and works at zero, and boundedChannels - Generics support
- Function and operator overloading, with
whereto choose an overload at compile time - Function values, without closures
- Small functions are inlined and small structs live in registers,
inline funcinlines at every call simd[T, n], lanes of numbers in one register with operators that work on all of them, on SSE and NEON- ABI FFI to interop with other languages (both ways), with typed C function values, and shared libraries that a program loads and reloads while it runs
- A small standard library: text, lists, maps, buffered files, folders, other programs, JSON, TCP, UDP and raylib
- QBE backend for really fast compilation, for example, the compiler builds itself in about a second and a half
- Support for Linux, macOS and Windows
type error NotFound:
name: &strview
func index_of(names: &listview[&strview], name: &strview) -> i64|NotFound:
for i, n in names:
if n == name:
return i
return NotFound{name}
func main():
names := ["bob", "alice"]
for name in ["alice", "ada"]:
found := index_of(ptr(names), name)
switch found:
case i64:
print(name, " is at ", found)
case NotFound:
print("there is no ", found.name)
Important: this is not a production-ready programming language, so be aware.
Except for the lexer which is the base of the code style, all the code in the compiler was rewritten by AI.
- Overview, a tour of the language
- Reference, the exact rules, the limits and how the compiler works
- Library, every function of the standard library
- Examples
Download the archive for your system from the releases: flag-0.6.0-linux-x86_64.tar.gz, flag-0.6.0-macos-arm64.tar.gz or flag-0.6.0-windows-x86_64.tar.gz. Unpack it and put its bin folder in your PATH
tar -xzf flag-0.6.0-linux-x86_64.tar.gz
export PATH="$PWD/flag-0.6.0-linux-x86_64/bin:$PATH"
flagc -versionflagc is a single file, the standard library is inside it. You also need a C compiler, see Requirements.
- On macOS, if the system says it cannot check the developer, run
xattr -d com.apple.quarantine flag-0.6.0-macos-arm64/bin/flagc - On Windows, unpack it the same way from the MSYS2 shell, or with
tar -xzfin PowerShell
For errors, hover and go to definition in your editor, see flag-lsp.
flagc turns your code into assembly and links it with a C compiler, so you need one
- Linux: gcc or clang, usually already installed (
sudo apt install gccon Debian and Ubuntu) - macOS: the Xcode command line tools,
xcode-select --install - Windows: gcc from MSYS2, in its UCRT64 shell
pacman -S mingw-w64-ucrt-x86_64-gcc
If yours is not called cc, set the CC variable, for example CC=gcc. zig works on the three systems with CC="zig cc", and it can also build for the other two.
Clone the repo and run build.sh, it only needs the C compiler of the requirements. On Windows run it from the MSYS2 UCRT64 shell
cd flag-lang
./build.shThe compiler ends up in build/flagc.
If you have cool ideas to make the language better, open an issue and I may add them.
You can also open pull requests, and I will review them. Just make sure to open an issue first and link it from the pull request
You can use AI, just make sure to use a good frontier model, and review what it writes or have another model review it before publishing.