File tree 4 files changed +72
-9
lines changed 4 files changed +72
-9
lines changed Original file line number Diff line number Diff line change
1
+ from ltypes import c64 , i32
2
+
3
+ def test_tuple_with_lists ():
4
+ mat : list [list [c64 ]] = []
5
+ vec : list [c64 ] = []
6
+ tensor : tuple [list [list [c64 ]], list [c64 ]]
7
+ tensors : list [tuple [list [list [c64 ]], list [c64 ]]]
8
+ i : i32
9
+ j : i32
10
+ k : i32
11
+ l : i32
12
+ rows : i32 = 10
13
+ cols : i32 = 5
14
+
15
+ for i in range (rows ):
16
+ for j in range (cols ):
17
+ vec .append (complex (i + j , 0 ))
18
+ mat .append (vec )
19
+ vec .clear ()
20
+
21
+ for i in range (cols ):
22
+ vec .append (complex (2 * i , 0 ))
23
+
24
+ for i in range (rows ):
25
+ for j in range (cols ):
26
+ assert mat [i ][j ] - vec [j ] == i - j
27
+
28
+ tensor = (mat , vec )
29
+
30
+ for i in range (rows ):
31
+ for j in range (cols ):
32
+ mat [i ][j ] += complex (0 , 3.0 )
33
+
34
+ for i in range (cols ):
35
+ vec [i ] += complex (0 , 2.0 )
36
+
37
+ for i in range (rows ):
38
+ for j in range (cols ):
39
+ assert tensor [0 ][i ][j ] - mat [i ][j ] == - complex (0 , 3.0 )
40
+
41
+ for i in range (cols ):
42
+ assert tensor [1 ][i ] - vec [i ] == - complex (0 , 2.0 )
43
+
44
+ tensor = (mat , vec )
45
+
46
+ for k in range (2 * rows ):
47
+ tensors .append (tensor )
48
+ for i in range (rows ):
49
+ for j in range (cols ):
50
+ mat [i ][j ] += complex (1.0 , 2.0 )
51
+
52
+ for i in range (cols ):
53
+ vec [i ] += complex (1.0 , 2.0 )
54
+
55
+ tensor = (mat , vec )
56
+
57
+ for k in range (2 * rows ):
58
+ for i in range (rows ):
59
+ for j in range (cols ):
60
+ assert tensors [k ][0 ][i ][j ] - mat [i ][j ] == - (2 * rows - k ) * complex (1.0 , 2.0 )
61
+
62
+ for k in range (2 * rows ):
63
+ for i in range (cols ):
64
+ assert tensors [k ][1 ][i ] - vec [i ] == - (2 * rows - k ) * complex (1.0 , 2.0 )
65
+
66
+ test_tuple_with_lists ()
Original file line number Diff line number Diff line change @@ -1307,7 +1307,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1307
1307
this ->visit_expr_wrapper (x.m_pos , true );
1308
1308
llvm::Value *pos = tmp;
1309
1309
1310
- tmp = tuple_api->read_item (ptuple, pos);
1310
+ tmp = tuple_api->read_item (ptuple, pos, LLVM::is_llvm_struct (x. m_type ) );
1311
1311
}
1312
1312
1313
1313
void visit_ArrayItem (const ASR::ArrayItem_t& x) {
@@ -1855,7 +1855,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1855
1855
std::string el_type_code = ASRUtils::get_type_code (asr_list->m_type );
1856
1856
int32_t type_size = -1 ;
1857
1857
if ( LLVM::is_llvm_struct (asr_list->m_type ) ||
1858
- ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ) {
1858
+ ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ||
1859
+ ASR::is_a<ASR::Complex_t>(*asr_list->m_type ) ) {
1859
1860
llvm::DataLayout data_layout (module.get ());
1860
1861
type_size = data_layout.getTypeAllocSize (el_llvm_type);
1861
1862
} else {
@@ -2237,7 +2238,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
2237
2238
a_kind);
2238
2239
int32_t type_size = -1 ;
2239
2240
if ( LLVM::is_llvm_struct (asr_list->m_type ) ||
2240
- ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ) {
2241
+ ASR::is_a<ASR::Character_t>(*asr_list->m_type ) ||
2242
+ ASR::is_a<ASR::Complex_t>(*asr_list->m_type ) ) {
2241
2243
llvm::DataLayout data_layout (module.get ());
2242
2244
type_size = data_layout.getTypeAllocSize (el_llvm_type);
2243
2245
} else {
Original file line number Diff line number Diff line change @@ -304,7 +304,7 @@ namespace LFortran {
304
304
arg_size);
305
305
llvm::Type* el_type = std::get<2 >(typecode2listtype[src_type_code]);
306
306
copy_data = builder->CreateBitCast (copy_data, el_type->getPointerTo ());
307
- if ( LLVM::is_mutable_llvm_struct (list_type->m_type ) ) {
307
+ if ( LLVM::is_llvm_struct (list_type->m_type ) ) {
308
308
builder->CreateStore (copy_data, get_pointer_to_list_data (dest));
309
309
llvm::AllocaInst *pos_ptr = builder->CreateAlloca (llvm::Type::getInt32Ty (context),
310
310
nullptr );
Original file line number Diff line number Diff line change @@ -55,11 +55,6 @@ namespace LFortran {
55
55
ASR::is_a<ASR::Derived_t>(*asr_type) ||
56
56
ASR::is_a<ASR::Class_t>(*asr_type);
57
57
}
58
- static inline bool is_mutable_llvm_struct (ASR::ttype_t * asr_type) {
59
- return ASR::is_a<ASR::List_t>(*asr_type) ||
60
- ASR::is_a<ASR::Derived_t>(*asr_type) ||
61
- ASR::is_a<ASR::Class_t>(*asr_type);
62
- }
63
58
}
64
59
65
60
class LLVMList ;
You can’t perform that action at this time.
0 commit comments