Add Slice<T> generic struct support and fix C backend generic filtering

- Add lib/Slice.bux with Slice<T> generic struct
- Fix C backend to recognize Slice/Slice* as generic types
- Use var instead of let for uninitialized Slice<T> locals
- Selfhost loop passes, tests pass
This commit is contained in:
2026-06-10 12:03:31 +03:00
parent 3a7b4bd5c1
commit 51bd3c172b
2 changed files with 32 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
module Std::Slice {
extern func bux_bounds_check(index: uint, len: uint);
struct Slice<T> {
data: *T,
len: uint,
}
func Slice_FromArray<T>(arr: *Array<T>) -> Slice<T> {
var s: Slice<T>;
s.data = arr.data;
s.len = arr.len;
return s;
}
func Slice_Get<T>(self: *Slice<T>, idx: uint) -> T {
bux_bounds_check(idx, self.len);
return self.data[idx];
}
func Slice_Set<T>(self: *Slice<T>, idx: uint, value: T) {
bux_bounds_check(idx, self.len);
self.data[idx] = value;
}
func Slice_Len<T>(self: *Slice<T>) -> uint {
return self.len;
}
}
+1
View File
@@ -683,6 +683,7 @@ func CBE_IsGenericTypeName(name: String) -> bool {
if String_Eq(name, "MapEntry") || String_Eq(name, "MapEntry*") { return true; } if String_Eq(name, "MapEntry") || String_Eq(name, "MapEntry*") { return true; }
if String_Eq(name, "StringMap") || String_Eq(name, "StringMap*") { return true; } if String_Eq(name, "StringMap") || String_Eq(name, "StringMap*") { return true; }
if String_Eq(name, "StringMapEntry") || String_Eq(name, "StringMapEntry*") { return true; } if String_Eq(name, "StringMapEntry") || String_Eq(name, "StringMapEntry*") { return true; }
if String_Eq(name, "Slice") || String_Eq(name, "Slice*") { return true; }
return false; return false;
} }