Skip to content

Commit

Permalink
Merge pull request #100 from czgdp1807/struct_01
Browse files Browse the repository at this point in the history
Ported ``integration_tests/structs_01.py`` from LPython and improve LC to compile it
  • Loading branch information
czgdp1807 authored Feb 29, 2024
2 parents f1443a3 + 1d69d52 commit edec429
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_03.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_04.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_05.cpp LABELS gcc llvm NOFAST)

RUN(NAME pointer_01.cpp LABELS gcc)
RUN(NAME pointer_02.cpp LABELS gcc)
Expand Down
48 changes: 48 additions & 0 deletions integration_tests/struct_05.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>

struct A_t {
float y;
int32_t x;

constexpr A_t(float y_, int32_t x_): y(y_), x(x_) {}
};

void assert(bool condition) {
if( !condition ) {
exit(2);
}
}

void f(const A_t& a) {
std::cout << a.x << std::endl;
std::cout << a.y << std::endl;
}

void change_struct(A_t& a) {
a.x = a.x + 1;
a.y = a.y + float(1);
}

void g() {
A_t x = A_t(float(3.25), 3);
f(x);
assert( x.x == 3 );
assert( double(x.y) == 3.25 );

x.x = 5;
x.y = float(5.5);
f(x);
assert( x.x == 5 );
assert( double(x.y) == 5.5 );
change_struct(x);
assert( x.x == 6 );
assert( double(x.y) == 6.5 );
}

int main() {

g();

return 0;

}

0 comments on commit edec429

Please sign in to comment.