Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added struct test #2058

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ RUN(NAME structs_27 LABELS cpython llvm c)
RUN(NAME structs_28 LABELS cpython llvm c)
RUN(NAME structs_29 LABELS cpython llvm)
RUN(NAME structs_30 LABELS cpython llvm c)
RUN(NAME structs_31 LABELS cpython c)

RUN(NAME symbolics_01 LABELS cpython_sym c_sym)
RUN(NAME symbolics_02 LABELS cpython_sym c_sym)
Expand Down
45 changes: 45 additions & 0 deletions integration_tests/structs_31.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from lpython import ccallback, ccall, packed, dataclass, i32, c_p_pointer, Pointer, CPtr, u16, pointer, 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()