@@ -164,6 +164,9 @@ namespace CastingUtil {
164
164
}
165
165
cast_kind = type_rules.at (cast_key);
166
166
}
167
+ if ( ASRUtils::check_equal_type (src, dest, true ) ) {
168
+ return expr;
169
+ }
167
170
// TODO: Fix loc
168
171
return ASRUtils::EXPR (ASRUtils::make_Cast_t_value (al, loc, expr,
169
172
cast_kind, dest));
@@ -505,6 +508,10 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
505
508
// Stores the name of imported functions and the modules they are imported from
506
509
std::map<std::string, std::string> imported_functions;
507
510
511
+ std::map<std::string, std::string> numpy2lpythontypes = {
512
+ {" int8" , " i8" },
513
+ };
514
+
508
515
CommonVisitor (Allocator &al, LocationManager &lm, SymbolTable *symbol_table,
509
516
diag::Diagnostics &diagnostics, bool main_module, std::string module_name,
510
517
std::map<int , ASR::symbol_t *> &ast_overload, std::string parent_dir,
@@ -7520,16 +7527,45 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7520
7527
tmp = ASR::make_UnsignedIntegerBitNot_t (al, x.base .base .loc , operand, operand_type, value);
7521
7528
return ;
7522
7529
} else if ( call_name == " array" ) {
7523
- parse_args (x, args);
7530
+ ASR::ttype_t * type = nullptr ;
7531
+ if ( x.n_keywords == 0 ) {
7532
+ parse_args (x, args);
7533
+ } else {
7534
+ args.reserve (al, 1 );
7535
+ visit_expr_list (x.m_args , x.n_args , args);
7536
+ if ( x.n_keywords > 1 ) {
7537
+ throw SemanticError (" More than one keyword "
7538
+ " arguments aren't recognised by array" ,
7539
+ x.base .base .loc );
7540
+ }
7541
+ if ( std::string (x.m_keywords [0 ].m_arg ) != " dtype" ) {
7542
+ throw SemanticError (" Unrecognised keyword argument, " +
7543
+ std::string (x.m_keywords [0 ].m_arg ), x.base .base .loc );
7544
+ }
7545
+ std::string dtype_np = " " ;
7546
+ if ( AST::is_a<AST::Name_t>(*x.m_keywords [0 ].m_value ) ) {
7547
+ AST::Name_t* name_t = AST::down_cast<AST::Name_t>(x.m_keywords [0 ].m_value );
7548
+ dtype_np = name_t ->m_id ;
7549
+ } else {
7550
+ LCOMPILERS_ASSERT (false );
7551
+ }
7552
+ LCOMPILERS_ASSERT (numpy2lpythontypes.find (dtype_np) != numpy2lpythontypes.end ());
7553
+ Vec<ASR::dimension_t > dims;
7554
+ dims.n = 0 ;
7555
+ type = get_type_from_var_annotation (
7556
+ numpy2lpythontypes[dtype_np], x.base .base .loc , dims);
7557
+ }
7524
7558
if ( args.size () != 1 ) {
7525
7559
throw SemanticError (" array accepts only 1 argument for now, got " +
7526
7560
std::to_string (args.size ()) + " arguments instead." ,
7527
7561
x.base .base .loc );
7528
7562
}
7529
7563
ASR::expr_t *arg = args[0 ].m_value ;
7530
- ASR::ttype_t *type = ASRUtils::expr_type (arg);
7564
+ if ( type == nullptr ) {
7565
+ type = ASRUtils::expr_type (arg);
7566
+ }
7531
7567
if (ASR::is_a<ASR::ListConstant_t>(*arg)) {
7532
- type = ASR::down_cast<ASR::List_t> (type)-> m_type ;
7568
+ type = ASRUtils::get_contained_type (type);
7533
7569
ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
7534
7570
ASR::expr_t **m_args = list->m_args ;
7535
7571
size_t n_args = list->n_args ;
@@ -7544,6 +7580,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7544
7580
dims.push_back (al, dim);
7545
7581
type = ASRUtils::make_Array_t_util (al, x.base .base .loc , type, dims.p , dims.size (),
7546
7582
ASR::abiType::Source, false , ASR::array_physical_typeType::PointerToDataArray, true );
7583
+ for ( size_t i = 0 ; i < n_args; i++ ) {
7584
+ m_args[i] = CastingUtil::perform_casting (m_args[i], ASRUtils::expr_type (m_args[i]),
7585
+ ASRUtils::type_get_past_array (type), al, x.base .base .loc );
7586
+ }
7547
7587
tmp = ASR::make_ArrayConstant_t (al, x.base .base .loc , m_args, n_args, type, ASR::arraystorageType::RowMajor);
7548
7588
} else {
7549
7589
throw SemanticError (" array accepts only list for now, got " +
0 commit comments