lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 158 forks source link

ASR -> CPython: Add `SetConstant` visitor #2692

Closed kmr-srbh closed 4 months ago

kmr-srbh commented 4 months ago

Global scope

from lpython import i32, f64

my_first_set: set[i32] = {1, 2, 3, 2, 4}
print(my_first_set)

my_second_set: set[f64] = {1.1, 2.5, 6.8}
print(my_second_set)

my_third_set: set[str] = {"a", "b", "a", "c"}
print(my_third_set)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py --show-python
def __main__global_init():
    my_first_set = {1, 2, 3, 2, 4}
    my_second_set = {1.100000, 2.500000, 6.800000}
    my_third_set = {"a", "b", "a", "c"}
def __main__global_stmts():
    print(my_first_set)
    print(my_second_set)
    print(my_third_set)

Local scope

from lpython import i32, f64

def f():
    my_first_set: set[i32] = {1, 2, 3, 2, 4}
    print(my_first_set)

    my_second_set: set[f64] = {1.1, 2.5, 6.8}
    print(my_second_set)

    my_third_set: set[str] = {"a", "b", "a", "c"}
    print(my_third_set)

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_set: set[i32]
    my_second_set: set[f64]
    my_third_set: set[str]
    my_first_set = {1, 2, 3, 2, 4}
    print(my_first_set)
    my_second_set = {1.100000, 2.500000, 6.800000}
    print(my_second_set)
    my_third_set = {"a", "b", "a", "c"}
    print(my_third_set)

TODO

nikabot commented 4 months ago

See: https://github.com/lcompilers/lpython/pull/2690#discussion_r1595612282

kmr-srbh commented 4 months ago

Closing due to https://github.com/lcompilers/lpython/pull/2690#issuecomment-2102941947