rename intrinsics

This commit is contained in:
2026-07-14 19:22:20 +02:00
parent 471896b48a
commit 5157cf3bcc
26 changed files with 107640 additions and 106418 deletions
+3 -3
View File
@@ -30,8 +30,8 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
new_capacity usize = 8
if list.capacity >= 8 {
half usize :: div_trunc(list.capacity, 2)
if list.capacity > max_value(usize) - half {
half usize :: divtrunc!(list.capacity, 2)
if list.capacity > maxval!(usize) - half {
new_capacity = minimum_capacity
} else {
new_capacity = list.capacity + half
@@ -53,7 +53,7 @@ reserve func($T type, list @mut ArrayList(T), minimum_capacity usize) void ! mem
append func($T type, list @mut ArrayList(T), value T) void ! mem.AllocError {
length usize :: list.items.len
if length == max_value(usize) {
if length == maxval!(usize) {
return .out_of_memory
}
try reserve(list, length + 1)
+2 -2
View File
@@ -76,7 +76,7 @@ write_all func(writer Writer, bytes []u8) void ! WriteError {
_system_read func(_ ?*mut anyopaque, stream ReadStream, buffer []mut u8) usize ! ReadError {
request usize = buffer.len
maximum usize :: usize(max_value(c_long))
maximum usize :: usize(maxval!(c_long))
if request > maximum {
request = maximum
}
@@ -94,7 +94,7 @@ _system_read func(_ ?*mut anyopaque, stream ReadStream, buffer []mut u8) usize !
_system_write func(_ ?*mut anyopaque, stream WriteStream, bytes []u8) usize ! WriteError {
fd c_int :: c_int(stream)
request usize = bytes.len
maximum usize :: usize(max_value(c_long))
maximum usize :: usize(maxval!(c_long))
if request > maximum {
request = maximum
}
+16 -16
View File
@@ -44,7 +44,7 @@ eql func($T type, left, right []T) bool {
_empty_storage [1]mut u64 = [0]
_empty_slice func($T type, count usize) []mut T {
pointer *mut T :: ptr_cast(T, (&_empty_storage).ptr)
pointer *mut T :: ptrcast!(T, (&_empty_storage).ptr)
return pointer[..count]
}
@@ -57,17 +57,17 @@ alloc func($T type, allocator Allocator, count usize) []mut T ! AllocError {
return _empty_slice(T, 0)
}
element_size usize :: size_of(T)
element_size usize :: sizeof!(T)
if element_size == 0 {
return _empty_slice(T, count)
}
if count > div_trunc(max_value(usize), element_size) {
if count > divtrunc!(maxval!(usize), element_size) {
return .out_of_memory
}
memory ?*mut u8 = raw_alloc(allocator, count * element_size, align_of(T))
memory ?*mut u8 = raw_alloc(allocator, count * element_size, alignof!(T))
if memory |bytes| {
pointer *mut T :: ptr_cast(T, bytes)
pointer *mut T :: ptrcast!(T, bytes)
return pointer[..count]
}
return .out_of_memory
@@ -82,18 +82,18 @@ realloc func($T type, allocator Allocator, memory []mut T, new_count usize) []mu
return _empty_slice(T, 0)
}
element_size usize :: size_of(T)
element_size usize :: sizeof!(T)
if element_size == 0 {
return _empty_slice(T, new_count)
}
if new_count > div_trunc(max_value(usize), element_size) {
if new_count > divtrunc!(maxval!(usize), element_size) {
return .out_of_memory
}
old_memory ?*mut u8 = none
old_size usize = 0
if memory.len != 0 {
old_memory = ptr_cast(u8, memory.ptr)
old_memory = ptrcast!(u8, memory.ptr)
old_size = memory.len * element_size
}
resized ?*mut u8 = raw_realloc(
@@ -101,18 +101,18 @@ realloc func($T type, allocator Allocator, memory []mut T, new_count usize) []mu
old_memory,
old_size,
new_count * element_size,
align_of(T),
alignof!(T),
)
if resized |bytes| {
pointer *mut T :: ptr_cast(T, bytes)
pointer *mut T :: ptrcast!(T, bytes)
return pointer[..new_count]
}
return .out_of_memory
}
free func($T type, allocator Allocator, memory []mut T) void {
if memory.len != 0 and size_of(T) != 0 {
raw_free(allocator, ptr_cast(u8, memory.ptr), memory.len * size_of(T), align_of(T))
if memory.len != 0 and sizeof!(T) != 0 {
raw_free(allocator, ptrcast!(u8, memory.ptr), memory.len * sizeof!(T), alignof!(T))
}
}
@@ -125,7 +125,7 @@ _power_of_two func(value usize) bool {
current usize = value
while current > 1 {
half usize = div_trunc(current, 2)
half usize = divtrunc!(current, 2)
if half * 2 != current {
return false
}
@@ -141,7 +141,7 @@ _c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
}
if alignment <= _malloc_alignment {
return ptr_cast(u8, c.malloc(c_ulong(size)))
return ptrcast!(u8, c.malloc(c_ulong(size)))
}
memory [1]mut ?*mut anyopaque = [none]
@@ -150,7 +150,7 @@ _c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
return none
}
return ptr_cast(u8, memory[0])
return ptrcast!(u8, memory[0])
}
_c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size usize, alignment usize) ?*mut u8 {
@@ -165,7 +165,7 @@ _c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size usi
if memory |old_memory| {
if alignment <= _malloc_alignment {
return ptr_cast(u8, c.realloc(old_memory, c_ulong(new_size)))
return ptrcast!(u8, c.realloc(old_memory, c_ulong(new_size)))
}
new_memory ?*mut u8 = _c_alloc(none, new_size, alignment)
+10 -10
View File
@@ -30,7 +30,7 @@ raw_free func(allocator Allocator, memory ?*mut u8, size usize, alignment usize)
_empty_storage [1]mut u64 = [0]
_empty_slice func($T type, count usize) []mut T {
pointer *mut T :: ptr_cast(T, (&_empty_storage).ptr)
pointer *mut T :: ptrcast!(T, (&_empty_storage).ptr)
return pointer[..count]
}
@@ -39,25 +39,25 @@ alloc func($T type, allocator Allocator, count usize) []mut T ! AllocError {
return _empty_slice(T, 0)
}
element_size usize :: size_of(T)
element_size usize :: sizeof!(T)
if element_size == 0 {
return _empty_slice(T, count)
}
if count > max_value(usize) / element_size {
if count > maxval!(usize) / element_size {
return .out_of_memory
}
memory ?*mut u8 = raw_alloc(allocator, count * element_size, align_of(T))
memory ?*mut u8 = raw_alloc(allocator, count * element_size, alignof!(T))
if memory |bytes| {
pointer *mut T :: ptr_cast(T, bytes)
pointer *mut T :: ptrcast!(T, bytes)
return pointer[..count]
}
return .out_of_memory
}
free func($T type, allocator Allocator, memory []mut T) void {
if memory.len != 0 and size_of(T) != 0 {
raw_free(allocator, ptr_cast(u8, memory.ptr), memory.len * size_of(T), align_of(T))
if memory.len != 0 and sizeof!(T) != 0 {
raw_free(allocator, ptrcast!(u8, memory.ptr), memory.len * sizeof!(T), alignof!(T))
}
}
@@ -86,7 +86,7 @@ _c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
}
if alignment <= _malloc_alignment {
return ptr_cast(u8, c.malloc(c_ulong(size)))
return ptrcast!(u8, c.malloc(c_ulong(size)))
}
memory [1]mut ?*mut anyopaque = [none]
@@ -95,7 +95,7 @@ _c_alloc func(_ ?*mut anyopaque, size usize, alignment usize) ?*mut u8 {
return none
}
return ptr_cast(u8, memory[0])
return ptrcast!(u8, memory[0])
}
_c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size usize, alignment usize) ?*mut u8 {
@@ -110,7 +110,7 @@ _c_realloc func(_ ?*mut anyopaque, memory ?*mut u8, old_size usize, new_size usi
if memory |old_memory| {
if alignment <= _malloc_alignment {
return ptr_cast(u8, c.realloc(old_memory, c_ulong(new_size)))
return ptrcast!(u8, c.realloc(old_memory, c_ulong(new_size)))
}
new_memory ?*mut u8 = _c_alloc(none, new_size, alignment)