Skip to content

Commit 9796963

Browse files
kmr-srbhassem2002
authored andcommitted
Fix symbolic pass for handling IntrinsicElementalFunction in print() (lcompilers#2665)
* Fix symbolic pass for handling `IntrinsicElementalFunction` in `print()` * Tests: Add tests and update references * Fix mistakenly commented out lines * Tests: Add testcase and update references * Tests: Update references * Style changes * Remove C backend * Tests: Add asserts and update test reference
1 parent 4b9ab17 commit 9796963

6 files changed

Lines changed: 51 additions & 0 deletions

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ RUN(NAME print_list_tuple_01 LABELS cpython llvm llvm_jit c NOFAST)
469469
RUN(NAME print_list_tuple_02 LABELS cpython llvm llvm_jit c NOFAST)
470470
RUN(NAME print_list_tuple_03 LABELS cpython llvm llvm_jit c NOFAST)
471471
RUN(NAME test_list_item_mixed_print LABELS cpython llvm llvm_jit c NOFAST)
472+
RUN(NAME test_intrinsic_function_mixed_print LABELS cpython llvm llvm_jit NOFAST)
472473

473474
# CPython and LLVM
474475
RUN(NAME const_01 LABELS cpython llvm llvm_jit c wasm)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from lpython import i32
2+
3+
def test_intrinsic_function_mixed_print():
4+
# list and list methods
5+
my_list: list[i32] = [1, 2, 3, 4, 5]
6+
print("Popped element:", my_list.pop())
7+
assert my_list == [1, 2, 3, 4]
8+
9+
print("1 is located at:", my_list.index(1))
10+
assert my_list.index(1) == 0
11+
12+
my_list.append(2)
13+
print("2 is present", my_list.count(2), "times")
14+
assert my_list.count(2) == 2
15+
16+
print(my_list.pop(), my_list)
17+
assert my_list == [1, 2, 3, 4]
18+
19+
# dict and dict methods
20+
my_dict: dict[str, i32] = {"first": 1, "second": 2, "third": 3}
21+
print("Keys:", my_dict.keys())
22+
print("Value of 'third':", my_dict.pop("third"))
23+
assert len(my_dict.keys()) == 2
24+
25+
test_intrinsic_function_mixed_print()

src/libasr/pass/replace_symbolic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
816816
ASR::expr_t* function_call = process_attributes(x.base.base.loc, val);
817817
print_tmp.push_back(function_call);
818818
}
819+
} else {
820+
print_tmp.push_back(val);
819821
}
820822
} else if (ASR::is_a<ASR::Cast_t>(*val)) {
821823
ASR::Cast_t* cast_t = ASR::down_cast<ASR::Cast_t>(val);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "runtime-test_intrinsic_function_mixed_print-a862825",
3+
"cmd": "lpython {infile}",
4+
"infile": "tests/../integration_tests/test_intrinsic_function_mixed_print.py",
5+
"infile_hash": "b0f779598e5d9868d183f1032fb3f87c131fedacf7848aaed6c4d238",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout",
9+
"stdout_hash": "a8d2083be043accf4ebe8c6a3e8a2427d492323b12d0c041ba79f10e",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Popped element: 5
2+
1 is located at: 0
3+
2 is present 2 times
4+
2 [1, 2, 3, 4]
5+
Keys: ['second', 'third', 'first']
6+
Value of 'third': 3

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ llvm = true
465465
filename = "../integration_tests/test_list_item_mixed_print.py"
466466
run = true
467467

468+
[[test]]
469+
filename = "../integration_tests/test_intrinsic_function_mixed_print.py"
470+
run = true
471+
468472
[[test]]
469473
filename = "../integration_tests/generics_01.py"
470474
asr = true

0 commit comments

Comments
 (0)