forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
97 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from ltypes import i32, f64, dataclass | ||
|
||
@dataclass | ||
class A: | ||
y: f64 | ||
x: i32 | ||
|
||
def verify(s: A[:], x1: i32, y1: f64, x2: i32, y2: f64): | ||
eps: f64 = 1e-12 | ||
print(s[0].x, s[0].y) | ||
assert s[0].x == x1 | ||
assert abs(s[0].y - y1) < eps | ||
print(s[1].x, s[1].y) | ||
assert s[1].x == x2 | ||
assert abs(s[1].y - y2) < eps | ||
|
||
def update_1(s: A): | ||
s.x = 2 | ||
s.y = 1.2 | ||
|
||
def update_2(s: A[:]): | ||
s[1].x = 3 | ||
s[1].y = 2.3 | ||
|
||
def g(): | ||
# TODO: Replace y: A[2] with y: A[2] = [None, None] | ||
# TODO: And enable cpython in integration_tests. | ||
y: A[2] | ||
y[0] = A(1.1, 1) | ||
y[1] = A(2.2, 2) | ||
verify(y, 1, 1.1, 2, 2.2) | ||
update_1(y[0]) | ||
update_2(y) | ||
verify(y, 2, 1.2, 3, 2.3) | ||
|
||
g() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-structs_05-fa98307", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/../integration_tests/structs_05.py", | ||
"infile_hash": "8022943f9e2faac2fac4bd147f9ccba284127429215ddef38d22beb8", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "asr-structs_05-fa98307.stdout", | ||
"stdout_hash": "5611b3927900d1071ff9b00de1306cc5baeba9fefd0947d49552336e", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
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 @@ | ||
(TranslationUnit (SymbolTable 1 {A: (DerivedType (SymbolTable 2 {x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Real 8 []) Source Public Required .false.)}) A [y x] Source Public ()), _lpython_main_program: (Subroutine (SymbolTable 84 {}) _lpython_main_program [] [(SubroutineCall 1 g () [] ())] Source Public Implementation () .false. .false.), abs@__lpython_overloaded_0__abs: (ExternalSymbol 1 abs@__lpython_overloaded_0__abs 8 __lpython_overloaded_0__abs lpython_builtin [] __lpython_overloaded_0__abs Public), g: (Subroutine (SymbolTable 6 {y: (Variable 6 y Local () () Default (Derived 1 A [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) Source Public Required .false.)}) g [] [(= (ArrayItem 6 y [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) ()) (DerivedTypeConstructor 1 A [(RealConstant 1.10000000000000009e+00 (Real 8 [])) (IntegerConstant 1 (Integer 4 []))] (Derived 1 A []) ()) ()) (= (ArrayItem 6 y [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) ()) (DerivedTypeConstructor 1 A [(RealConstant 2.20000000000000018e+00 (Real 8 [])) (IntegerConstant 2 (Integer 4 []))] (Derived 1 A []) ()) ()) (SubroutineCall 1 verify () [((Var 6 y)) ((IntegerConstant 1 (Integer 4 []))) ((RealConstant 1.10000000000000009e+00 (Real 8 []))) ((IntegerConstant 2 (Integer 4 []))) ((RealConstant 2.20000000000000018e+00 (Real 8 [])))] ()) (SubroutineCall 1 update_1 () [((ArrayItem 6 y [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [((IntegerConstant 0 (Integer 4 [])) (IntegerBinOp (IntegerConstant 2 (Integer 4 [])) Sub (IntegerConstant 1 (Integer 4 [])) (Integer 4 []) (IntegerConstant 1 (Integer 4 []))))]) ()))] ()) (SubroutineCall 1 update_2 () [((Var 6 y))] ()) (SubroutineCall 1 verify () [((Var 6 y)) ((IntegerConstant 2 (Integer 4 []))) ((RealConstant 1.19999999999999996e+00 (Real 8 []))) ((IntegerConstant 3 (Integer 4 []))) ((RealConstant 2.29999999999999982e+00 (Real 8 [])))] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 83 {}) main_program [] [(SubroutineCall 1 _lpython_main_program () [] ())]), update_1: (Subroutine (SymbolTable 4 {s: (Variable 4 s In () () Default (Derived 1 A []) Source Public Required .false.)}) update_1 [(Var 4 s)] [(= (DerivedRef (Var 4 s) 2 x (Integer 4 []) ()) (IntegerConstant 2 (Integer 4 [])) ()) (= (DerivedRef (Var 4 s) 2 y (Real 8 []) ()) (RealConstant 1.19999999999999996e+00 (Real 8 [])) ())] Source Public Implementation () .false. .false.), update_2: (Subroutine (SymbolTable 5 {s: (Variable 5 s InOut () () Default (Derived 1 A [(() ())]) Source Public Required .false.)}) update_2 [(Var 5 s)] [(= (DerivedRef (ArrayItem 5 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 x (Integer 4 []) ()) (IntegerConstant 3 (Integer 4 [])) ()) (= (DerivedRef (ArrayItem 5 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 y (Real 8 []) ()) (RealConstant 2.29999999999999982e+00 (Real 8 [])) ())] Source Public Implementation () .false. .false.), verify: (Subroutine (SymbolTable 3 {abs: (ExternalSymbol 3 abs 8 abs lpython_builtin [] abs Private), eps: (Variable 3 eps Local () () Default (Real 8 []) Source Public Required .false.), s: (Variable 3 s InOut () () Default (Derived 1 A [(() ())]) Source Public Required .false.), x1: (Variable 3 x1 In () () Default (Integer 4 []) Source Public Required .false.), x2: (Variable 3 x2 In () () Default (Integer 4 []) Source Public Required .false.), y1: (Variable 3 y1 In () () Default (Real 8 []) Source Public Required .false.), y2: (Variable 3 y2 In () () Default (Real 8 []) Source Public Required .false.)}) verify [(Var 3 s) (Var 3 x1) (Var 3 y1) (Var 3 x2) (Var 3 y2)] [(= (Var 3 eps) (RealConstant 9.99999999999999980e-13 (Real 8 [])) ()) (Print () [(DerivedRef (ArrayItem 3 s [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 x (Integer 4 []) ()) (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 y (Real 8 []) ())] () ()) (Assert (IntegerCompare (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 x (Integer 4 []) ()) Eq (Var 3 x1) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 0 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 y (Real 8 []) ()) Sub (Var 3 y1) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ()) (Print () [(DerivedRef (ArrayItem 3 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 x (Integer 4 []) ()) (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 y (Real 8 []) ())] () ()) (Assert (IntegerCompare (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 x (Integer 4 []) ()) Eq (Var 3 x2) (Logical 4 []) ()) ()) (Assert (RealCompare (FunctionCall 1 abs@__lpython_overloaded_0__abs 3 abs [((RealBinOp (DerivedRef (ArrayItem 3 s [(() (IntegerConstant 1 (Integer 4 [])) ())] (Derived 1 A [(() ())]) ()) 2 y (Real 8 []) ()) Sub (Var 3 y2) (Real 8 []) ()))] (Real 8 []) () ()) Lt (Var 3 eps) (Logical 4 []) ()) ())] Source Public Implementation () .false. .false.)}) []) |
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