@@ -118,6 +118,8 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
118
118
return result;
119
119
}
120
120
121
+
122
+
121
123
ASR::asr_t * duplicate_Var (ASR::Var_t *x) {
122
124
std::string sym_name = ASRUtils::symbol_name (x->m_v );
123
125
ASR::symbol_t *sym = current_scope->get_symbol (sym_name);
@@ -139,6 +141,16 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
139
141
return ASR::make_ArrayItem_t (al, x->base .base .loc , m_v, args.p , x->n_args , type, m_value);
140
142
}
141
143
144
+ ASR::asr_t * duplicate_ListItem (ASR::ListItem_t *x) {
145
+ ASR::expr_t *m_a = duplicate_expr (x->m_a );
146
+ ASR::expr_t *m_pos = duplicate_expr (x->m_pos );
147
+ ASR::ttype_t *type = substitute_type (x->m_type );
148
+ ASR::expr_t *m_value = duplicate_expr (x->m_value );
149
+
150
+ return ASR::make_ListItem_t (al, x->base .base .loc ,
151
+ m_a, m_pos, type, m_value);
152
+ }
153
+
142
154
ASR::array_index_t duplicate_array_index (ASR::array_index_t x) {
143
155
ASR::expr_t *left = duplicate_expr (x.m_left );
144
156
ASR::expr_t *right = duplicate_expr (x.m_right );
@@ -150,6 +162,21 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
150
162
return result;
151
163
}
152
164
165
+ ASR::asr_t * duplicate_Assignment (ASR::Assignment_t *x) {
166
+ ASR::expr_t *target = duplicate_expr (x->m_target );
167
+ ASR::ttype_t *target_type = substitute_type (ASRUtils::expr_type (x->m_target ));
168
+ ASR::expr_t *value = duplicate_expr (x->m_value );
169
+ if (ASRUtils::is_real (*target_type) && ASR::is_a<ASR::IntegerConstant_t>(*x->m_value )) {
170
+ ASR::IntegerConstant_t *int_value = ASR::down_cast<ASR::IntegerConstant_t>(x->m_value );
171
+ if (int_value->m_n == 0 ) {
172
+ value = ASRUtils::EXPR (ASR::make_RealConstant_t (al, value->base .loc , 0 ,
173
+ ASRUtils::duplicate_type (al, target_type)));
174
+ }
175
+ }
176
+ ASR::stmt_t *overloaded = duplicate_stmt (x->m_overloaded );
177
+ return ASR::make_Assignment_t (al, x->base .base .loc , target, value, overloaded);
178
+ }
179
+
153
180
ASR::asr_t * duplicate_TemplateBinOp (ASR::TemplateBinOp_t *x) {
154
181
ASR::expr_t *left = duplicate_expr (x->m_left );
155
182
ASR::expr_t *right = duplicate_expr (x->m_right );
@@ -172,11 +199,20 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
172
199
return ASR::make_DoLoop_t (al, x->base .base .loc , head, m_body.p , x->n_body );
173
200
}
174
201
202
+ ASR::asr_t * duplicate_Cast (ASR::Cast_t *x) {
203
+ ASR::expr_t *arg = duplicate_expr (x->m_arg );
204
+ ASR::ttype_t *type = substitute_type (ASRUtils::expr_type (x->m_arg ));
205
+ if (ASRUtils::is_real (*type)) {
206
+ return (ASR::asr_t *) arg;
207
+ }
208
+ return ASRUtils::make_Cast_t_value (al, x->base .base .loc , arg, ASR::cast_kindType::IntegerToReal, x->m_type );
209
+ }
210
+
175
211
ASR::ttype_t * substitute_type (ASR::ttype_t *param_type) {
176
212
if (ASR::is_a<ASR::List_t>(*param_type)) {
177
- ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(param_type);
178
- ASR::ttype_t *elem_type = substitute_type (list_type-> m_type );
179
- return ASRUtils::TYPE ( ASR::make_List_t (al, param_type-> base . loc , elem_type ));
213
+ ASR::List_t *tlist = ASR::down_cast<ASR::List_t>(param_type);
214
+ return ASRUtils::TYPE ( ASR::make_List_t (al, param_type-> base . loc ,
215
+ substitute_type (tlist-> m_type ) ));
180
216
}
181
217
if (ASR::is_a<ASR::TypeParameter_t>(*param_type)) {
182
218
ASR::TypeParameter_t *param = ASR::down_cast<ASR::TypeParameter_t>(param_type);
@@ -191,28 +227,26 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
191
227
ASR::Real_t* tnew = ASR::down_cast<ASR::Real_t>(t);
192
228
return ASRUtils::TYPE (ASR::make_Real_t (al, t->base .loc ,
193
229
tnew->m_kind , param->m_dims , param->n_dims ));
194
- }
230
+ }
195
231
case ASR::ttypeType::Character: {
196
232
ASR::Character_t* tnew = ASR::down_cast<ASR::Character_t>(t);
197
233
return ASRUtils::TYPE (ASR::make_Character_t (al, t->base .loc ,
198
234
tnew->m_kind , tnew->m_len , tnew->m_len_expr ,
199
235
param->m_dims , param->n_dims ));
200
- }
236
+ }
201
237
default : return subs[param->m_param ];
202
238
}
203
239
}
204
240
return param_type;
205
241
}
206
242
243
+ // Commented out part is not yet considered for generic functions
207
244
ASR::asr_t * make_BinOp_helper (ASR::expr_t *left, ASR::expr_t *right,
208
245
ASR::binopType op, const Location &loc) {
209
246
ASR::ttype_t *left_type = ASRUtils::expr_type (left);
210
247
ASR::ttype_t *right_type = ASRUtils::expr_type (right);
211
248
ASR::ttype_t *dest_type = nullptr ;
212
249
ASR::expr_t *value = nullptr ;
213
-
214
- // bool right_is_int = ASRUtils::is_character(*left_type) && ASRUtils::is_integer(*right_type);
215
- // bool left_is_int = ASRUtils::is_integer(*left_type) && ASRUtils::is_character(*right_type);
216
250
217
251
if ((ASRUtils::is_integer (*left_type) || ASRUtils::is_real (*left_type) ||
218
252
ASRUtils::is_complex (*left_type) || ASRUtils::is_logical (*left_type)) &&
@@ -223,7 +257,6 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
223
257
dest_type = ASRUtils::expr_type (left);
224
258
} else if (ASRUtils::is_character (*left_type) && ASRUtils::is_character (*right_type)
225
259
&& op == ASR::binopType::Add) {
226
- // string concat
227
260
ASR::Character_t *left_type2 = ASR::down_cast<ASR::Character_t>(left_type);
228
261
ASR::Character_t *right_type2 = ASR::down_cast<ASR::Character_t>(right_type);
229
262
LFORTRAN_ASSERT (left_type2->n_dims == 0 );
@@ -250,9 +283,10 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
250
283
int64_t result;
251
284
switch (op) {
252
285
case (ASR::binopType::Add): { result = left_value + right_value; break ; }
253
- case (ASR::binopType::Sub): { result = left_value - right_value; break ; }
254
- case (ASR::binopType::Mul): { result = left_value * right_value; break ; }
286
+ // case (ASR::binopType::Sub): { result = left_value - right_value; break; }
287
+ // case (ASR::binopType::Mul): { result = left_value * right_value; break; }
255
288
case (ASR::binopType::Div): { result = left_value / right_value; break ; }
289
+ /*
256
290
case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; }
257
291
case (ASR::binopType::BitAnd): { result = left_value & right_value; break; }
258
292
case (ASR::binopType::BitOr): { result = left_value | right_value; break; }
@@ -271,17 +305,20 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
271
305
result = left_value >> right_value;
272
306
break;
273
307
}
308
+ */
274
309
default : { LFORTRAN_ASSERT (false ); } // should never happen
275
310
}
276
311
value = ASR::down_cast<ASR::expr_t >(ASR::make_IntegerConstant_t (al, loc, result, dest_type));
277
312
}
278
313
return ASR::make_IntegerBinOp_t (al, loc, left, op, right, dest_type, value);
279
314
} else if (ASRUtils::is_real (*dest_type)) {
315
+ /*
280
316
if (op == ASR::binopType::BitAnd || op == ASR::binopType::BitOr || op == ASR::binopType::BitXor ||
281
317
op == ASR::binopType::BitLShift || op == ASR::binopType::BitRShift) {
282
318
throw LCompilersException("ICE: failure in instantiation: Unsupported binary operation on floats: '"
283
319
+ ASRUtils::binop_to_str_python(op) + "'");
284
320
}
321
+ */
285
322
right = cast_helper (left_type, right);
286
323
dest_type = ASRUtils::expr_type (right);
287
324
if (ASRUtils::expr_value (left) != nullptr && ASRUtils::expr_value (right) != nullptr ) {
0 commit comments