There are still some bugs in how variable initialization is handled.
fromltypesimporti32defg(x: i32):
print(x)
x: i32=7deff():
a: i32=5x: i32=3x=5b: i32=x+1g(a*b+3)
f()
It prints:
$ lpython --new-parser a.py && ./a.out 23
$ PYTHONPATH=src/runtime/ltypes python a.py33
The solution: unless x is declared as x: Constant[i32] (we currently do not support it, but we could), then any initialization must be assigned to it using Assignment, not as "value" in the Variable_t, because then you can't assign to it later (we should check this in verify). Above x still has 3, not 5. For Constant[i32] you have to assign to it right away, and then you can't change it.
So the above code effectively becomes:
deff():
a: i32x: i32b: i32a=5x=3x=5b=x+1g(a*b+3)
And everything should work.
There are still some bugs in how variable initialization is handled.
It prints:
The solution: unless
xis declared asx: Constant[i32](we currently do not support it, but we could), then any initialization must be assigned to it using Assignment, not as "value" in theVariable_t, because then you can't assign to it later (we should check this in verify). Abovexstill has 3, not 5. ForConstant[i32]you have to assign to it right away, and then you can't change it.So the above code effectively becomes:
And everything should work.