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;

View File

@@ -384,7 +384,7 @@ File stderr_file;
fn void putchar(char c) @inline
{
(void)stdout_file.putc(c);
(void)stdout_file.write_byte(c);
}
fn File* stdout()

View File

@@ -24,6 +24,7 @@ fn Path! native_temp_directory(Allocator allocator = allocator::heap()) @if(env:
}
module std::io::os @if(env::NO_LIBC);
import std::io::path;
macro Path! native_temp_directory(Allocator allocator = allocator::heap())
{

View File

@@ -60,7 +60,7 @@ fn double __tan(double x, double y, int odd) @extern("__tan") @weak @nostrip
w = x + r;
if (big)
{
s = 1 - 2 * odd;
s = (double)(1 - 2 * odd);
v = s - 2.0 * (x + (r - w*w/(w + s)));
return sign ? -v : v;
}

View File

@@ -63,7 +63,7 @@ fn int __rem_pio2f(float x, double *y)
if (ix >= 0x7f800000)
{
// x is inf or NaN */
*y = x-x;
*y = x - (double)x;
return 0;
}
/* scale x into [2^23, 2^24-1] */