Implement global struct
This commit is contained in:
parent
27e8d13748
commit
aba6b2d22b
@ -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;
|
||||
}
|
||||
|
2146
src/converter.zig
2146
src/converter.zig
File diff suppressed because it is too large
Load Diff
@ -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
28
tests/global_struct.bbb
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user