This commit is contained in:
agra
2026-02-11 01:43:30 +02:00
parent 25e1372731
commit 89fc6427c4
6 changed files with 236 additions and 27 deletions

View File

@@ -1,12 +1,32 @@
#import "modules/std.sx";
List :: struct ($T: Type) {
items: [*]T = .[];
len: s32 = 0;
cap: s32 = 0;
items: [*]T = null;
len: s64 = 0;
cap: s64 = 0;
}
append :: (list: *List($T), item: T) {
if list.len >= list.cap {
new_cap := if list.cap == 0 then 4 else list.cap * 2;
new_items : [*]T = xx malloc(new_cap * size_of(T));
if list.len > 0 {
memcpy(new_items, list.items, list.len * size_of(T));
free(list.items);
}
list.items = new_items;
list.cap = new_cap;
}
list.items[list.len] = item;
list.len += 1;
}
main :: () {
list := List(s32).{};
append(list, 3);
append(list, 1);
append(list, 4);
append(list, 1);
append(list, 5);
print("{}\n", list);
}

View File

@@ -194,7 +194,9 @@ slice_to_string :: (items: []$T) -> string {
pointer_to_string :: (p: $T) -> string {
addr : s64 = xx p;
concat(type_name(T), concat("@", int_to_hex_string(addr)));
if addr == 0 { "null"; } else {
concat(type_name(T), concat("@0x", int_to_hex_string(addr)));
}
}
union_to_string :: (u: $T) -> string {