Consistent naming in allocators. Fix where cast from char array -> bitstruct would not work.

This commit is contained in:
Christoffer Lerno
2023-05-10 10:30:37 +02:00
parent 6210522c75
commit 4d0f73a8f5
8 changed files with 24 additions and 18 deletions

View File

@@ -184,7 +184,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [15, 16]
llvm_version: [16]
steps:
- uses: actions/checkout@v3

View File

@@ -17,19 +17,19 @@ struct DynamicArenaAllocator
* @require page_size >= 128
* @require this != null
**/
fn void DynamicArenaAllocator.init(DynamicArenaAllocator* this, usz page_size, Allocator* backing_allocator = mem::heap())
fn void DynamicArenaAllocator.init(DynamicArenaAllocator* this, usz page_size, Allocator* using = mem::heap())
{
this.function = &dynamic_arena_allocator_function;
this.page = null;
this.unused_page = null;
this.page_size = page_size;
this.backing_allocator = backing_allocator;
this.backing_allocator = using;
}
/**
* @require this != null
**/
fn void DynamicArenaAllocator.destroy(DynamicArenaAllocator* this)
fn void DynamicArenaAllocator.free(DynamicArenaAllocator* this)
{
DynamicArenaPage* page = this.page;
while (page)
@@ -67,7 +67,7 @@ struct DynamicArenaChunk @local
* @require ptr && this
* @require this.page `tried to free pointer on invalid allocator`
*/
fn void DynamicArenaAllocator.free(DynamicArenaAllocator* this, void* ptr) @private
fn void DynamicArenaAllocator.free_ptr(DynamicArenaAllocator* this, void* ptr) @private
{
DynamicArenaPage* current_page = this.page;
if (ptr == current_page.last_ptr)
@@ -226,7 +226,7 @@ fn void*! dynamic_arena_allocator_function(Allocator* data, usz size, usz alignm
if (!size)
{
if (!old_pointer) return null;
allocator.free(old_pointer);
allocator.free_ptr(old_pointer);
return null;
}
if (!old_pointer) return allocator._alloc(size, alignment, offset);
@@ -235,7 +235,7 @@ fn void*! dynamic_arena_allocator_function(Allocator* data, usz size, usz alignm
case ALIGNED_FREE:
case FREE:
if (!old_pointer) return null;
allocator.free(old_pointer);
allocator.free_ptr(old_pointer);
return null;
case MARK:
unreachable("Tried to mark a dynamic arena");

View File

@@ -37,12 +37,12 @@ macro bool TempAllocatorPage.is_aligned(TempAllocatorPage* page) => page.size &
/**
* @require size >= 16
**/
fn TempAllocator*! new_temp(usz size, Allocator* backing_allocator)
fn TempAllocator*! new_temp(usz size, Allocator* using)
{
TempAllocator* allocator = malloc_checked(TempAllocator, .using = backing_allocator, .end_padding = size)!;
TempAllocator* allocator = malloc_checked(TempAllocator, .using = using, .end_padding = size)!;
allocator.last_page = null;
allocator.function = &temp_allocator_function;
allocator.backing_allocator = backing_allocator;
allocator.backing_allocator = using;
allocator.used = 0;
allocator.capacity = size;
return allocator;

View File

@@ -24,10 +24,10 @@ struct TrackingAllocator
*
* @require this != null
**/
fn void TrackingAllocator.init(TrackingAllocator* this, Allocator* allocator)
fn void TrackingAllocator.init(TrackingAllocator* this, Allocator* using)
{
*this = { .inner_allocator = allocator, .allocator.function = &tracking_allocator_fn };
this.map.init(.using = allocator);
*this = { .inner_allocator = using, .allocator.function = &tracking_allocator_fn };
this.map.init(.using = using);
}
fn void TrackingAllocator.free(TrackingAllocator* this)

View File

@@ -109,7 +109,7 @@ fn usz! File.write(File file, char[] buffer)
* @param [&in] file
* @require file.file `File must be initialized`
*/
fn usz! File.printn(File file, String string)
fn usz! File.printn(File file, String string = "")
{
usz len = file.print(string)!;
if (!libc::putc('\n', file.file)) return IoError.UNKNOWN_ERROR?;

View File

@@ -329,7 +329,7 @@ struct Type_
void *backend_debug_type;
union
{
// Error, Struct, Union, Typedef, Member
// Error, Struct, Union, Typedef, Member, Bitstruct
Decl *decl;
// int, float, bool
TypeBuiltin builtin;
@@ -341,8 +341,6 @@ struct Type_
Type *pointer;
// Optional
Type *optional;
// Bitstruct
Type *bitstruct;
};
};

View File

@@ -1162,6 +1162,9 @@ static bool cast_from_array(SemaContext *context, Expr *expr, Type *from, Type *
// Len must be checked.
if (to->array.len != from->array.len) return sema_error_cannot_convert(expr, to_type, false, silent);
break;
case TYPE_BITSTRUCT:
if (to->decl->bitstruct.base_type->type->canonical == from) return cast_with_optional(expr, to_type, add_optional);
FALLTHROUGH;
default:
// No other conversions are allowed.
return sema_error_cannot_convert(expr, to_type, false, silent);
@@ -1891,6 +1894,11 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type)
return false;
case TYPE_ARRAY:
if (to->type_kind == TYPE_VECTOR) return array_to_vector(expr, to_type);
if (to->type_kind == TYPE_BITSTRUCT)
{
expr->type = to_type;
return true;
}
FALLTHROUGH;
case TYPE_STRUCT:
case TYPE_UNION:

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.507"
#define COMPILER_VERSION "0.4.508"