Fun is a statically-typed programming language that transpiles to C, designed for safety, performance, and simplicity. Written in Zig. By default, Fun is a 64-bit language: num is a signed 64-bit integer and dec is a 64-bit IEEE double.
- Fun Programming Language
- Statically-typed, C-like performance
- 64-bit numeric core (
num= int64,dec= double) - Transpiles to readable C code
- Simple, expressive syntax
- Modular imports
- Pattern matching (
fitstatement) - Type-safe variables and functions
- CLI with multiple output and debug options
- AST printing and analysis
- Comprehensive error handling
- Example and test suite
Requires Zig (v0.14.0+ recommended).
zig buildThis will build the fun compiler in zig-out/bin/fun.
To install the compiler plus the Fun standard library files:
zig build installThis installs:
zig-out/bin/funzig-out/share/fun/stdlib/std/c/*.fn(signature-only C-interop modules used for tooling)
Notes:
std.c.*is the C-interop layer (signatures only). These modules describe external C APIs (e.g.printf) so the compiler and language server can typecheck and provide tooling.std.*(without.c) is intended for Fun-native standard library modules written in Fun.
Release assets are packaged as install bundles (binary + share/fun/ + an installer script).
On Windows, release assets are provided as .msi installers.
The compiler discovers the standard library at runtime using, in order:
FUN_STDLIB_DIR(explicit override)<exe>/../share/fun(installed layout)- common system locations (platform-dependent)
Use the published setup action to install fun in CI:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: omdxp/setup-fun@v1
with:
version: latest
- run: fun -versionUsage: fun -in <input_file> [-out <output_file>] [-no-exec] [-outf] [-ast] [-help]
Arguments:
-in <file> Input file to compile (required)
-out <file> Output file (optional, defaults to input filename with .c extension)
-no-exec Disable automatic compilation and execution (optional, execution enabled by default)
-outf Generate .c output file (optional, disabled by default)
-ast Print AST nodes (optional, disabled by default)
-help Show this help message
By default, fun uses zig cc unless FUN_CC is set. Release installers on macOS/Linux set FUN_CC=gcc by default. The Windows MSI sets FUN_CC to use cl with a template command. You can override the C compiler with environment variables:
FUN_CC: compiler command. If it includes{src}and{out}, it is treated as a full template.FUN_CC_ARGS: extra arguments appended after the base command.
Examples:
- Use clang:
FUN_CC=clang
- Use zig cc explicitly:
FUN_CC=zigandFUN_CC_ARGS="cc"
- Use a template with explicit placeholders:
FUN_CC="clang -O2 {src} -o {out}"
Write your first program in hello.fn:
imp std.c.io;
fun main(str[] args) {
printf("Hello, World!\n");
}Compile and run:
zig build
./zig-out/bin/fun -in hello.fnExplore the examples/ directory for more:
- Basic:
test.fn - Advanced:
advanced/custom_functions.fn - Imports:
imports/main.fn - Imports (parent traversal
....):imports/parent_traversal_2up/nested/level1/main.fn - Error cases:
error_cases/
- Language overview: docs/language.md
- Full reference: docs/reference.md
cmd/— CLI entrypointmodules/— Core compiler modules (lexer, parser, codegen, semantics, utils, etc.)examples/— Example programstests/— Test suitebuild.zig— Zig build script
Contributions are welcome! Please open issues or pull requests. See CONTRIBUTING.md if available.
See CHANGELOG.md for release notes and development history.
This project is licensed under the MIT License. See the LICENSE file for details.
This repo includes a work-in-progress language server called fls.
- Build:
zig build(installsflsalongsidefun) - The server speaks LSP over stdio and currently supports:
- Diagnostics (via
fun -no-exec) - Formatting (via
fun -fmt -no-exec)
- Diagnostics (via
There is a minimal VS Code extension scaffold in editors/vscode.
- Build
fun+flsfirst (zig build) - Then open
editors/vscodein VS Code and follow its README.
See editors/README.md for Vim/Neovim, Emacs, JetBrains, and Sublime setup.
This repo maps .fn files to Zig highlighting on GitHub via /.gitattributes.
For native Fun highlighting, submit a Fun definition + TextMate grammar to GitHub Linguist.
- Zig (the one defined in build.zig.zon)
- Windows, Linux, or macOS
Clone the repository and build using Zig:
git clone https://github.com/omdxp/fun.git
cd fun
zig buildPre-built installers and binaries are available for each release. See Release installers (bundles).