MetaprogrammingSeen supports compile-time evaluation, decorators, derive macros, and reflection.

Metaprogramming

Seen supports compile-time evaluation, decorators, derive macros, and reflection.

Decorators

Decorators are annotations that modify code generation. They use the @ prefix.

Function Decorators

DecoratorEffect
@asyncTransform function into LLVM coroutine
@inline / @always_inlineForce inlining
@intrinsicMap to LLVM intrinsic
@compute(workgroup_size=N)GPU compute shader
@testMark as test function
@benchmarkMark as benchmark function
@initRun at module initialization

Class Decorators

DecoratorEffect
@derive(...)Generate trait implementations
@reflectEnable runtime type information
@packedRemove field padding
@cache_lineAlign to cache line
@trivially_copyableAllow memcpy
@moveEnforce move semantics
@nondeterministicAllow in deterministic mode
@componentRegister in component framework
@storeMutation-tracking state store

Modifier Decorators

DecoratorEffect
@sendType safe to transfer between threads
@syncType safe to share between threads
@cfg("feature")Conditional compilation
@repr(C)C-compatible struct layout

Derive Macros

@derive auto-generates trait implementations:

@derive(Clone, Hash, Eq, Debug)
class Point {
    var x: Float
    var y: Float
}

Available Derives

DeriveGenerated
Cloneclone() -- deep copy
Hashhash() -- hash code
Eqeq(other) -- equality check
Debugdebug() -- debug string representation
SerializeBinary serialization
DeserializeBinary deserialization
JsonJSON serialization/deserialization

Example: JSON Derive

@derive(Json)
class Config {
    var name: String
    var port: Int
    var debug: Bool
}

fun main() {
    let config = Config { name: "app", port: 8080, debug: true }
    let json = config.toJson()
    println(json)  // {"name":"app","port":8080,"debug":true}
}

Reflection

@reflect enables runtime type information (RTTI):

@reflect
class User {
    var name: String
    var age: Int
    var email: String
}

fun main() {
    let user = User { name: "Alice", age: 30, email: "alice@example.com" }

    // Get field names at runtime
    let fields = user.fieldNames()
    for field in fields {
        println(field)  // "name", "age", "email"
    }

    // Check if field exists
    if reflectHasField(user.fieldNames(), "email") {
        println("User has email field")
    }
}

Compile-Time Evaluation

comptime functions

Functions evaluated at compile time:

comptime fun factorial(n: Int) r: Int {
    if n <= 1 { return 1 }
    return n * factorial(n - 1)
}

let TABLE_SIZE = comptime { factorial(10) }

comptime blocks

Arbitrary compile-time computation:

let LOOKUP = comptime {
    var table = Array<Int>.withLength(256)
    var i = 0
    while i < 256 {
        table[i] = i * i
        i = i + 1
    }
    table
}

comptime if

Conditional compilation based on compile-time values:

comptime if TARGET == "wasm" {
    fun allocate(size: Int) r: Int {
        return wasm_alloc(size)
    }
} else {
    fun allocate(size: Int) r: Int {
        return malloc(size)
    }
}

@intrinsic

Map a Seen function directly to an LLVM intrinsic:

@intrinsic("llvm.sqrt.f64")
extern fun __Sqrt(x: Float) r: Float

@intrinsic("llvm.sin.f64")
extern fun __Sin(x: Float) r: Float

@intrinsic("llvm.fabs.f64")
extern fun __Fabs(x: Float) r: Float

Feature Flags

Conditional compilation via feature flags:

seen compile app.seen app --feature=gpu --feature=experimental

In source code:

@cfg("gpu")
fun renderWithGPU() {
    // only compiled when --feature=gpu is passed
}

@cfg("experimental")
class ExperimentalOptimizer {
    // only compiled when --feature=experimental is passed
}

Macros

Basic macro support for code generation:

macro define_getter(field_name, field_type) {
    fun get_{field_name}() r: {field_type} {
        return this.{field_name}
    }
}
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.