Skip to content
FramaLunaPublic

About

Flag Programming Language

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Flag

This is the compiler for the Flag programming language, my own language, a mix of ideas from lots of programming languages.

What the language has

  • 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 -debug builds for gdb and lldb
  • flagc test runs every func 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, iferror or a switch, and a dropped error doesn't compile
  • Tagged unions, narrowed by is and by the cases of a switch, 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 context keyword: a context for each thread, inherited by the threads it starts, or shared by all of them, and nothing runs before main
  • Threads with parallel f(x) and wait(t), a Lock[T] that wraps what it guards and works at zero, and bounded Channels
  • Generics support
  • Function and operator overloading, with where to choose an overload at compile time
  • Function values, without closures
  • Small functions are inlined and small structs live in registers, inline func inlines 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

Quick Code Example

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)

Status

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.

Docs

Installation

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 -version

flagc 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 -xzf in PowerShell

For errors, hover and go to definition in your editor, see flag-lsp.

Requirements

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 gcc on 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.

Build from source

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.sh

The compiler ends up in build/flagc.

Contributing

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.

About

Flag Programming Language

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages