Skip to content

Commit

Permalink
Add support for item access from Const data-structures (#2579)
Browse files Browse the repository at this point in the history
* Add support for accessing items from data-structures within `Const`

* Update type checking logic for `Const dict`

Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com>

* Minor formatting change

Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com>

* Handle negative indices for `const list` and minor formatting changes

* Add tests

* Update test references

* Heavily simplify handling `const`

* Tests: Add compile time test

* Remove calls to `type_get_past_const()`

* Tests: Update test references

* Remove extra newline

Co-authored-by: Shaikh Ubaid <shaikhubaid769@gmail.com>

* Delete tests/reference/asr-test_const_access-82a9a24.json

* Delete tests/reference/asr-test_const_access-82a9a24.stdout

* Delete tests/reference/asr-test_const_str_access-59ff543.stderr

* Delete tests/reference/asr-test_const_tuple_access-0d4c6df.json

* Delete tests/reference/asr-test_const_tuple_access-0d4c6df.stderr

* Delete tests/reference/asr-test_const_str_access-59ff543.json

* Formatting changes

* Tests: Add test to CMakeLists and update error references

* Update asr_to_llvm.cpp

* Undo formatting changes

* Undo formatting changes

* Revert throwing error for `Const` annotated tuples and strings

* Tests: Remove error references

* Remove redundant visitor

* Undo moving `index`

---------

Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com>
Co-authored-by: Shaikh Ubaid <shaikhubaid769@gmail.com>
  • Loading branch information
3 people authored May 1, 2024
1 parent a74d529 commit dfeacbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ RUN(NAME test_list_compare LABELS cpython llvm llvm_jit)
RUN(NAME test_list_concat LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_list_reserve LABELS cpython llvm llvm_jit)
RUN(NAME test_const_list LABELS cpython llvm llvm_jit)
RUN(NAME test_const_access LABELS cpython llvm llvm_jit)
RUN(NAME test_tuple_01 LABELS cpython llvm llvm_jit c)
RUN(NAME test_tuple_02 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_tuple_03 LABELS cpython llvm llvm_jit c)
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/test_const_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lpython import i32, Const

CONST_LIST: Const[list[i32]] = [1, 2, 3, 4, 5]
CONST_DICTIONARY: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3}

assert CONST_LIST[0] == 1
assert CONST_LIST[-2] == 4

assert CONST_DICTIONARY["a"] == 1

0 comments on commit dfeacbc

Please sign in to comment.