cgen: format module_init generated c code (#14764)

master
yuyi 2022-06-16 16:01:17 +08:00 committed by GitHub
parent 205221074c
commit f2962c34dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -4791,11 +4791,15 @@ fn (mut g Gen) write_init_function() {
g.writeln('\t_closure_mtx_init();')
}
for mod_name in g.table.modules {
g.writeln('\t{ // Initializations for module $mod_name :')
mut is_empty := true
// write globals and consts init later
for var_name in g.sorted_global_const_names {
if var := g.global_const_defs[var_name] {
if var.mod == mod_name && var.init.len > 0 {
if is_empty {
is_empty = false
g.writeln('\t// Initializations for module $mod_name')
}
g.writeln(var.init)
}
}
@ -4803,12 +4807,14 @@ fn (mut g Gen) write_init_function() {
init_fn_name := '${mod_name}.init'
if initfn := g.table.find_fn(init_fn_name) {
if initfn.return_type == ast.void_type && initfn.params.len == 0 {
if is_empty {
g.writeln('\t// Initializations for module $mod_name')
}
mod_c_name := util.no_dots(mod_name)
init_fn_c_name := '${mod_c_name}__init'
g.writeln('\t${init_fn_c_name}();')
}
}
g.writeln('\t}')
}
g.writeln('}')
if g.pref.printfn_list.len > 0 && '_vinit' in g.pref.printfn_list {

View File

@ -15,5 +15,3 @@ v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(void
v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
res.path = _SLIT("embed.vv");
// Initializations for module v.embed_file :

View File

@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
res.path = _SLIT("embed.vv");
res.apath = _SLIT("");
res.uncompressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("none"))->data;
// Initializations for module v.embed_file :

View File

@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
res.path = _SLIT("embed.vv");
res.apath = _SLIT("");
res.compressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("zlib"))->data;
// Initializations for module v.embed_file :