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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user