suicmez/tests/arrays.c
2025-12-20 11:02:42 +02:00

68 lines
1.5 KiB
C

#include "libsuicmez/libsuicmez.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
void* gc_alloc(const TypeInfo* type, size_t size);
void gc_init(void);
void gc_shutdown(void);
// Helper for allocating arrays
static void* suic_alloc_array(const TypeInfo* type, size_t elem_size, size_t len, void* init_data) {
void* ptr = gc_alloc(type, elem_size * len);
if (init_data) memcpy(ptr, init_data, elem_size * len);
return ptr;
}
// Helper for allocating structs
static void* suic_alloc_struct(const TypeInfo* type, size_t size, void* init_data) {
void* ptr = gc_alloc(type, size);
if (init_data) memcpy(ptr, init_data, size);
return ptr;
}
struct Color {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
struct Shader {
int id;
};
static const uint8_t sui_bitmap_Color[] = { 0, 0, 0, 0 };
static const TypeInfo sui_typeinfo_Color = {
.field_count = 4,
.pointer_count = 0,
.pointer_bitmap = sui_bitmap_Color
};
static const uint8_t sui_bitmap_Shader[] = { 0 };
static const TypeInfo sui_typeinfo_Shader = {
.field_count = 1,
.pointer_count = 0,
.pointer_bitmap = sui_bitmap_Shader
};
int suic_main(void);
int suic_main(void) {
int* arr = suic_alloc_array(NULL, sizeof(int), 4, (int[]){1, 2, 3, 4});
int x = arr[2];
return x;
}
int main(int argc, char* argv[]) {
// Initialize GC
gc_init();
// init globals
// init event loop
int result = suic_main();
// Shutdown GC
gc_shutdown();
return result;
}