- Extend Lcx_BuildAutoDropFree to detect TypeName_Drop methods registered by sema for extend Type for Drop impl blocks. - Preserve existing @[Drop] attribute path and move semantics. - Add design doc and implementation plan. - Mark Destructors/Drop roadmap item done in selfhost.
8.0 KiB
Bux Language Roadmap — New Constructs
Updated: 2026-06-09 | Status: In Progress
This document tracks planned language constructs beyond Phase 8 strategy.
✅ Done
1. defer Statement
Status: ✅ Implemented in both bootstrap and selfhost.
Syntax:
func ReadFile(path: String) -> String {
let fd: int = Open(path);
defer Close(fd); // runs on any exit from scope
defer PrintLine("done"); // LIFO order
let data: String = ReadAll(fd);
return data; // both defers run before return
}
2. Native switch / case
Status: ✅ Implemented in both bootstrap and selfhost. Desugars to if-else chain.
Syntax:
switch statusCode {
case 200: PrintLine("OK");
case 404: PrintLine("Not Found");
case 500: PrintLine("Server Error");
default: PrintLine("Unknown");
}
3. Operator Overloading
Status: ✅ Implemented in bootstrap. Selfhost has no method-table yet (not needed for selfhost-loop parity).
Supported operators:
func Vec2_operator_add(self: *Vec2, other: Vec2) -> Vec2 { ... }
func Vec2_operator_sub(self: *Vec2, other: Vec2) -> Vec2 { ... }
func Vec2_operator_eq(self: *Vec2, other: Vec2) -> bool { ... }
func Vec2_operator_lt(self: *Vec2, other: Vec2) -> bool { ... }
func MyArray_operator_index_get(self: *MyArray, idx: int) -> int { ... }
func MyArray_operator_index_set(self: *MyArray, idx: int, value: int) { ... }
Notes:
- Works via method-table lookup in sema + hir_lower.
- Generic method instantiation supported.
- Short-circuit operators (
&&,||) remain builtin.
4. String Interpolation
Status: ✅ Implemented in bootstrap (selfhost reserves AST node).
Syntax:
let name: String = "Bux";
let msg: String = f"Hello, {name}!";
let num: int = 42;
let msg2: String = f"Count: {num}";
Notes:
f"..."prefix enables interpolation.- Escaped braces:
\{and\}. - Auto-converts
int,uint,float,bool, andStringinside braces.
5. Named / Default Parameters
Status: ✅ Implemented in both bootstrap and selfhost.
Syntax:
func HttpResponse(code: int = 200, body: String = "") -> Response { ... }
let r: Response = HttpResponse(body: "hello"); // code=200
let s = HttpResponse(404, body: "err"); // positional + named mixed
Notes:
- Bootstrap parser already parsed defaults; added named-arg parsing and sema injection.
- Selfhost parser parses
= defaultExprin params andname: valueat call sites. - Sema injects default expressions and reorders named args into param order.
6. CLI Commands (bux new, bux init, bux test, bux fmt)
Status: ✅ Implemented in selfhost.
| Command | Description |
|---|---|
bux new <name> |
Create a new project directory with bux.toml and src/Main.bux |
bux init |
Initialize a Bux project in the current directory |
bux test [dir] |
Build and run the project binary, reporting pass/fail |
| `bux fmt <file | dir>` |
7. Basic Borrow Checker (@[Checked])
Status: ✅ Implemented in selfhost.
Features:
@[Checked]attribute enables per-function borrow checking.&T(shared reference) and&mut T(mutable reference) type syntax.- Rejects write-through raw pointer (
*T) in checked functions. - Detects double mutable borrow (
Swap(&mut x, &mut x)). - Tracks use-after-move for
own Tvalues.
P0 — Critical (Unlocks Major Use Cases)
8. Full Selfhost Bootstrap Loop
Why: The selfhost compiler must compile itself deterministically.
Status: ✅ Done — selfhost-loop produces identical C output on every iteration.
6. Closures / Anonymous Functions
Status: ✅ Implemented in both bootstrap and selfhost. Capture-less and with captures.
Syntax:
// Capture-less closure
let add: func(int, int) -> int = |a, b| { return a + b; };
// Closure with captures
let base: int = 10;
let adder: func(int) -> int = |a: int| -> int { return a + base; };
let result: int = adder(5); // 15
// Pass closure to higher-order function
Array_Filter(nums, |x| { return x > 10; });
Implementation:
- Capture-less closures: generate global thunk function, return
&thunkas function pointer. - Closures with captures:
- Sema:
Scope_LookupUpToidentifies captured variables from outer scope. - HIR Lower: generate
__closure_env_Nstruct + global instance__closure_env_instance_N. - At closure creation site: emit capture assignments (
env_instance.x = x;). - In thunk body: rewrite captured identifiers to
env_instance.xviahFieldAccess. - C backend: emit env struct definition + global instance before thunk function.
- Sema:
Limitations: One global instance per closure AST node (no multiple instances). No loop/return support in closures yet.
Complexity: High — touches parser, sema, type system, HIR/LIR backend.
7. for x in collection Iterator Loops
Why: Currently only for i in 0..10 works. No way to iterate arrays/channels/maps.
Syntax:
for item in arr {
PrintLine(item);
}
for msg in channel {
Process(msg);
}
Implementation Steps:
- ✅ Parser: extend
forto acceptfor <ident> in <expr> { ... } - ✅ Range-based:
for i in lo..hiandfor i in lo..=hi— desugared towhileloop with counter - ✅ Collection-based:
for x in arr— desugared toArray_Iter_T+Iter_HasNext_T+Iter_Next_T
Complexity: Medium — done.
P1 — High Impact
8. Destructors / Drop Trait
Status: ✅ Done in selfhost.
Why: own T exists but nothing cleans up automatically. Complements defer.
Syntax:
import Drop
struct Buffer {
ptr: *int
}
extend Buffer for Drop {
func Drop(self: *Buffer) {
bux_free(self.ptr as *void);
}
}
Implementation Steps:
- ✅ Define
Dropinterface in stdlib (lib/Drop.bux) - ✅ HIR lowering: emit
TypeName_Drop(&value)before variable goes out of scope (selfhost) - ✅ Respect move semantics — moved values are skipped via
CBE_IsMoved
Notes:
- Bootstrap compiler still requires explicit
deferfor user-defined cleanup. - See
docs/superpowers/specs/2026-06-14-drop-interface-auto-drop-design.md.
Complexity: Medium — reused existing @[Drop] auto-drop path and interface method table.
9. Trait Bounds (T: Comparable)
Why: Generic functions need constraints on type parameters.
Syntax:
func Sort<T: Comparable>(arr: &mut Array<T>) { ... }
Status: ✅ Implemented — @[Comparable] attribute + Sema_CheckTraitBounds in selfhost.
10. CTFE (Compile-Time Function Execution)
Why: Precomputed tables for embedded / kernel dev.
Syntax:
const A: int = 10;
const B: int = 20;
const C: int = A + B; // Evaluated at compile time
Status: ✅ Implemented — multi-pass expression evaluator in HIR lowering.
Supported: literals, binary/unary/ternary ops, casts, cross-const references.
P2 — Nice to Have
11. Concurrency
Why: Go-style goroutines + channels, but without GC.
Syntax:
let (tx, rx) = Channel::New<int>();
Task::Spawn(Worker, rx);
Recommended Order
- ✅
defer— Done - ✅
switch/case— Done - ✅ Operator overloading — Done (bootstrap)
- ✅ String interpolation — Done (bootstrap)
- ✅ Named/default parameters — Done
- ✅ Basic borrow checker (
@[Checked]) — Done (selfhost) - ✅
bux fmt,bux test,bux new,bux init— Done (selfhost) - ✅ Closures (capture-less) — Done
- ✅ Closures with captures — Done
- ✅
for x in collection— Done - ✅ Trait bounds (
T: Comparable) — Done - ✅ CTFE — Done
- ✅ Selfhost bootstrap loop — Done
- ✅ Destructors / Drop — Done in selfhost.
- Bounds checking on slices — Add
Slice<T>type with bounds-checked indexing. - Concurrency — Green threads + channels.