-
Notifications
You must be signed in to change notification settings - Fork 170
ASR: Support param access in, out, inout #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise I think this looks good, thanks!
We should also add regular integration tests and CPython tests for this. |
9402ab1
to
e35f45e
Compare
Done. |
I am adding this to auto-merge as it seems approved. I will work on further modications (if any) in another PR. |
class Intent: | ||
def __init__(self, type): | ||
self._type = type | ||
|
||
def __getitem__(self, params): | ||
return params | ||
|
||
In = Intent("In") | ||
Out = Intent("Out") | ||
InOut = Intent("InOut") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disabled the auto-merge. I think/guess this needs a review. I would like to know if this approach is fine for supporting In
, Out
, InOut
in CPython
.
Ready. |
|
||
print(a, b, c, d.p) | ||
|
||
f(a, b, c, d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about testing In[list[u32]]
, In[Foo]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ cat examples/expr2.py
from lpython import i32, u32, f64, dataclass, In, Out, InOut
@dataclass
class Foo:
p: i32
def f(z: In[list[u32]], w: In[Foo]):
print(z, w.p)
def main0():
c: list[u32] = [u32(1), u32(2), u32(3), u32(4)]
d: Foo = Foo(25)
f(c, d)
assert c[-1] == u32(4)
assert d.p == 25
main0()
$ python examples/expr2.py
[1, 2, 3, 4] 25
$ lpython examples/expr2.py
[1, 2, 3, 4] 25
It seems to work locally. Shall I add this as an integration_test?
Do you mean about printing errors when there is assignment/modification to In
variables? I am hoping to handle printing errors in PR #1803 after completion/merging of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, thanks @Shaikh-Ubaid !
towards #1807.