https://github.com/omdxp/fun
Fun is a statically-typed language that transpiles to C, combining safety and performance with C's efficiency.
https://github.com/omdxp/fun
c transpiler zig
Last synced: 24 days ago
JSON representation
Fun is a statically-typed language that transpiles to C, combining safety and performance with C's efficiency.
- Host: GitHub
- URL: https://github.com/omdxp/fun
- Owner: omdxp
- License: mit
- Created: 2024-09-12T08:17:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-01T20:57:38.000Z (28 days ago)
- Last Synced: 2026-04-02T04:38:09.007Z (28 days ago)
- Topics: c, transpiler, zig
- Language: Zig
- Homepage: https://omdxp.github.io/fun
- Size: 2.72 MB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-zig - Fun - A statically-typed language that transpiles to C, combining safety and performance with C's efficiency. (Systems Programming / Compilers and Interpreters)
README
# Fun Programming Language
[](https://github.com/omdxp/fun/actions)
[](LICENSE)
**Fun** is a statically-typed programming language that transpiles to C, designed for safety, performance, and simplicity. Written in Zig. Fun includes high-level defaults (`num`, `dec`) and low-level fixed/arbitrary-width numeric types (`i32`, `u64`, `f32`, `f64`, `iN`, `uN`).
---
## Table of Contents
- [Fun Programming Language](#fun-programming-language)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Installation](#installation)
- [Release installers (bundles)](#release-installers-bundles)
- [GitHub Actions](#github-actions)
- [CLI Usage](#cli-usage)
- [C Compiler Selection](#c-compiler-selection)
- [Windows notes](#windows-notes)
- [Quickstart](#quickstart)
- [Examples](#examples)
- [Documentation](#documentation)
- [Project Structure](#project-structure)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)
- [IDE / Language Server (fls)](#ide--language-server-fls)
- [VS Code](#vs-code)
- [Other Editors](#other-editors)
- [GitHub Syntax Highlighting](#github-syntax-highlighting)
- [Installation](#installation-1)
- [Prerequisites](#prerequisites)
- [Build from Source](#build-from-source)
- [Install from Release](#install-from-release)
---
## Features
- Statically-typed, C-like performance
- Rich numeric model (`num`/`dec`, fixed-width `i32`/`u64`, and arbitrary-width `iN`/`uN`)
- Transpiles to readable C code
- Simple, expressive syntax
- Modular imports
- Pattern matching (`fit` statement)
- Type-safe variables and functions
- CLI with multiple output and debug options
- AST printing and analysis
- Comprehensive error handling
- Example and test suite
## Installation
Requires [Zig](https://ziglang.org/) (v0.14.0+ recommended).
```bash
zig build
```
This will build the `fun` compiler in `zig-out/bin/fun`.
To install the compiler plus the Fun standard library files:
```bash
zig build install
```
This installs:
- `zig-out/bin/fun`
- `zig-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 installers (bundles)
Release assets are packaged as install bundles (binary + `share/fun/` + an installer script).
On Windows, release assets are provided as both `.msi` installers and portable `.zip` archives.
The portable archive contains the same `fun-/` layout (`bin/` + `share/fun/`) so you can unzip and run without installation.
Each portable archive also includes `README-portable.txt` with Windows-specific quickstart notes.
The compiler discovers the standard library at runtime using, in order:
- `FUN_STDLIB_DIR` (explicit override)
- `/../share/fun` (installed layout)
- common system locations (platform-dependent)
## GitHub Actions
Use the published setup action to install `fun` in CI:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: omdxp/setup-fun@v1
with:
version: latest
- run: fun -version
```
## CLI Usage
```
Usage: fun -in [-out ] [-no-exec] [-outf] [-ast] [-help]
Arguments:
-in Input file to compile (required)
-out 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
```
### C Compiler Selection
By default, `fun` tries platform compiler defaults unless `FUN_CC` is set:
- Windows: `zig cc`, `clang`, `gcc`, `cl`
- macOS/Linux: `zig cc`, `clang`, `gcc`, `cc`
Release installers on macOS/Linux set `FUN_CC=gcc` by default. The Windows MSI sets `FUN_CC` to use `cl` with a template command. The Windows portable `.zip` does not modify your environment. 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=zig` and `FUN_CC_ARGS="cc"`
- Use a template with explicit placeholders:
- `FUN_CC="clang -O2 {src} -o {out}"`
#### Windows notes
If you use `cl`, run `fun` from **Developer PowerShell for Visual Studio** (or after `VsDevCmd.bat`) so MSVC environment variables are initialized.
Recommended stable setup on Windows:
```powershell
$env:FUN_CC = "zig"
$env:FUN_CC_ARGS = "cc"
```
Use `cl` explicitly only when your VS toolchain shell is active:
```powershell
$env:FUN_CC = "cl /nologo /Fe{out} {src}"
$env:FUN_CC_ARGS = ""
```
If `cl` compiles but runtime output looks wrong on your system/toolset, switch back to `zig cc`.
## Quickstart
Write your first program in `hello.fn`:
```fun
imp std.c.io;
fun main(str[] args) {
printf("Hello, World!\n");
}
```
Compile and run:
```bash
zig build
./zig-out/bin/fun -in hello.fn
```
## Examples
Explore the [`examples/`](examples/) directory for more:
- Basic: [`test.fn`](examples/test.fn)
- Advanced: [`advanced/custom_functions.fn`](examples/advanced/custom_functions.fn)
- Imports: [`imports/main.fn`](examples/imports/main.fn)
- Imports (parent traversal `....`): [`imports/parent_traversal_2up/nested/level1/main.fn`](examples/imports/parent_traversal_2up/nested/level1/main.fn)
- Error cases: [`error_cases/`](examples/error_cases/)
## Documentation
- Language overview: [docs/language.md](docs/language.md)
- Full reference: [docs/reference.md](docs/reference.md)
- Channel/runtime conformance matrix and backend thresholds: [docs/channel-runtime-conformance.md](docs/channel-runtime-conformance.md)
## Project Structure
- `cmd/` — CLI entrypoint
- `modules/` — Core compiler modules (lexer, parser, codegen, semantics, utils, etc.)
- `examples/` — Example programs
- `tests/` — Test suite
- `build.zig` — Zig build script
## Contributing
Contributions are welcome! Please open issues or pull requests. See [CONTRIBUTING.md](CONTRIBUTING.md) if available.
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for release notes and development history.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## IDE / Language Server (fls)
This repo includes a work-in-progress language server called `fls`.
- Build: `zig build` (installs `fls` alongside `fun`)
- The server speaks LSP over stdio and currently supports:
- Diagnostics (via `fun -no-exec`)
- Formatting (via `fun -fmt -no-exec`)
### VS Code
There is a minimal VS Code extension scaffold in [editors/vscode](editors/vscode).
- Build `fun` + `fls` first (`zig build`)
- Then open `editors/vscode` in VS Code and follow its README.
### Other Editors
See [editors/README.md](editors/README.md) for Vim/Neovim, Emacs, JetBrains, and Sublime setup.
### GitHub Syntax Highlighting
This repo maps `.fn` files to Zig highlighting on GitHub via [/.gitattributes](.gitattributes).
For native Fun highlighting, submit a Fun definition + TextMate grammar to GitHub Linguist.
## Installation
### Prerequisites
- [Zig](https://ziglang.org/download/) (the one defined in [build.zig.zon](build.zig.zon))
- Windows, Linux, or macOS
### Build from Source
Clone the repository and build using Zig:
```sh
git clone https://github.com/omdxp/fun.git
cd fun
zig build
```
### Install from Release
Pre-built installers and binaries are available for each release. See [Release installers (bundles)](#release-installers-bundles).