Skip to content
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

ASR -> CPython: Add DictConstant visitor #2693

Merged

Conversation

kmr-srbh
Copy link
Contributor

@kmr-srbh kmr-srbh commented May 9, 2024

Global scope

from lpython import i32, f64

my_first_dict: dict[str, i32] = {"a": 1, "b": 2, "c": 3}
print(my_first_dict)

my_second_dict: dict[i32, f64] = {1: 1.33, 2: 2.33, 3: 3.33}
print(my_second_dict)

my_third_dict: dict[str, str] = {"a": "A", "b": "B", "c": "C"}
print(my_third_dict)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py --show-python
def __main__global_init():
    my_first_dict = {"a": 1, "b": 2, "c": 3}
    my_second_dict = {1: 1.330000, 2: 2.330000, 3: 3.330000}
    my_third_dict = {"a": "A", "b": "B", "c": "C"}
def __main__global_stmts():
    print(my_first_dict)
    print(my_second_dict)
    print(my_third_dict)

Local scope

from lpython import i32, f64


def f():
    my_first_dict: dict[str, i32] = {"a": 1, "b": 2, "c": 3}
    print(my_first_dict)

    my_second_dict: dict[i32, f64] = {1: 1.33, 2: 2.33, 3: 3.33}
    print(my_second_dict)

    my_third_dict: dict[str, str] = {"a": "A", "b": "B", "c": "C"}
    print(my_third_dict)


f()
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py --show-python
def __main__global_stmts():
    f()
def f():
    my_first_dict: dict[str, i32]
    my_second_dict: dict[i32, f64]
    my_third_dict: dict[str, str]
    my_first_dict = {"a": 1, "b": 2, "c": 3}
    print(my_first_dict)
    my_second_dict = {1: 1.330000, 2: 2.330000, 3: 3.330000}
    print(my_second_dict)
    my_third_dict = {"a": "A", "b": "B", "c": "C"}
    print(my_third_dict)

TODO

  • Add tests

@nikabot
Copy link

nikabot commented May 9, 2024

See: #2690 (comment)

@kmr-srbh
Copy link
Contributor Author

kmr-srbh commented May 9, 2024

@Shaikh-Ubaid I think we should wait until #2690 is merged. We can then test for set, tuple and list values in dictionary and have the test in the same file. Shall we?

@kmr-srbh kmr-srbh marked this pull request as ready for review May 9, 2024 18:16
@Shaikh-Ubaid Shaikh-Ubaid merged commit e378b4e into lcompilers:main May 9, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants