-
Notifications
You must be signed in to change notification settings - Fork 171
Add support for list
methods with Const
#2570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1ec15d5
Implement `append`, `remove`, `reverse`, `pop`, `clear` and `insert`
kmr-srbh 46975a2
Implement `count` and `index`
kmr-srbh e8789f5
Improve checking for `Const` type
kmr-srbh d4d0952
Simplify type checking for `Const`
kmr-srbh aba1177
Update test references
kmr-srbh 3798cbc
Add tests
kmr-srbh 4d191dd
Update test
kmr-srbh 3549a5d
Update error test references
kmr-srbh cf327c2
Update error test references
kmr-srbh 842bf4c
Update tests/tests.toml
kmr-srbh 6841437
Tests: Update tests and test references
kmr-srbh 0b9b94f
LLVM: Fix const list declaration
ubaidsk dd87ac8
Fix type for type checking
ubaidsk fdf6cb3
Add print statements in test
ubaidsk d202999
TEST: Update reference tests
ubaidsk a605f6c
TEST: Remove C flag as ListCount() yet to be supported
ubaidsk 66c288f
Remove list, str import
ubaidsk c5d556f
Fix formatting changes
kmr-srbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,19 @@ | ||
from lpython import i32, Const | ||
|
||
|
||
def test_const_list(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
print(CONST_INTEGER_LIST.count(1)) | ||
print(CONST_INTEGER_LIST.index(1)) | ||
assert CONST_INTEGER_LIST.count(1) == 2 | ||
assert CONST_INTEGER_LIST.index(1) == 0 | ||
|
||
CONST_STRING_LIST: Const[list[str]] = ["ALPHA", "BETA", "RELEASE"] | ||
print(CONST_STRING_LIST.count("ALPHA")) | ||
print(CONST_STRING_LIST.index("RELEASE")) | ||
assert CONST_STRING_LIST.count("ALPHA") == 1 | ||
assert CONST_STRING_LIST.index("RELEASE") == 2 | ||
|
||
|
||
test_const_list() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_append(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.append(6) | ||
|
||
|
||
test_const_list_append() |
This file contains hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_clear(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.clear() | ||
|
||
|
||
test_const_list_clear() |
This file contains hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_insert(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.insert(3, 8) | ||
|
||
|
||
test_const_list_insert() |
This file contains hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_pop(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.pop() | ||
|
||
|
||
test_const_list_pop() |
This file contains hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_remove(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.remove(1) | ||
|
||
|
||
test_const_list_remove() |
This file contains hidden or 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,10 @@ | ||
from lpython import i32, list, Const | ||
|
||
|
||
def test_const_list_reverse(): | ||
CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] | ||
|
||
CONST_INTEGER_LIST.reverse() | ||
|
||
|
||
test_const_list_reverse() |
This file contains hidden or 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": "asr-test_const_list_append-ada1ade", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_append.py", | ||
"infile_hash": "1f8e9cdfaf24139c23d0a063fcce8c1765b0349500874c946c2a5bda", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_append-ada1ade.stderr", | ||
"stderr_hash": "84fe0a7a75edd73700bce92d3e43cdc85e7f3c58f0047f53fb4412ad", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot append element to a const list | ||
--> tests/errors/test_const_list_append.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.append(6) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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": "asr-test_const_list_clear-33bfae7", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_clear.py", | ||
"infile_hash": "df04c8c3b9063bbbe0a24443f962c70732fecef59a7418cd7d5182af", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_clear-33bfae7.stderr", | ||
"stderr_hash": "5c0c698319211c447c76e3309a027ee068dffded22d87bb3024cedf9", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot clear elements from a const list | ||
--> tests/errors/test_const_list_clear.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.clear() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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": "asr-test_const_list_insert-4c81295", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_insert.py", | ||
"infile_hash": "d4a31ff954a49f096c46e38118ab88ac8821d5d691f1ada9ab323828", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_insert-4c81295.stderr", | ||
"stderr_hash": "148e2a44028dd423007236ebf7a2c393fcefa4e8c12aad565f1c87fe", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot insert element in a const list | ||
--> tests/errors/test_const_list_insert.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.insert(3, 8) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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": "asr-test_const_list_pop-568b207", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_pop.py", | ||
"infile_hash": "e6cae5dc10a6a3505b3227d8492f32859f5baef086c143b1afcacdbf", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_pop-568b207.stderr", | ||
"stderr_hash": "32d57cbb983509ca6c54bc0812c9a74b3c1886ecc94e635c5011c378", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot pop element from a const list | ||
--> tests/errors/test_const_list_pop.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.pop() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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": "asr-test_const_list_remove-c5deb20", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_remove.py", | ||
"infile_hash": "e2bfdbf86ced2fae5e85037b6ea8479c1b73ab9b11b21c259739f8c1", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_remove-c5deb20.stderr", | ||
"stderr_hash": "3529d822548d9327dbd0eab32aebc7b4a0da518cc0a6c2356e65c7b8", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot remove element from a const list | ||
--> tests/errors/test_const_list_remove.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.remove(1) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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": "asr-test_const_list_reverse-2df1a6f", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_const_list_reverse.py", | ||
"infile_hash": "b49f332d26356501f60c0342b86303deb62cd13621a821f3f2bc30c9", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_const_list_reverse-2df1a6f.stderr", | ||
"stderr_hash": "78d4df28bbde66600867165e7c4d2b7e56874ba0f459052f8ab1b7fc", | ||
"returncode": 2 | ||
} |
This file contains hidden or 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,5 @@ | ||
semantic error: cannot reverse a const list | ||
--> tests/errors/test_const_list_reverse.py:7:5 | ||
| | ||
7 | CONST_INTEGER_LIST.reverse() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.