Dead strip by default. Add list to_string. Fix missing check for dynamic calls.

This commit is contained in:
Christoffer Lerno
2023-06-05 09:49:17 +02:00
committed by Christoffer Lerno
parent 4baacc7d52
commit 8eaad81800
17 changed files with 199 additions and 39 deletions

View File

@@ -38,6 +38,26 @@ fn void List.tinit(List* list, usz initial_capacity = 16)
list.init(initial_capacity, mem::temp()) @inline;
}
fn String List.to_string(List* list, Allocator* using = mem::heap()) @dynamic
{
if (!list.size) return "[]".copy(using);
if (list.size == 1) return string::printf("[%s]", list.entries[0], .using = using);
@stack_mem(512 + 128; Allocator* mem)
{
DString str;
str.init(512, mem);
str.append("[");
foreach (i, element : list.entries[:list.size])
{
if (i != 0) str.append(", ");
str.printf("%s", element);
}
str.printf("]");
return str.copy_str(using);
};
}
fn void List.push(List* list, Type element) @inline
{
list.append(element);