feat: capture-less anonymous functions (closures)

Implement MVP closures — anonymous functions without captures.

Syntax:
  |a: int, b: int| -> int { return a + b; }

Changes:
- ast.bux + ast.nim: add ekClosure AST node
- parser.bux + parser.nim: parse |params| -> Ret { body }
- sema.bux + sema.nim: type-check closure params/body, return tyFunc
- hir_lower.bux + hir_lower.nim: generate __closure_N function + hAddrOf
- lir_c_backend.nim: fix function-pointer variable declaration (cParamDecl)
- C backend: closures compile to global functions with unique names

Test: _test_closure/src/Main.bux
- Closure as variable
- Closure passed to higher-order function
- Address of named function as function pointer

Both bootstrap and selfhost compilers build and pass the test.
This commit is contained in:
2026-06-09 20:24:10 +03:00
parent 34504d1647
commit c83f6d5994
16 changed files with 2290 additions and 8 deletions
+3
View File
@@ -107,6 +107,7 @@ const ekMatch: int = 22;
const ekSpawn: int = 24;
const ekAwait: int = 25;
const ekStringInterp: int = 26;
const ekClosure: int = 27;
struct ExprList {
expr: *Expr,
@@ -139,6 +140,8 @@ struct Expr {
// Struct init fields
structName: String,
structFieldCount: int,
// Closure params (for ekClosure)
closureParams: *Decl,
// Call arguments (linked list for multi-arg support)
callArgs: *ExprList,
callArgCount: int,