feat: generic methods on generic structs + method call auto-addressing

- Auto-register func Type_Method<T>(self: *Type<T>) as methods in sema
- Add type param awareness to sema resolveType for generic function bodies
- Add lazy monomorphization for generic struct method calls in HIR lowering
- Track varTypeExprs in LowerCtx for local variable type inference
- Fix ekSelf in both sema and hir_lower to resolve actual parameter type
- Fix lowerFunc to use substituteType for param/return types (handles pointers to generic structs)
- Auto-address value receivers when method expects pointer (e.g., b.Get() where self: *Box<T>)
- Add C forward declarations for all functions to fix ordering issues
- Relax type checks for tkTypeParam in assignments and arguments
- Update generics_struct example with Box_Get, Box_Set, Pair_GetFirst/Second
This commit is contained in:
2026-05-31 11:57:52 +03:00
parent 9f733aca7d
commit af14f392f6
5 changed files with 220 additions and 35 deletions
+11
View File
@@ -490,6 +490,17 @@ proc emitModule*(be: var CBackend, module: HirModule): string =
for e in module.enums:
be.emitEnum(e.name, e.variants)
# Forward declarations for all functions
for f in module.funcs:
let retType = typeToC(f.retType)
var params: seq[string] = @[]
for p in f.params:
params.add(typeToC(p.typ) & " " & p.name)
if params.len == 0:
params.add("void")
be.emitLine(retType & " " & f.name & "(" & params.join(", ") & ");")
be.emitLine("")
# Function definitions
var hasMain = false
for f in module.funcs: