lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 156 forks source link

ASR -> CPython: Add `TupleConstant` visitor #2691

Closed kmr-srbh closed 1 month ago

kmr-srbh commented 1 month ago

Global scope

from lpython import i32, f64

my_first_tuple: tuple[i32, str, f64] = (1, "hello", 2.4)
print(my_first_tuple)

my_second_tuple: tuple[tuple[i32, str], str] = ((1, "hello"), "world")
print(my_second_tuple)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py --show-python
def __main__global_init():
    my_first_tuple = (1, "hello", 2.400000)
    my_second_tuple = ((1, "hello"), "world")
def __main__global_stmts():
    print(my_first_tuple)
    print(my_second_tuple)

Local scope

from lpython import i32, f64

def f():
    my_first_tuple: tuple[i32, str, f64] = (1, "hello", 2.4)
    print(my_first_tuple)

    my_second_tuple: tuple[tuple[i32, str], str] = ((1, "hello"), "world")
    print(my_second_tuple)

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_tuple: tuple[i32, str, f64]
    my_second_tuple: tuple[tuple[i32, str], str]
    my_first_tuple = (1, "hello", 2.400000)
    print(my_first_tuple)
    my_second_tuple = ((1, "hello"), "world")
    print(my_second_tuple)

TODO

nikabot commented 1 month ago

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

kmr-srbh commented 1 month ago

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