|
29 | 29 |
|
30 | 30 |
|
31 | 31 | namespace LFortran::LPython { |
32 | | - |
| 32 | + |
33 | 33 | // Does a CPython style lookup for a module: |
34 | 34 | // * First the current directory (this is incorrect, we need to do it relative to the current file) |
35 | 35 | // * Then the LPython runtime directory |
@@ -3657,6 +3657,25 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> { |
3657 | 3657 | throw SemanticError("len() is only supported for `str`, `set`, `dict`, `list` and `tuple`", loc); |
3658 | 3658 | } |
3659 | 3659 |
|
| 3660 | + ASR::asr_t* handle_reshape(Allocator &al, Vec<ASR::call_arg_t> args, |
| 3661 | + const Location &loc) { |
| 3662 | + if( args.size() != 2 ) { |
| 3663 | + throw SemanticError("reshape accepts only 2 arguments, got " + |
| 3664 | + std::to_string(args.size()) + " arguments instead.", |
| 3665 | + loc); |
| 3666 | + } |
| 3667 | + ASR::expr_t* array = args[0].m_value; |
| 3668 | + ASR::expr_t* newshape = args[1].m_value; |
| 3669 | + Vec<ASR::dimension_t> dims; |
| 3670 | + dims.reserve(al, 1); |
| 3671 | + ASR::dimension_t newdim; |
| 3672 | + newdim.loc = loc; |
| 3673 | + newdim.m_start = nullptr, newdim.m_length = nullptr; |
| 3674 | + dims.push_back(al, newdim); |
| 3675 | + ASR::ttype_t* empty_type = ASRUtils::duplicate_type(al, ASRUtils::expr_type(array), &dims); |
| 3676 | + return ASR::make_ArrayReshape_t(al, loc, array, newshape, empty_type, nullptr); |
| 3677 | + } |
| 3678 | + |
3660 | 3679 | ASR::asr_t* create_CPtrToPointer(const AST::Call_t& x) { |
3661 | 3680 | if( x.n_args != 2 ) { |
3662 | 3681 | throw SemanticError("c_p_pointer accepts two positional arguments, " |
@@ -3790,6 +3809,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> { |
3790 | 3809 | // with the type |
3791 | 3810 | tmp = nullptr; |
3792 | 3811 | return; |
| 3812 | + } else if (call_name == "reshape") { |
| 3813 | + tmp = handle_reshape(al, args, x.base.base.loc); |
| 3814 | + return ; |
3793 | 3815 | } else if (call_name == "empty_c_void_p") { |
3794 | 3816 | // TODO: check that `empty_c_void_p uses` has arguments that are compatible |
3795 | 3817 | // with the type |
|
0 commit comments