Pass 'global'

This commit is contained in:
David Gonzalez Martin 2025-06-12 17:02:48 -06:00
parent 7f5d0834ae
commit b9d7212169

View File

@ -6238,7 +6238,30 @@ parse = fn (module: &Module) void
if (!is_global_keyword)
{
#trap();
>initial_value = parse_value(module, scope, zero);
skip_space(module);
expect_character(module, ';');
>global_storage = new_value(module);
global_storage.& = {
.id = .global,
zero,
};
>global = new_global(module);
global.& = {
.variable = {
.storage = global_storage,
.type = global_type,
.scope = scope,
.name = global_name,
.line = global_line,
.column = global_column,
},
.initial_value = initial_value,
.linkage = .internal, // TODO: linkage
zero,
};
}
}
}
@ -10829,14 +10852,14 @@ emit = fn (module: &Module) void
continue;
}
>global_pointer_type = global.variable.storage.type;
assert(global_pointer_type.id == .pointer);
>global_value_type = global_pointer_type.content.pointer.element_type;
switch (global.variable.storage.id)
{
.function, .forward_declared_function =>
{
>global_pointer_type = global.variable.storage.type;
assert(global_pointer_type.id == .pointer);
>global_value_type = global_pointer_type.content.pointer.element_type;
>function_type = &global_value_type.content.function;
>semantic_argument_types = function_type.base.semantic_argument_types;
>semantic_return_type = function_type.base.semantic_return_type;
@ -11063,7 +11086,16 @@ emit = fn (module: &Module) void
assert(!module.current_macro_instantiation);
assert(!module.current_macro_declaration);
if (global.variable.storage.id == .function)
if (global.emitted)
{
continue;
}
switch (global.variable.storage.id)
{
.function,
.forward_declared_function,
=>
{
module.current_function = global;
@ -11451,6 +11483,12 @@ emit = fn (module: &Module) void
// END OF SCOPE
module.current_function = zero;
},
.global =>
{
#trap();
},
else => { report_error(); },
}
global = global.next;
@ -11783,6 +11821,7 @@ names: [_][]u8 = [
"pointer_cast",
"u1_return",
"local_type_inference",
"global",
];
[export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32