feat: Phase 8.2, 8.4, 8.5, 9.1 + C backend fixes

Phase 8.2 — Gradual Ownership:
- Add tkRef/tkMutRef types and `mut` keyword
- Add @[Checked] attribute for opt-in borrow checking
- Reject assignment through &T in checked functions
- examples/ownership.bux

Phase 8.4 — CTFE:
- Evaluate const func at compile-time via evalExpr/evalBlock
- Fold const declarations to literals; emit #define in C
- examples/ctfe.bux (Factorial(10) → 3628800)

Phase 8.5 — Trait Bounds:
- Change declFuncTypeParams from seq[string] to seq[TypeParam] (name + bound)
- Parser handles <T: Comparable>
- Sema checks typeImplements at call sites
- Fix C backend: generic receivers + pointer self field access
- examples/trait_bounds.bux

Phase 9.1 — Package Manager:
- Inline tables/arrays in TOML parser
- bux add, bux install, bux.lock generation
- Dependency resolution with git/path sources
- Build pipeline merges dependency .bux sources

C Backend Fixes:
- resolveExprType(ekIdent) now applies typeSubst for generic params
- Method desugaring works for monomorphized generic receivers
- Pointer checks use isPointer (covers tkRef/tkMutRef)
- Field access on &T emits -> instead of .

Remove accidentally committed test binaries from tracking
This commit is contained in:
2026-05-31 23:48:45 +03:00
parent b1f1fc277c
commit 8e255b2125
21 changed files with 1360 additions and 111 deletions
+22 -2
View File
@@ -212,6 +212,9 @@ proc parseBaseType(p: var Parser): TypeExpr =
return TypeExpr(kind: tekPointer, loc: loc, pointerPointee: p.parseBaseType())
of tkAmp:
discard p.advance()
if p.check(tkMut):
discard p.advance()
return TypeExpr(kind: tekMutRef, loc: loc, pointerPointee: p.parseBaseType())
return TypeExpr(kind: tekRef, loc: loc, pointerPointee: p.parseBaseType())
of tkLParen:
discard p.advance()
@@ -894,11 +897,27 @@ proc parseStmt(p: var Parser): Stmt =
# Declarations
# ---------------------------------------------------------------------------
proc parseTypeParams(p: var Parser): seq[string] =
proc parseTypeParams(p: var Parser): seq[TypeParam] =
if p.check(tkLt):
discard p.advance()
while not p.check(tkGt) and not p.isAtEnd:
result.add(p.expect(tkIdent, "expected type parameter name").text)
let name = p.expect(tkIdent, "expected type parameter name").text
var bounds: seq[string] = @[]
if p.check(tkColon):
discard p.advance()
# Parse bound: single identifier or path like Std::Comparable
var boundName = ""
while true:
let part = p.expect(tkIdent, "expected trait/interface name").text
if boundName.len > 0:
boundName.add("_")
boundName.add(part)
if p.check(tkColonColon):
discard p.advance()
else:
break
bounds.add(boundName)
result.add(TypeParam(name: name, bounds: bounds))
if p.check(tkComma):
discard p.advance()
discard p.expect(tkGt, "expected '>' to close type parameters")
@@ -1241,6 +1260,7 @@ proc parseDecl(p: var Parser): Decl =
var attrs = ParsedAttrs()
if p.check(tkAt):
attrs = p.parseAttrs()
p.skipNewlines()
var isConst = false
if p.check(tkConst) and p.peek(1) == tkFunc: