-
Notifications
You must be signed in to change notification settings - Fork 171
LPython Semantics
Ondřej Čertík edited this page Aug 4, 2022
·
5 revisions
LPython is designed to compile such a subset of Python so that we can modify the Python's semantics to always copy things over for a = b
(no reference counting), and still be equivalent to Python. This is done for performance reasons. The idea is that LPython will not compile your code if it does not follow the restricted subset. If you want reference counting, then one must ask for it explicitly.
>>> src = [] # fine
>>> dest = src # fine
>>> dest.append(1) # fine
>>> src # error --- LPython and CPython would differ here, so we must disallow at compile time
If you want reference counting, then we could do something like:
>>> src = rcp([]) # fine
>>> dest = rcp(src) # fine
>>> dest.append(1) # fine
>>> src # fine
Later, we can add ASR->ASR optimizations that turn this:
src = []
dest = src # deep copy
dest.append(1)
print(dest)
To this:
src = []
src.append(1)
print(src)