Skip to content

Nested Dictionaries Support #1690

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions examples/expr2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
def main0():
x: i32
x = (2+3)*5
print(x)
def test_dict():

main0()
tables: dict[i32, dict[i32, i32]] # NESTED DICTIONARY
tables = {2: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10},
3: {1: 3, 2: 6, 3: 9, 4: 12, 5: 15},
4: {1: 4, 2: 8, 3: 12, 4: 16, 5: 20},
5: {1: 5, 2: 10, 3: 15, 4: 20, 5: 25},
6: {1: 6, 2: 12, 3: 18, 4: 24, 5: 30},
7: {1: 7, 2: 14, 3: 21, 4: 28, 5: 35},
8: {1: 8, 2: 16, 3: 24, 4: 32, 5: 40},
9: {1: 9, 2: 18, 3: 27, 4: 36, 5: 45},
10: {1: 10, 2: 20, 3: 30, 4: 40, 5: 50}}

# Not implemented yet in LPython:
#if __name__ == "__main__":
# main()
i : i32
j : i32
for i in range(2, 11):
for j in range(1, 6):
assert tables[i][j] == i * j

test_dict()
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ RUN(NAME test_dict_07 LABELS cpython llvm)
RUN(NAME test_dict_08 LABELS cpython llvm c)
RUN(NAME test_dict_09 LABELS cpython llvm c)
RUN(NAME test_dict_10 LABELS cpython llvm) # TODO: Add support of dict with string in C backend
RUN(NAME test_dict_11 LABELS cpython llvm)
RUN(NAME test_for_loop LABELS cpython llvm c)
RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
RUN(NAME modules_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Expand Down
20 changes: 20 additions & 0 deletions integration_tests/test_dict_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def test_dict():

tables: dict[i32, dict[i32, i32]] # NESTED DICTIONARY
tables = {2: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10},
3: {1: 3, 2: 6, 3: 9, 4: 12, 5: 15},
4: {1: 4, 2: 8, 3: 12, 4: 16, 5: 20},
5: {1: 5, 2: 10, 3: 15, 4: 20, 5: 25},
6: {1: 6, 2: 12, 3: 18, 4: 24, 5: 30},
7: {1: 7, 2: 14, 3: 21, 4: 28, 5: 35},
8: {1: 8, 2: 16, 3: 24, 4: 32, 5: 40},
9: {1: 9, 2: 18, 3: 27, 4: 36, 5: 45},
10: {1: 10, 2: 20, 3: 30, 4: 40, 5: 50}}

i : i32
j : i32
for i in range(2, 11):
for j in range(1, 6):
assert tables[i][j] == i * j

test_dict()
5 changes: 5 additions & 0 deletions src/libasr/codegen/llvm_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ namespace LCompilers {
}
break ;
}
case ASR::ttypeType::Dict: {
ASR::Dict_t* dict_type = ASR::down_cast<ASR::Dict_t>(asr_type);
dict_api->dict_deepcopy(src, dest, dict_type, module, name2memidx);
break ;
}
default: {
throw LCompilersException("LLVMUtils::deepcopy isn't implemented for " +
ASRUtils::type_to_str_python(asr_type));
Expand Down