-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ASR -> CPython: Add
list
method visitors (#2694)
* Add visitors for `append`, `count`, `remove`, `clear` and `insert` * Tests: Add tests and create references * Fix codegen considering whether the method has a return value * Tests: Update test references * Tests: Update test references pertaining to fix related to `__main__global_stmts`
- Loading branch information
Showing
5 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "python-test_list_methods-ceccf6b", | ||
"cmd": "lpython --no-color --show-python {infile}", | ||
"infile": "tests/test_list_methods.py", | ||
"infile_hash": "8fe6f0b490e63a1b86d4964ede9d5410d421e0251bd692d36a4b79c6", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "python-test_list_methods-ceccf6b.stdout", | ||
"stdout_hash": "888c041c38f4a7c2ea49df884a2caae10cc223b746227de97f9abf25", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
def __main__global_stmts(): | ||
my_first_list = [1, 2, 3, 4, 5] | ||
print(my_first_list) | ||
my_first_list.append(4) | ||
my_first_list.remove(2) | ||
print(my_first_list.count(4)) | ||
my_first_list.insert(0, 1) | ||
my_first_list.clear() | ||
my_second_list = [1.200000, 4.300000, 2.800000] | ||
print(my_second_list) | ||
my_second_list.append(4.300000) | ||
my_second_list.remove(2.800000) | ||
print(my_second_list.count(4.300000)) | ||
my_second_list.insert(0, 3.300000) | ||
my_second_list.clear() | ||
my_third_list = ["hello", "world", "lpython"] | ||
print(my_third_list) | ||
my_third_list.append("hello") | ||
my_third_list.remove("world") | ||
print(my_third_list.count("hello")) | ||
my_third_list.insert(0, "hi") | ||
my_third_list.clear() | ||
my_fourth_list = [(1.200000, 4.300000), (2.800000, 3.300000)] | ||
print(my_fourth_list) | ||
my_fourth_list.append((1.600000, 2.200000)) | ||
my_fourth_list.remove((1.200000, 4.300000)) | ||
print(my_fourth_list.count((2.800000, 3.300000))) | ||
my_fourth_list.insert(0, (1.000000, 0.000000)) | ||
my_fourth_list.clear() | ||
f() | ||
def f(): | ||
my_first_list: list[i32] | ||
my_fourth_list: list[tuple[f64, f64]] | ||
my_second_list: list[f64] | ||
my_third_list: list[str] | ||
my_first_list = [1, 2, 3, 4, 5] | ||
print(my_first_list) | ||
my_first_list.append(4) | ||
my_first_list.remove(2) | ||
print(my_first_list.count(4)) | ||
my_first_list.insert(0, 1) | ||
my_first_list.clear() | ||
my_second_list = [1.200000, 4.300000, 2.800000] | ||
print(my_second_list) | ||
my_second_list.append(4.300000) | ||
my_second_list.remove(2.800000) | ||
print(my_second_list.count(4.300000)) | ||
my_second_list.insert(0, 3.300000) | ||
my_second_list.clear() | ||
my_third_list = ["hello", "world", "lpython"] | ||
print(my_third_list) | ||
my_third_list.append("hello") | ||
my_third_list.remove("world") | ||
print(my_third_list.count("hello")) | ||
my_third_list.insert(0, "hi") | ||
my_third_list.clear() | ||
my_fourth_list = [(1.200000, 4.300000), (2.800000, 3.300000)] | ||
print(my_fourth_list) | ||
my_fourth_list.append((1.600000, 2.200000)) | ||
my_fourth_list.remove((1.200000, 4.300000)) | ||
print(my_fourth_list.count((2.800000, 3.300000))) | ||
my_fourth_list.insert(0, (1.000000, 0.000000)) | ||
my_fourth_list.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from lpython import i32, f64 | ||
|
||
# Global scope | ||
my_first_list: list[i32] = [1, 2, 3, 4, 5] | ||
print(my_first_list) | ||
|
||
my_first_list.append(4) | ||
my_first_list.remove(2) | ||
print(my_first_list.count(4)) | ||
my_first_list.insert(0, 1) | ||
my_first_list.clear() | ||
|
||
my_second_list: list[f64] = [1.2, 4.3, 2.8] | ||
print(my_second_list) | ||
|
||
my_second_list.append(4.3) | ||
my_second_list.remove(2.8) | ||
print(my_second_list.count(4.3)) | ||
my_second_list.insert(0, 3.3) | ||
my_second_list.clear() | ||
|
||
my_third_list: list[str] = ["hello", "world", "lpython"] | ||
print(my_third_list) | ||
|
||
my_third_list.append("hello") | ||
my_third_list.remove("world") | ||
print(my_third_list.count("hello")) | ||
my_third_list.insert(0, "hi") | ||
my_third_list.clear() | ||
|
||
my_fourth_list: list[tuple[f64, f64]] = [(1.2, 4.3), (2.8, 3.3)] | ||
print(my_fourth_list) | ||
|
||
my_fourth_list.append((1.6, 2.2)) | ||
my_fourth_list.remove((1.2, 4.3)) | ||
print(my_fourth_list.count((2.8, 3.3))) | ||
my_fourth_list.insert(0, (1.0, 0.0)) | ||
my_fourth_list.clear() | ||
|
||
# Local scope | ||
def f(): | ||
my_first_list: list[i32] = [1, 2, 3, 4, 5] | ||
print(my_first_list) | ||
|
||
my_first_list.append(4) | ||
my_first_list.remove(2) | ||
print(my_first_list.count(4)) | ||
my_first_list.insert(0, 1) | ||
my_first_list.clear() | ||
|
||
my_second_list: list[f64] = [1.2, 4.3, 2.8] | ||
print(my_second_list) | ||
|
||
my_second_list.append(4.3) | ||
my_second_list.remove(2.8) | ||
print(my_second_list.count(4.3)) | ||
my_second_list.insert(0, 3.3) | ||
my_second_list.clear() | ||
|
||
my_third_list: list[str] = ["hello", "world", "lpython"] | ||
print(my_third_list) | ||
|
||
my_third_list.append("hello") | ||
my_third_list.remove("world") | ||
print(my_third_list.count("hello")) | ||
my_third_list.insert(0, "hi") | ||
my_third_list.clear() | ||
|
||
my_fourth_list: list[tuple[f64, f64]] = [(1.2, 4.3), (2.8, 3.3)] | ||
print(my_fourth_list) | ||
|
||
my_fourth_list.append((1.6, 2.2)) | ||
my_fourth_list.remove((1.2, 4.3)) | ||
print(my_fourth_list.count((2.8, 3.3))) | ||
my_fourth_list.insert(0, (1.0, 0.0)) | ||
my_fourth_list.clear() | ||
|
||
|
||
f() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters