@@ -598,6 +598,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
598
598
// Stores the name of imported functions and the modules they are imported from
599
599
std::map<std::string, std::string> imported_functions;
600
600
601
+ std::map<std::string, std::string> numpy2lpythontypes;
602
+
601
603
CommonVisitor (Allocator &al, LocationManager &lm, SymbolTable *symbol_table,
602
604
diag::Diagnostics &diagnostics, bool main_module, std::string module_name,
603
605
std::map<int , ASR::symbol_t *> &ast_overload, std::string parent_dir,
@@ -7413,14 +7415,40 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
7413
7415
tmp = ASR::make_GetPointer_t (al, x.base .base .loc , args[0 ].m_value , type, nullptr );
7414
7416
return ;
7415
7417
} else if ( call_name == " array" ) {
7416
- parse_args (x, args);
7418
+ ASR::ttype_t * type = nullptr ;
7419
+ if ( x.n_keywords == 0 ) {
7420
+ parse_args (x, args);
7421
+ } else {
7422
+ args.reserve (al, 1 );
7423
+ visit_expr_list (x.m_args , x.n_args , args);
7424
+ if ( x.n_keywords > 1 ) {
7425
+ throw SemanticError (" More than one keyword "
7426
+ " arguments aren't recognised by array" ,
7427
+ x.base .base .loc );
7428
+ }
7429
+ if ( std::string (x.m_keywords [0 ].m_arg ) != " dtype" ) {
7430
+ throw SemanticError (" Unrecognised keyword argument, " +
7431
+ std::string (x.m_keywords [0 ].m_arg ), x.base .base .loc );
7432
+ }
7433
+ visit_expr (*x.m_keywords [0 ].m_value );
7434
+ ASR::expr_t * dtype_expr = ASRUtils::EXPR (tmp);
7435
+ LCOMPILERS_ASSERT (ASR::is_a<ASR::StringConstant_t>(*dtype_expr));
7436
+ std::string dtype_np = ASR::down_cast<ASR::StringConstant_t>(dtype_expr)->m_s ;
7437
+ LCOMPILERS_ASSERT (numpy2lpythontypes.find (dtype_np) != numpy2lpythontypes.end ());
7438
+ Vec<ASR::dimension_t > dims;
7439
+ dims.n = 0 ;
7440
+ type = get_type_from_var_annotation (
7441
+ numpy2lpythontypes[dtype_np], x.base .base .loc , dims);
7442
+ }
7417
7443
if ( args.size () != 1 ) {
7418
7444
throw SemanticError (" array accepts only 1 argument for now, got " +
7419
7445
std::to_string (args.size ()) + " arguments instead." ,
7420
7446
x.base .base .loc );
7421
7447
}
7422
7448
ASR::expr_t *arg = args[0 ].m_value ;
7423
- ASR::ttype_t *type = ASRUtils::expr_type (arg);
7449
+ if ( type == nullptr ) {
7450
+ type = ASRUtils::expr_type (arg);
7451
+ }
7424
7452
if (ASR::is_a<ASR::ListConstant_t>(*arg)) {
7425
7453
type = ASR::down_cast<ASR::List_t>(type)->m_type ;
7426
7454
ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
0 commit comments