-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2056 from Smit-create/i-1981-1
Store initializer exprs for Structs in ASR
- Loading branch information
Showing
26 changed files
with
334 additions
and
182 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,45 @@ | ||
from lpython import packed, dataclass, i32, InOut | ||
|
||
|
||
@packed | ||
@dataclass | ||
class inner_struct: | ||
a: i32 | ||
|
||
|
||
@packed | ||
@dataclass | ||
class outer_struct: | ||
b: inner_struct = inner_struct(0) | ||
|
||
|
||
def update_my_inner_struct(my_inner_struct: InOut[inner_struct]) -> None: | ||
my_inner_struct.a = 99999 | ||
|
||
|
||
def update_my_outer_struct(my_outer_struct: InOut[outer_struct]) -> None: | ||
my_outer_struct.b.a = 12345 | ||
|
||
|
||
def main() -> None: | ||
my_outer_struct: outer_struct = outer_struct() | ||
my_inner_struct: inner_struct = my_outer_struct.b | ||
|
||
assert my_outer_struct.b.a == 0 | ||
|
||
my_outer_struct.b.a = 12345 | ||
assert my_outer_struct.b.a == 12345 | ||
|
||
my_outer_struct.b.a = 0 | ||
assert my_outer_struct.b.a == 0 | ||
|
||
update_my_outer_struct(my_outer_struct) | ||
assert my_outer_struct.b.a == 12345 | ||
|
||
my_inner_struct.a = 1111 | ||
assert my_inner_struct.a == 1111 | ||
|
||
update_my_inner_struct(my_inner_struct) | ||
assert my_inner_struct.a == 99999 | ||
|
||
main() |
This file contains 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 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 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 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 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
Oops, something went wrong.