Skip to content

Commit

Permalink
compiler: Fix C code gen emitting var defs incorrectly
Browse files Browse the repository at this point in the history
DCO-1.1-Signed-off-by: Ellie <[email protected]>
  • Loading branch information
ell1e committed Nov 19, 2024
1 parent 117e2d9 commit ac40b9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
28 changes: 19 additions & 9 deletions src/compiler/moose64/codegen/c_gen.h64
Original file line number Diff line number Diff line change
Expand Up @@ -1665,16 +1665,26 @@ func node_to_c_string(project_file, node, parents,
if node.scope == none {
is_global = yes
# This must be a global variable.
for lbl in node.var_labels {
t += indent_str + c_var_type + " " +
get_global_symbol_c_name(
lbl, project_file=project_file) + ";\n"
}
} else {
for lbl in node.var_labels {
t += indent_str + c_var_type + " " +
lbl + ";\n"
}
for lbl in node.var_labels {
var c_name = if not is_global (lbl)
else (get_global_symbol_c_name(
lbl, project_file=project_file))
var c_var_type = texpr.as_c_code(
global_name_assign_callback=
get_global_symbol_c_name,
global_register_m64_array_callback=
project_file.project.c_export_tracker.
register_m64_array_type,
c_name_to_insert_if_func_ptr=c_name,
project=project, project_file=project_file,
is_moose64=is_moose64)

t += indent_str + c_var_type
if not texpr.is_func_ref {
t += " " + c_name
}
t += ";\n"
}
func handle_assigned_values_if_needed {
if node.is_empty {
Expand Down
12 changes: 10 additions & 2 deletions src/compiler/typeinfo/ast_typeref.h64
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func TypeRefFuncExpr.as_str(indent=0) {
func TypeRefFuncExpr.as_c_code(
indent=0, global_name_assign_callback=none,
global_register_m64_array_callback=none,
c_name_to_insert_if_func_ptr=none,
project=none, project_file=none,
is_moose64=no
) {
Expand Down Expand Up @@ -314,8 +315,14 @@ func TypeRefFuncExpr.as_c_code(
} else {
t += "void"
}
# FIXME: Handle global name adjustment here.
t += " (*" + if self.name != none (self.name) else ("") + ")"
t += " (*"
if c_name_to_insert_if_func_ptr != none {
t += c_name_to_insert_if_func_ptr
} elseif self.name != none {
# FIXME: Handle global name adjustment here.
t += self.name
}
t += ")"

if t != "" {
t += " "
Expand Down Expand Up @@ -641,6 +648,7 @@ func TypeRefExpr.as_code(indent=0) {
func TypeRefExpr.as_c_code(
indent=0, global_name_assign_callback=none,
global_register_m64_array_callback=none,
c_name_to_insert_if_func_ptr=none,
project=none, project_file=none,
is_moose64=no
) {
Expand Down

0 comments on commit ac40b9b

Please sign in to comment.