selfhost: add *_Drop wrappers to stdlib types; auto-drop uses _Drop instead of _Free
- Array.bux, Channel.bux, Set.bux, Map.bux: add *_Drop<T> delegating to *_Free - hir_lower.bux: Lcx_BuildAutoDropFree searches for _Drop suffix instead of _Free - Skip direct lowering of generic functions (only monomorphized instances)
This commit is contained in:
@@ -46,4 +46,8 @@ func Array_Free<T>(self: *Array<T>) {
|
|||||||
self.cap = 0;
|
self.cap = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Array_Drop<T>(self: *Array<T>) {
|
||||||
|
Array_Free<T>(self);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ func Channel_Free<T>(ch: *Channel<T>) {
|
|||||||
bux_channel_free(ch.handle);
|
bux_channel_free(ch.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Channel_Drop<T>(ch: *Channel<T>) {
|
||||||
|
Channel_Free<T>(ch);
|
||||||
|
}
|
||||||
|
|
||||||
/* Convenience wrappers for common types */
|
/* Convenience wrappers for common types */
|
||||||
func Channel_SendInt(ch: *Channel<int>, value: int) {
|
func Channel_SendInt(ch: *Channel<int>, value: int) {
|
||||||
bux_channel_send(ch.handle, (&value) as *void);
|
bux_channel_send(ch.handle, (&value) as *void);
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ func Map_Free<K, V>(m: *Map<K, V>) {
|
|||||||
m.len = 0;
|
m.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Map_Drop<K, V>(m: *Map<K, V>) {
|
||||||
|
Map_Free<K, V>(m);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// StringMap<V> — specialized Map for String keys, using strcmp
|
// StringMap<V> — specialized Map for String keys, using strcmp
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -68,4 +68,8 @@ func Set_Free<T>(s: *Set<T>) {
|
|||||||
s.len = 0;
|
s.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Set_Drop<T>(s: *Set<T>) {
|
||||||
|
Set_Free<T>(s);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-5
@@ -2104,11 +2104,16 @@ func Lcx_EvalConstExpr(ctx: *LowerCtx, expr: *Expr) -> int {
|
|||||||
func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
||||||
if String_StartsWith(typeName, "Array_") {
|
if String_StartsWith(typeName, "Array_") {
|
||||||
let elemType: String = bux_str_slice(typeName, 6, bux_strlen(typeName) - 6);
|
let elemType: String = bux_str_slice(typeName, 6, bux_strlen(typeName) - 6);
|
||||||
|
// Ensure inner free is also monomorphized since Drop calls Free
|
||||||
let genFree: *Decl = Lcx_FindGenericFunc(ctx, "Array_Free");
|
let genFree: *Decl = Lcx_FindGenericFunc(ctx, "Array_Free");
|
||||||
if genFree != null as *Decl {
|
if genFree != null as *Decl {
|
||||||
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
||||||
}
|
}
|
||||||
return String_Concat("Array_Free_", elemType);
|
let genDrop: *Decl = Lcx_FindGenericFunc(ctx, "Array_Drop");
|
||||||
|
if genDrop != null as *Decl {
|
||||||
|
Lcx_GenerateFuncInstance(ctx, genDrop, elemType, "", 1);
|
||||||
|
}
|
||||||
|
return String_Concat("Array_Drop_", elemType);
|
||||||
}
|
}
|
||||||
if String_StartsWith(typeName, "Channel_") {
|
if String_StartsWith(typeName, "Channel_") {
|
||||||
let elemType: String = bux_str_slice(typeName, 8, bux_strlen(typeName) - 8);
|
let elemType: String = bux_str_slice(typeName, 8, bux_strlen(typeName) - 8);
|
||||||
@@ -2116,7 +2121,11 @@ func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
|||||||
if genFree != null as *Decl {
|
if genFree != null as *Decl {
|
||||||
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
||||||
}
|
}
|
||||||
return String_Concat("Channel_Free_", elemType);
|
let genDrop: *Decl = Lcx_FindGenericFunc(ctx, "Channel_Drop");
|
||||||
|
if genDrop != null as *Decl {
|
||||||
|
Lcx_GenerateFuncInstance(ctx, genDrop, elemType, "", 1);
|
||||||
|
}
|
||||||
|
return String_Concat("Channel_Drop_", elemType);
|
||||||
}
|
}
|
||||||
if String_StartsWith(typeName, "Set_") {
|
if String_StartsWith(typeName, "Set_") {
|
||||||
let elemType: String = bux_str_slice(typeName, 4, bux_strlen(typeName) - 4);
|
let elemType: String = bux_str_slice(typeName, 4, bux_strlen(typeName) - 4);
|
||||||
@@ -2124,7 +2133,11 @@ func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
|||||||
if genFree != null as *Decl {
|
if genFree != null as *Decl {
|
||||||
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
Lcx_GenerateFuncInstance(ctx, genFree, elemType, "", 1);
|
||||||
}
|
}
|
||||||
return String_Concat("Set_Free_", elemType);
|
let genDrop: *Decl = Lcx_FindGenericFunc(ctx, "Set_Drop");
|
||||||
|
if genDrop != null as *Decl {
|
||||||
|
Lcx_GenerateFuncInstance(ctx, genDrop, elemType, "", 1);
|
||||||
|
}
|
||||||
|
return String_Concat("Set_Drop_", elemType);
|
||||||
}
|
}
|
||||||
if String_StartsWith(typeName, "Map_") {
|
if String_StartsWith(typeName, "Map_") {
|
||||||
let rest: String = bux_str_slice(typeName, 4, bux_strlen(typeName) - 4);
|
let rest: String = bux_str_slice(typeName, 4, bux_strlen(typeName) - 4);
|
||||||
@@ -2144,7 +2157,11 @@ func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
|||||||
if genFree != null as *Decl {
|
if genFree != null as *Decl {
|
||||||
Lcx_GenerateFuncInstance(ctx, genFree, kType, vType, 2);
|
Lcx_GenerateFuncInstance(ctx, genFree, kType, vType, 2);
|
||||||
}
|
}
|
||||||
return String_Concat(String_Concat("Map_Free_", kType), String_Concat("_", vType));
|
let genDrop: *Decl = Lcx_FindGenericFunc(ctx, "Map_Drop");
|
||||||
|
if genDrop != null as *Decl {
|
||||||
|
Lcx_GenerateFuncInstance(ctx, genDrop, kType, vType, 2);
|
||||||
|
}
|
||||||
|
return String_Concat(String_Concat("Map_Drop_", kType), String_Concat("_", vType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
@@ -2236,7 +2253,7 @@ func HirLower_LowerModule(mod: *Module, sema: *Sema) -> *HirModule {
|
|||||||
}
|
}
|
||||||
hm.structCount = hm.structCount + 1;
|
hm.structCount = hm.structCount + 1;
|
||||||
}
|
}
|
||||||
if decl.kind == dkFunc && decl.refBody != null as *Block {
|
if decl.kind == dkFunc && decl.refBody != null as *Block && decl.typeParamCount == 0 {
|
||||||
let f: *HirFunc = Lcx_LowerFunc(ctx, decl);
|
let f: *HirFunc = Lcx_LowerFunc(ctx, decl);
|
||||||
ctx.funcs[ctx.funcCount] = *f;
|
ctx.funcs[ctx.funcCount] = *f;
|
||||||
ctx.funcCount = ctx.funcCount + 1;
|
ctx.funcCount = ctx.funcCount + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user