Add code generation for array
This commit is contained in:
18
codegen/array/snippets/alloc_capacity
Normal file
18
codegen/array/snippets/alloc_capacity
Normal file
@@ -0,0 +1,18 @@
|
||||
u64 allocation_size = sizeof({ArrayType}) + sizeof({T}) * capacity;
|
||||
{ArrayType} *array = NULL;
|
||||
|
||||
if (!allocator) {{
|
||||
goto RETURN_{Tupper}_ARRAY_ALLOC;
|
||||
}}
|
||||
|
||||
array = wapp_mem_allocator_alloc(allocator, allocation_size);
|
||||
if (!array) {{
|
||||
goto RETURN_{Tupper}_ARRAY_ALLOC;
|
||||
}}
|
||||
|
||||
array->items = ({T} *)((u8 *)array + sizeof({ArrayType}));
|
||||
array->count = 0;
|
||||
array->capacity = capacity;
|
||||
|
||||
RETURN_{Tupper}_ARRAY_ALLOC:
|
||||
return array;
|
Reference in New Issue
Block a user