Closed czgdp1807 closed 5 months ago
I will continue this work on Monday.
Yes, one way to solve this is to introduce a list to array cast, which we need for LPython as well. By assigning to mdspan, we copy the data. The C++ code above does not copy data, but does a "view". We would need to ensure that the original data is not use elsewhere, similarly like we (will) do for LPython.
So as can be seen in the test we need to add support for the following things in the ASR,
ListToArray
cast - This will simply represent,std::vector::data
call. Inside LLVM backend it will be implemented simply as taking the data pointer fromlist
struct to data pointer of array (shallow copy as those are the semantics followed bymdspan
as well). In C backend it will be simply transformed to a pointer assignment from list struct to array's data pointer (if the user doesn't want to use any array library) or if someone chooses to usemdspan
then will be transformed to original source code.Rest everything can be managed with the existing ASR features.
https://github.com/lcompilers/lc/issues/14
cc: @certik