feat: add generics support with monomorphization

- Add ekGenericCall to AST for generic function calls (Max<int>)
- Parse generic type arguments in parsePostfix
- Support generic calls in sema with type parameter substitution
- Implement monomorphization in hir_lower:
  - Collect generic function declarations
  - Find all generic call sites
  - Generate specialized versions with mangled names (Max_int)
  - Substitute type parameters with concrete types
- Add generics.bux example

Example:
  func Max<T>(a: T, b: T) -> T {
      if a > b { return a; }
      else { return b; }
  }

  let m: int = Max<int>(10, 20);  // Generates Max_int
This commit is contained in:
2026-05-31 00:22:03 +03:00
parent cf074bec89
commit aa3433b5a9
5 changed files with 245 additions and 23 deletions
+4
View File
@@ -104,6 +104,7 @@ type
ekTernary
ekRange
ekCall
ekGenericCall
ekIndex
ekField
ekStructInit
@@ -160,6 +161,9 @@ type
of ekCall:
exprCallCallee*: Expr
exprCallArgs*: seq[Expr]
of ekGenericCall:
exprGenericCallee*: string
exprGenericTypeArgs*: seq[TypeExpr]
of ekIndex:
exprIndexObj*: Expr
exprIndexIdx*: Expr