Skip to content

Commit e6c2a3b

Browse files
authored
Merge pull request #1342 from Smit-create/i-1245
[ASR/LLVM][WIP]: Implement Tuple/List Compare
2 parents 08b04b0 + 5e10562 commit e6c2a3b

19 files changed

+603
-14
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ RUN(NAME test_builtin_round LABELS cpython llvm c)
290290
RUN(NAME test_builtin_divmod LABELS cpython llvm c)
291291
RUN(NAME test_math1 LABELS cpython llvm c)
292292
RUN(NAME test_math_02 LABELS cpython llvm)
293+
RUN(NAME test_pass_compare LABELS cpython llvm)
293294
RUN(NAME test_c_interop_01 LABELS cpython llvm c)
294295
RUN(NAME test_c_interop_02 LABELS cpython llvm c
295296
EXTRAFILES test_c_interop_02b.c)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from ltypes import i32
2+
3+
4+
def f():
5+
a11: tuple[i32, i32]
6+
b11: tuple[i32, i32]
7+
a11 = (1, 2)
8+
b11 = (1, 2)
9+
assert a11 == b11
10+
c11: tuple[i32, i32]
11+
c11 = (1, 3)
12+
assert a11 != c11 and c11 != b11
13+
a: tuple[tuple[i32, i32], str, bool]
14+
b: tuple[tuple[i32, i32], str, bool]
15+
a = (a11, 'ok', True)
16+
b = (b11, 'ok', True)
17+
assert a == b
18+
b = (b11, 'notok', True)
19+
assert a != b
20+
21+
22+
def g():
23+
a11: list[i32]
24+
b11: list[i32]
25+
a11 = [1, 2, 3, 4]
26+
b11 = [1, 2, 3, 4]
27+
assert a11 == b11
28+
a11.append(5)
29+
assert a11 != b11
30+
c11: list[i32] = []
31+
assert a11 != c11
32+
33+
d11: list[str] = ['a', 'b', '^', '*']
34+
e11: list[str] = ['a', 'b', '^']
35+
assert d11 != e11
36+
e11.append('*')
37+
assert d11 == e11
38+
39+
f11: list[tuple[i32, i32]] = []
40+
x: tuple[i32, i32]
41+
i: i32
42+
for i in range(10):
43+
x = (i, i+2)
44+
f11.append(x)
45+
46+
g11: list[tuple[i32, i32]] = []
47+
for i in range(9):
48+
x = (i, i+2)
49+
g11.append(x)
50+
assert g11 != f11
51+
x = (9, 11)
52+
g11.append(x)
53+
assert g11 == f11
54+
55+
56+
def check():
57+
f()
58+
g()
59+
60+
61+
check()

src/libasr/ASR.asdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,14 @@ expr
251251
| ListConstant(expr* args, ttype type)
252252
| ListLen(expr arg, ttype type, expr? value)
253253
| ListConcat(expr left, expr right, ttype type, expr? value)
254+
| ListCompare(expr left, cmpop op, expr right, ttype type, expr? value)
254255

255256
| SetConstant(expr* elements, ttype type)
256257
| SetLen(expr arg, ttype type, expr? value)
257258

258259
| TupleConstant(expr* elements, ttype type)
259260
| TupleLen(expr arg, ttype type, expr value)
261+
| TupleCompare(expr left, cmpop op, expr right, ttype type, expr? value)
260262

261263
| StringConstant(string s, ttype type)
262264
| StringConcat(expr left, expr right, ttype type, expr? value)

src/libasr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ set(SRC
5454
pass/update_array_dim_intrinsic_calls.cpp
5555
pass/pass_array_by_data.cpp
5656
pass/pass_list_expr.cpp
57+
pass/pass_compare.cpp
5758

5859
asr_verify.cpp
5960
asr_utils.cpp

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6042,6 +6042,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
60426042
target_type = get_type_from_ttype_t_util(arg_type);
60436043
break ;
60446044
}
6045+
case (ASR::ttypeType::Tuple) : {
6046+
target_type = get_type_from_ttype_t_util(arg_type);
6047+
break ;
6048+
}
60456049
default :
60466050
throw CodeGenError("Type " + ASRUtils::type_to_str(arg_type) + " not implemented yet.");
60476051
}

0 commit comments

Comments
 (0)