This commit is contained in:
Masashi 2025-12-17 21:22:00 +05:30
commit 4a85a0008c
3 changed files with 49 additions and 2 deletions

47
tests/arrays.c Normal file
View file

@ -0,0 +1,47 @@
#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;
}
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[0];
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;
}

BIN
tests/arrays.o Executable file

Binary file not shown.

View file

@ -1,7 +1,7 @@
# Array test # Array test
fn main(args: [string]) -> int do fn main() -> int do
let arr = [1, 2, 3, 4]; let arr = [1, 2, 3, 4];
let empty = []; # let empty = [];
let x = arr[0]; let x = arr[0];
x x
end end