selfhost: add lib/Drop.bux with interface Drop; extend methods visible in scope
- lib/Drop.bux: interface Drop { func Drop(self: *Self); }
- sema.bux: define TypeName_MethodName in scope for impl block methods
so auto-drop (Lcx_BuildAutoDropFree) can find Drop implementations
via extend Type for Drop, not just @[Drop] or standalone functions
- Verified: extend Buffer for Drop auto-calls Buffer_Drop in @[Checked]
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
// Drop trait — automatic cleanup for heap-allocated or resource-holding types
|
||||||
|
interface Drop {
|
||||||
|
func Drop(self: *Self);
|
||||||
|
}
|
||||||
+14
-1
@@ -1148,12 +1148,25 @@ func Sema_CollectGlobals(sema: *Sema) {
|
|||||||
let implTypeName: String = decl.strValue;
|
let implTypeName: String = decl.strValue;
|
||||||
var m: *Decl = decl.childDecl1;
|
var m: *Decl = decl.childDecl1;
|
||||||
while m != null as *Decl {
|
while m != null as *Decl {
|
||||||
if m.kind == dkFunc && sema.methodCount < 256 {
|
if m.kind == dkFunc {
|
||||||
|
if sema.methodCount < 256 {
|
||||||
sema.methodEntries[sema.methodCount].typeName = implTypeName;
|
sema.methodEntries[sema.methodCount].typeName = implTypeName;
|
||||||
sema.methodEntries[sema.methodCount].methodName = m.strValue;
|
sema.methodEntries[sema.methodCount].methodName = m.strValue;
|
||||||
sema.methodEntries[sema.methodCount].decl = m;
|
sema.methodEntries[sema.methodCount].decl = m;
|
||||||
sema.methodCount = sema.methodCount + 1;
|
sema.methodCount = sema.methodCount + 1;
|
||||||
}
|
}
|
||||||
|
// Also define TypeName_MethodName in scope so auto-drop can find it
|
||||||
|
let methodSymName: String = String_Concat(implTypeName, "_");
|
||||||
|
let methodSymName2: String = String_Concat(methodSymName, m.strValue);
|
||||||
|
var methodSym: Symbol;
|
||||||
|
Sema_ZeroInitSymbol(&methodSym);
|
||||||
|
methodSym.kind = skFunc;
|
||||||
|
methodSym.name = methodSymName2;
|
||||||
|
methodSym.typeKind = tyFunc;
|
||||||
|
methodSym.isPublic = decl.isPublic;
|
||||||
|
methodSym.decl = m;
|
||||||
|
discard Scope_Define(sema.scope, methodSym);
|
||||||
|
}
|
||||||
m = m.childDecl2;
|
m = m.childDecl2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user