lcompilers / lpython

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

ASR -> CPython: Add `list` method visitors #2694

Closed kmr-srbh closed 4 months ago

kmr-srbh commented 4 months ago
from lpython import i32, f64

# global scope
my_first_list: list[i32] = [1, 2, 3, 4, 5]
print(my_first_list)

my_first_list.append(4)
my_first_list.remove(2)
print(my_first_list.count(4))
my_first_list.insert(0, 1)
my_first_list.clear()

# local scope
def f():
    my_first_list: list[i32] = [1, 2, 3, 4, 5]
    print(my_first_list)

    my_first_list.append(4)
    my_first_list.remove(2)
    print(my_first_list.count(4))
    my_first_list.insert(0, 1)
    my_first_list.clear()

f()
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py --show-python
def __main__global_stmts():
    my_first_list = [1, 2, 3, 4, 5]
    print(my_first_list)
    my_first_list.append(4)
    my_first_list.remove(2)
    print(my_first_list.count(4))
    my_first_list.insert(0, 1)
    my_first_list.clear()
    f()
def f():
    my_first_list: list[i32]
    my_first_list = [1, 2, 3, 4, 5]
    print(my_first_list)
    my_first_list.append(4)
    my_first_list.remove(2)
    print(my_first_list.count(4))
    my_first_list.insert(0, 1)
    my_first_list.clear()
kmr-srbh commented 4 months ago

@Shaikh-Ubaid could you please look into the anomaly occurring in the generated code when a function call is present inside a function, as in, print(my_first_list.count(4))?