Skip to content

Commit

Permalink
[Core] Standardise number types to int32_t for array indices, lengths…
Browse files Browse the repository at this point in the history
… and capacities (#152)
  • Loading branch information
nicbarker authored Jan 2, 2025
1 parent a44423a commit cf12cd6
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 226 deletions.
6 changes: 3 additions & 3 deletions bindings/odin/clay-odin/clay.odin
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ when ODIN_OS == .Windows {
}

String :: struct {
length: c.int,
length: c.int32_t,
chars: [^]c.char,
}

Expand Down Expand Up @@ -258,8 +258,8 @@ LayoutConfig :: struct {
}

ClayArray :: struct($type: typeid) {
capacity: u32,
length: u32,
capacity: i32,
length: i32,
internalArray: [^]type,
}

Expand Down
Binary file modified bindings/odin/clay-odin/linux/clay.a
Binary file not shown.
Binary file modified bindings/odin/clay-odin/macos-arm64/clay.a
Binary file not shown.
Binary file modified bindings/odin/clay-odin/macos/clay.a
Binary file not shown.
Binary file modified bindings/odin/clay-odin/wasm/clay.o
Binary file not shown.
Binary file modified bindings/odin/clay-odin/windows/clay.lib
Binary file not shown.
420 changes: 210 additions & 210 deletions clay.h

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions examples/clay-official-website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
}
case 'float': return 4;
case 'uint32_t': return 4;
case 'int32_t': return 4;
case 'uint16_t': return 2;
case 'uint8_t': return 1;
case 'bool': return 1;
Expand Down Expand Up @@ -206,6 +207,7 @@
}
case 'float': return { value: memoryDataView.getFloat32(address, true), __size: 4 };
case 'uint32_t': return { value: memoryDataView.getUint32(address, true), __size: 4 };
case 'int32_t': return { value: memoryDataView.getUint32(address, true), __size: 4 };
case 'uint16_t': return { value: memoryDataView.getUint16(address, true), __size: 2 };
case 'uint8_t': return { value: memoryDataView.getUint8(address, true), __size: 1 };
case 'bool': return { value: memoryDataView.getUint8(address, true), __size: 1 };
Expand Down Expand Up @@ -312,7 +314,6 @@

const importObject = {
clay: {

measureTextFunction: (addressOfDimensions, textToMeasure, addressOfConfig) => {
let stringLength = memoryDataView.getUint32(textToMeasure, true);
let pointerToString = memoryDataView.getUint32(textToMeasure + 4, true);
Expand Down Expand Up @@ -358,8 +359,8 @@
}

function renderLoopHTML() {
let capacity = memoryDataView.getUint32(scratchSpaceAddress, true);
let length = memoryDataView.getUint32(scratchSpaceAddress + 4, true);
let capacity = memoryDataView.getInt32(scratchSpaceAddress, true);
let length = memoryDataView.getInt32(scratchSpaceAddress + 4, true);
let arrayOffset = memoryDataView.getUint32(scratchSpaceAddress + 8, true);
let scissorStack = [{ nextAllocation: { x: 0, y: 0 }, element: htmlRoot, nextElementIndex: 0 }];
let previousId = 0;
Expand Down
2 changes: 1 addition & 1 deletion generator/array_allocate.template.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$NAME$ $NAME$_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__ALIGNMENT($TYPE$), arena)};
}
2 changes: 1 addition & 1 deletion generator/array_allocate_pointer.template.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$NAME$ $NAME$_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
$NAME$ $NAME$_Allocate_Arena(int32_t capacity, Clay_Arena *arena) {
return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__POINTER_ALIGNMENT, arena)};
}
4 changes: 2 additions & 2 deletions generator/array_define.template.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CLAY__TYPEDEF($NAME$, struct
{
uint32_t capacity;
uint32_t length;
int32_t capacity;
int32_t length;
$TYPE$ *internalArray;
});
2 changes: 1 addition & 1 deletion generator/array_define_slice.template.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CLAY__TYPEDEF($NAME$Slice, struct
{
uint32_t length;
int32_t length;
$TYPE$ *internalArray;
});
2 changes: 1 addition & 1 deletion generator/array_get.template.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$TYPE$ *$NAME$_Get($NAME$ *array, int index) {
$TYPE$ *$NAME$_Get($NAME$ *array, int32_t index) {
return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : $DEFAULT_VALUE$;
}
2 changes: 1 addition & 1 deletion generator/array_get_slice.template.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$TYPE$ *$NAME$Slice_Get($NAME$Slice *slice, int index) {
$TYPE$ *$NAME$Slice_Get($NAME$Slice *slice, int32_t index) {
return Clay__Array_RangeCheck(index, slice->length) ? &slice->internalArray[index] : $DEFAULT_VALUE$;
}
2 changes: 1 addition & 1 deletion generator/array_get_value.template.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$TYPE$ $NAME$_Get($NAME$ *array, int index) {
$TYPE$ $NAME$_Get($NAME$ *array, int32_t index) {
return Clay__Array_RangeCheck(index, array->length) ? array->internalArray[index] : $DEFAULT_VALUE$;
}
2 changes: 1 addition & 1 deletion generator/array_remove_swapback.template.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$TYPE$ $NAME$_RemoveSwapback($NAME$ *array, int index) {
$TYPE$ $NAME$_RemoveSwapback($NAME$ *array, int32_t index) {
if (Clay__Array_RangeCheck(index, array->length)) {
array->length--;
$TYPE$ removed = array->internalArray[index];
Expand Down
2 changes: 1 addition & 1 deletion generator/array_set.template.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void $NAME$_Set($NAME$ *array, int index, $TYPE$ value) {
void $NAME$_Set($NAME$ *array, int32_t index, $TYPE$ value) {
if (Clay__Array_RangeCheck(index, array->capacity)) {
array->internalArray[index] = value;
array->length = index < array->length ? array->length : index + 1;
Expand Down

0 comments on commit cf12cd6

Please sign in to comment.