Implement global struct

This commit is contained in:
David Gonzalez Martin 2025-03-24 21:10:17 +01:00
parent 27e8d13748
commit aba6b2d22b
4 changed files with 1132 additions and 1070 deletions

View File

@ -151,7 +151,31 @@ arena_initialize = fn (initialization: ArenaInitialization) &Arena
return arena;
}
arena_initialize_default = fn (initial_size: u64) &Arena
{
return arena_initialize({
.reserved_size = 4 * 1024 * 1024 * 1024,
.granularity = 4 * 1024,
.initial_size = initial_size,
});
}
GlobalState = struct
{
arena: &Arena,
}
global_state: GlobalState = undefined;
global_state_initialize = fn () void
{
global_state = {
.arena = arena_initialize_default(2 * 1024 * 1024),
};
}
[export] main = fn [cc(c)] () s32
{
global_state_initialize();
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -416,3 +416,7 @@ test "pointer_cast" {
test "struct_assignment" {
try invsrc(@src());
}
test "global_struct" {
try invsrc(@src());
}

28
tests/global_struct.bbb Normal file
View File

@ -0,0 +1,28 @@
S = struct
{
a: u32,
b: u32,
c: u32,
}
s: S = {
.a = 1,
.b = 2,
.c = 3,
};
require = fn (ok: u1) void
{
if (!ok)
{
#trap();
}
}
[export] main = fn () s32
{
require(s.a == 1);
require(s.b == 2);
require(s.c == 3);
return 0;
}