@@ -105,57 +105,31 @@ void pass_wrap_global_stmts(Allocator &al,
105105 }
106106
107107 if (return_var) {
108- // The last item was an expression, create a function returning it
109-
110108 // The last defined `return_var` is the actual return value
111109 ASR::down_cast2<ASR::Variable_t>(return_var)->m_intent = ASRUtils::intent_return_var;
110+ }
112111
113-
114- ASR::asr_t *fn = ASRUtils::make_Function_t_util (
115- al, loc,
116- /* a_symtab */ fn_scope,
117- /* a_name */ fn_name,
118- nullptr , 0 ,
119- /* a_args */ nullptr ,
120- /* n_args */ 0 ,
121- /* a_body */ body.p ,
122- /* n_body */ body.size (),
123- /* a_return_var */ return_var_ref,
124- ASR::abiType::BindC,
125- ASR::Public, ASR::Implementation,
126- nullptr ,
127- false , false , false , false , false ,
128- nullptr , 0 , nullptr , 0 ,
129- false , false , false );
130- std::string sym_name = fn_name;
131- if (unit.m_global_scope ->get_symbol (sym_name) != nullptr ) {
132- throw LCompilersException (" Function already defined" );
133- }
134- unit.m_global_scope ->add_symbol (sym_name, down_cast<ASR::symbol_t >(fn));
135- } else {
136- // The last item was a statement, create a subroutine (returning
137- // nothing)
138- ASR::asr_t *fn = ASRUtils::make_Function_t_util (
139- al, loc,
140- /* a_symtab */ fn_scope,
141- /* a_name */ fn_name,
142- nullptr , 0 ,
143- /* a_args */ nullptr ,
144- /* n_args */ 0 ,
145- /* a_body */ body.p ,
146- /* n_body */ body.size (),
147- nullptr ,
148- ASR::abiType::Source,
149- ASR::Public, ASR::Implementation, nullptr ,
150- false , false , false , false , false ,
151- nullptr , 0 , nullptr , 0 ,
152- false , false , false );
153- std::string sym_name = fn_name;
154- if (unit.m_global_scope ->get_symbol (sym_name) != nullptr ) {
155- throw LCompilersException (" Function already defined" );
156- }
157- unit.m_global_scope ->add_symbol (sym_name, down_cast<ASR::symbol_t >(fn));
112+ ASR::asr_t *fn = ASRUtils::make_Function_t_util (
113+ al, loc,
114+ /* a_symtab */ fn_scope,
115+ /* a_name */ fn_name,
116+ nullptr , 0 ,
117+ /* a_args */ nullptr ,
118+ /* n_args */ 0 ,
119+ /* a_body */ body.p ,
120+ /* n_body */ body.size (),
121+ /* a_return_var */ (return_var ? return_var_ref : nullptr ),
122+ (return_var ? ASR::abiType::BindC : ASR::abiType::Source),
123+ ASR::Public, ASR::Implementation,
124+ nullptr ,
125+ false , false , false , false , false ,
126+ nullptr , 0 , nullptr , 0 ,
127+ false , false , false );
128+ std::string sym_name = fn_name;
129+ if (unit.m_global_scope ->get_symbol (sym_name) != nullptr ) {
130+ throw LCompilersException (" Function already defined" );
158131 }
132+ unit.m_global_scope ->add_symbol (sym_name, down_cast<ASR::symbol_t >(fn));
159133 unit.m_items = nullptr ;
160134 unit.n_items = 0 ;
161135 PassUtils::UpdateDependenciesVisitor v (al);
0 commit comments