Indexing into a constant array / struct now works at compile time. Constants defined by indexing into another constant could fail codegen. Stdlib nolibc code bugs fixed.

This commit is contained in:
Christoffer Lerno
2024-07-20 01:20:03 +02:00
parent 7f5757d66b
commit b25c573ae3
18 changed files with 315 additions and 119 deletions

View File

@@ -54,6 +54,32 @@ fn List* List.temp_init(&self, usz initial_capacity = 16)
return self.new_init(initial_capacity, allocator::temp()) @inline;
}
/**
* Initialize a new list with an array.
*
* @param [in] values `The values to initialize the list with.`
* @require self.size == 0 "The List must be empty"
**/
fn List* List.new_init_with_array(&self, Type[] values, Allocator allocator = allocator::heap())
{
self.new_init(values.len, allocator) @inline;
self.add_array(values) @inline;
return self;
}
/**
* Initialize a temporary list with an array.
*
* @param [in] values `The values to initialize the list with.`
* @require self.size == 0 "The List must be empty"
**/
fn List* List.temp_init_with_array(&self, Type[] values)
{
self.temp_init(values.len) @inline;
self.add_array(values) @inline;
return self;
}
/**
* @require self.size == 0 "The List must be empty"
**/
@@ -192,6 +218,12 @@ fn Type[] List.array_view(&self)
return self.entries[:self.size];
}
/**
* Add the values of an array to this list.
*
* @param [in] array
* @ensure self.size >= array.len
**/
fn void List.add_array(&self, Type[] array)
{
if (!array.len) return;