Fun is a statically-typed, C-transpiling language focused on performance and clarity. The compiler emits readable C and relies on the system C toolchain for linking and execution.
numis a signed 64-bit integer (Cint64_t).decis a 64-bit floating-point number (Cdouble).- Fixed-width integers:
i8,i16,i32,i64,u8,u16,u32,u64. - Fixed-width floats:
f32(float),f64(double). - Arbitrary-width integers:
iN/uN(emitted as_BitInt(N)/unsigned _BitInt(N)when width is not a standard 8/16/32/64). binis boolean (bool).chris a character (char).stris a null-terminated string (char*).rawis an opaque/void type (voidin C; useraw*forvoid*).
- File extension:
.fn - Statements end with
;. - Blocks are delimited with
{}. - Comments:
//single-line.
imp std.c.io;imports a C header signature module.imp std.string;imports Fun stdlib modules.- Relative imports are supported (e.g.,
imp ..foo.bar;). - Import aliases are supported:
imp mod1 as one;then useone.symbol. - Aliases are the supported way to avoid duplicate exported symbol collisions across imported modules.
- Example:
imp mod1 as one;imp mod2 as two;num a = one.pick();num b = two.pick();
- Example:
num,dec,f32,f64,i8,i16,i32,i64,u8,u16,u32,u64,iN,uN,bin,chr,str,raw
- Syntax:
num[] arr = [1, 2, 3]; - Array literals require uniform element types.
- Pointer depth:
Type*. - Example:
Node* next;.
compound Point {
num x;
num y;
}quirk Shape {
area() num;
}impl Point {
translate(num dx, num dy) {
self.x += dx;
self.y += dy;
}
}
impl Rectangle Shape {
area() num { ret self.w * self.h; }
}- Compounds and impls can be generic:
compound Vec<T> { ... }. - Use
Vec<num>etc. where required.
- Variables can be explicitly typed or inferred with
let.
num x = 1;
str name = "fun";
let count = add(1, 2);fun add(num a, num b) num {
ret a + b;
}- No nested function declarations.
- Use
retfor return. - Generic functions are supported:
fun id<T>(T x) T { ret x; }if x > 0 {
...
} elif x == 0 {
...
} else {
...
}- Range:
for i : 0..10 { ... } - Array:
for item : arr { ... } - Indexed:
for i, item :: arr { ... } - While-style (condition):
for i < len { ... } - Infinite loop:
for true { ... } - This style is used in stdlib (for example
std/string.fn,std/net.fn, andstd/fs.fn).
fit c {
.Red -> { ... },
.Green -> { ... },
_ -> { ... }
}- Missing variants may produce warnings unless
_is present.
- Expression:
defer close(fd); - Block:
defer { cleanup(); } - Runs in LIFO order before function exit.
asm volatile (out y: "=r" = y; in x: "r" = x; clobber "memory") {
mov x0, x0
};asm arch x86_64 { ... };guards by target architecture.- Block contents are preserved as raw text (including whitespace/comments).
- Fun does not validate asm syntax inside the block; final validity is determined by the selected C toolchain assembler/dialect.
- Example:
jmp $can fail under clang/GAS inline asm, while local-label form (1: ... jmp 1b) is often accepted in that dialect. - Pass computed values through operands, e.g.
num x = 21 + 21; num y = 0; asm volatile (out y: "=r" = y; in x: "r" = x) { mov %[x], %[y] };. - Use string form for explicit escaping:
asm "...";.
- Import C headers via
imp std.c.*;. - C constants (e.g.,
NULL,INT_MAX) are allowed when headers are imported. nummaps toint64_t; forprintf, usePRId64(from<inttypes.h>) or cast tolong longand use%lld.
By default, fun uses zig cc. You can override the compiler with environment variables:
FUN_CC: compiler command. If it contains{src}and{out}, it is treated as a full template.FUN_CC_ARGS: extra arguments appended after the base command.
Examples:
FUN_CC=clangFUN_CC=zigandFUN_CC_ARGS="cc"FUN_CC="clang -O2 {src} -o {out}"
fun -fmt -in file.fnformats a file in place.fun -fmt-all -in file.fnformats local imports (skipsstd.*).- Asm block contents are preserved as raw text.
- Language Server for diagnostics and formatting.
- Diagnostics use
fun -no-execunder the hood.
std.array: array helpersstd.io: file helpers + print utilitiesstd.vec: dynamic vectorsstd.map: generic maps (Map<K, V>) with typed keys/values and bytewise hashed lookups by defaultstd.set: sets built on mapsstd.option: genericOption<T>containerstd.result: genericResult<T>containerstd.collections: collection quirks (len/is_empty)std.string: string helpersstd.json,std.toml: minimal serialization helpersstd.time,std.rand,std.math,std.path,std.net, etc.std.sys: environment and process helpers (sys_exit,sys_abort,sys_system)std.net: URL parsing + pure Fun POSIX TCP/HTTP helpers (POSIX sockets)
fun -in <input_file> [-out <output_file>] [-no-exec] [-outf] [-ast] [-help]
- Type mismatches, unknown symbols, and incomplete quirk implementations are errors.
- Fit exhaustiveness and pointer-return warnings are emitted as warnings.