cgen: [cinit] attr for globals

pull/14025/head
Alexander Medvednikov 2022-04-13 00:30:51 +03:00
parent e3e5bef139
commit 2525a30b5f
1 changed files with 3 additions and 1 deletions

View File

@ -4368,9 +4368,11 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
} else { } else {
'' ''
} }
// should the global be initialized now // should the global be initialized now, not later in `vinit()`
cinit := node.attrs.contains('cinit')
should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module) should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module)
|| (g.pref.build_mode == .build_module && g.module_built == node.mod) || (g.pref.build_mode == .build_module && g.module_built == node.mod)
|| cinit
mut attributes := '' mut attributes := ''
if node.attrs.contains('weak') { if node.attrs.contains('weak') {
attributes += 'VWEAK ' attributes += 'VWEAK '