-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c986b38
ASR: Support param intent in, out, inout
ubaidsk e35f45e
TEST: Add test and update refs
ubaidsk 5f09977
LPython: Support Intent In, Out, InOut
ubaidsk 6b27a70
LLVM: Support unsigned integer in list deepcopy
ubaidsk 26017ad
TEST: Add integration_test for In, Out, InOut
ubaidsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from lpython import i32, u32, f64, dataclass, In, Out, InOut | ||
|
||
@dataclass | ||
class Foo: | ||
p: i32 | ||
|
||
def f(x: i32, y: In[f64], z: InOut[list[u32]], w: Out[Foo]): | ||
assert (x == -12) | ||
assert abs(y - (4.44)) <= 1e-12 | ||
z.append(u32(5)) | ||
w.p = 24 | ||
|
||
|
||
def main0(): | ||
a: i32 = (-12) | ||
b: f64 = 4.44 | ||
c: list[u32] = [u32(1), u32(2), u32(3), u32(4)] | ||
d: Foo = Foo(25) | ||
|
||
print(a, b, c, d.p) | ||
|
||
f(a, b, c, d) | ||
assert c[-1] == u32(5) | ||
assert d.p == 24 | ||
|
||
main0() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,18 @@ def __init__(self, type, dims): | |
Union = ctypes.Union | ||
Pointer = PointerType("Pointer") | ||
|
||
|
||
class Intent: | ||
def __init__(self, type): | ||
self._type = type | ||
|
||
def __getitem__(self, params): | ||
return params | ||
|
||
In = Intent("In") | ||
Out = Intent("Out") | ||
InOut = Intent("InOut") | ||
Comment on lines
+88
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# Generics | ||
|
||
class TypeVar(): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@dataclass | ||
class Foo: | ||
p: i32 | ||
|
||
def f(x: i32, y: In[f64], z: InOut[list[u32]], w: Out[Foo[5]]): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-intent_01-66824bc", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/intent_01.py", | ||
"infile_hash": "0a8fa2940567fccee2cfccd4af40f353b74dbe542590460a195246a5", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "asr-intent_01-66824bc.stdout", | ||
"stdout_hash": "6c217775c0f43212356588d01124266dfe417ce0fd72c63c8cec30ad", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
(TranslationUnit | ||
(SymbolTable | ||
1 | ||
{ | ||
_global_symbols: | ||
(Module | ||
(SymbolTable | ||
5 | ||
{ | ||
Foo: | ||
(StructType | ||
(SymbolTable | ||
2 | ||
{ | ||
p: | ||
(Variable | ||
2 | ||
p | ||
[] | ||
Local | ||
() | ||
() | ||
Default | ||
(Integer 4 []) | ||
Source | ||
Public | ||
Required | ||
.false. | ||
) | ||
}) | ||
Foo | ||
[] | ||
[p] | ||
Source | ||
Public | ||
.false. | ||
.false. | ||
() | ||
() | ||
), | ||
f: | ||
(Function | ||
(SymbolTable | ||
3 | ||
{ | ||
w: | ||
(Variable | ||
3 | ||
w | ||
[] | ||
Out | ||
() | ||
() | ||
Default | ||
(Struct | ||
5 Foo | ||
[((IntegerConstant 0 (Integer 4 [])) | ||
(IntegerConstant 5 (Integer 4 [])))] | ||
) | ||
Source | ||
Public | ||
Required | ||
.false. | ||
), | ||
x: | ||
(Variable | ||
3 | ||
x | ||
[] | ||
In | ||
() | ||
() | ||
Default | ||
(Integer 4 []) | ||
Source | ||
Public | ||
Required | ||
.false. | ||
), | ||
y: | ||
(Variable | ||
3 | ||
y | ||
[] | ||
In | ||
() | ||
() | ||
Default | ||
(Real 8 []) | ||
Source | ||
Public | ||
Required | ||
.false. | ||
), | ||
z: | ||
(Variable | ||
3 | ||
z | ||
[] | ||
InOut | ||
() | ||
() | ||
Default | ||
(List | ||
(UnsignedInteger | ||
4 | ||
[] | ||
) | ||
) | ||
Source | ||
Public | ||
Required | ||
.false. | ||
) | ||
}) | ||
f | ||
(FunctionType | ||
[(Integer 4 []) | ||
(Real 8 []) | ||
(List | ||
(UnsignedInteger | ||
4 | ||
[] | ||
) | ||
) | ||
(Struct | ||
5 Foo | ||
[((IntegerConstant 0 (Integer 4 [])) | ||
(IntegerConstant 5 (Integer 4 [])))] | ||
)] | ||
() | ||
Source | ||
Implementation | ||
() | ||
.false. | ||
.false. | ||
.false. | ||
.false. | ||
.false. | ||
[] | ||
[] | ||
.false. | ||
) | ||
[] | ||
[(Var 3 x) | ||
(Var 3 y) | ||
(Var 3 z) | ||
(Var 3 w)] | ||
[] | ||
() | ||
Public | ||
.false. | ||
.false. | ||
() | ||
) | ||
}) | ||
_global_symbols | ||
[] | ||
.false. | ||
.false. | ||
), | ||
main_program: | ||
(Program | ||
(SymbolTable | ||
4 | ||
{ | ||
|
||
}) | ||
main_program | ||
[] | ||
[] | ||
) | ||
}) | ||
[] | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.