diff --git a/examples/expr2.py b/examples/expr2.py index 2e66f1e584..9b21524647 100644 --- a/examples/expr2.py +++ b/examples/expr2.py @@ -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() \ No newline at end of file diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 7f4d525db5..c6bfbae075 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -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) diff --git a/integration_tests/test_dict_11.py b/integration_tests/test_dict_11.py new file mode 100644 index 0000000000..9b21524647 --- /dev/null +++ b/integration_tests/test_dict_11.py @@ -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() \ No newline at end of file diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index bc790d5974..ca3dab2bd4 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -356,6 +356,11 @@ namespace LCompilers { } break ; } + case ASR::ttypeType::Dict: { + ASR::Dict_t* dict_type = ASR::down_cast(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));