Skip to content

Commit 2b719be

Browse files
authored
Merge branch 'main' into backend_lpython
2 parents 2976331 + 0a79bf5 commit 2b719be

File tree

223 files changed

+10034
-4780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+10034
-4780
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ jobs:
437437
strategy:
438438
fail-fast: false
439439
matrix:
440-
python-version: ["3.9", "3.10", "3.11"]
440+
python-version: ["3.9", "3.10", "3.11", "3.12"]
441441
steps:
442442
- uses: actions/checkout@v3
443443
with:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ integration_tests/b5/*
7373
integration_tests/b6/*
7474
integration_tests/_lpython-tmp-test-*
7575
inst/bin/*
76+
*.clj
77+
pass_fortran_*.f90
78+
pass_json_*.json
79+
pass_tree_*.txt
7680
*.tmp
7781
*.tlog
7882
*.filters

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ LFortran, see that project for a list of sponsors.
2929

3030
Here is the list of requirements needed to build LPython:
3131

32-
- Python (3.10+)
3332
- Conda
3433

3534
For Windows, these are additionally required:
@@ -111,6 +110,10 @@ Please follow the below steps for Windows:
111110
- Generate prerequisite files; build in Debug Mode:
112111

113112
```bash
113+
# if you are developing on top of a forked repository; please run following command first
114+
# ./generate_default_tag.sh
115+
116+
114117
./build0.sh
115118
./build1.sh
116119
```
@@ -135,8 +138,8 @@ Please follow the below steps for Windows:
135138

136139
```bash
137140
ctest
138-
inst\bin\lpython examples\expr2.py
139-
inst\bin\lpython examples\expr2.py -o a.out
141+
src\bin\lpython examples\expr2.py
142+
src\bin\lpython examples\expr2.py -o a.out
140143
a.out
141144
```
142145

@@ -169,6 +172,21 @@ Please follow the below steps for Windows:
169172
cd integration_tests
170173
./run_tests.py
171174
```
175+
- Troubleshooting on MacOS latest version:
176+
- In case of recently updated MacOS, you may get a warning like below in some test cases:
177+
```bash
178+
ld: warning: object file (test_list_index2.out.tmp.o) was built for newer macOS version (14.0) than being linked (13.3)
179+
```
180+
This leads to mismatch of hashes with expected output in some test cases, this can be resolved by updating command line tools. Below is a snippet for the same.
181+
182+
```bash
183+
git clean -dfx
184+
sudo rm -rf /Library/Developer/CommandLineTools # make sure you know what you're doing here
185+
sudo xcode-select --install
186+
./build.sh
187+
./run_tests.py
188+
```
189+
172190

173191
### Windows
174192

integration_tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,10 @@ RUN(NAME symbolics_07 LABELS cpython_sym c_sym llvm_sym NOFAST)
714714
RUN(NAME symbolics_08 LABELS cpython_sym c_sym llvm_sym)
715715
RUN(NAME symbolics_09 LABELS cpython_sym c_sym llvm_sym NOFAST)
716716
RUN(NAME symbolics_10 LABELS cpython_sym c_sym llvm_sym NOFAST)
717+
RUN(NAME symbolics_11 LABELS cpython_sym c_sym llvm_sym NOFAST)
718+
RUN(NAME symbolics_12 LABELS cpython_sym c_sym llvm_sym NOFAST)
719+
RUN(NAME symbolics_13 LABELS cpython_sym c_sym llvm_sym NOFAST)
720+
RUN(NAME test_gruntz LABELS cpython_sym llvm_sym NOFAST)
717721

718722
RUN(NAME sizeof_01 LABELS llvm c
719723
EXTRAFILES sizeof_01b.c)
@@ -772,6 +776,7 @@ RUN(NAME func_dep_03 LABELS cpython llvm c)
772776
RUN(NAME func_dep_04 LABELS cpython llvm c)
773777
RUN(NAME func_internal_def_01 LABELS cpython llvm NOFAST)
774778
RUN(NAME func_01 LABELS cpython llvm)
779+
RUN(NAME func_02 LABELS c_sym llvm_sym NOFAST)
775780

776781
RUN(NAME float_01 LABELS cpython llvm c wasm wasm_x64)
777782
RUN(NAME recursive_01 LABELS cpython llvm c wasm wasm_x64 wasm_x86)
@@ -799,6 +804,7 @@ RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython)
799804

800805
# Intrinsic Functions
801806
RUN(NAME intrinsics_01 LABELS cpython llvm NOFAST) # any
807+
RUN(NAME intrinsics_02 LABELS cpython llvm c) # floordiv
802808

803809
# lpython decorator
804810
RUN(NAME lpython_decorator_01 LABELS cpython)

integration_tests/func_02.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lpython import S, Out
2+
from sympy import pi
3+
4+
def func(r: Out[S]) -> None:
5+
r = pi
6+
7+
def test_func():
8+
z: S
9+
func(z)
10+
print(z)
11+
assert z == pi
12+
13+
test_func()

integration_tests/intrinsics_02.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from lpython import Const, i32, f32, f64
2+
3+
foo: Const[i32] = 4
4+
bar: Const[i32] = foo // 2
5+
6+
print(bar)
7+
assert bar == 2
8+
9+
def floordiv1():
10+
a: f64
11+
b: f64
12+
c: f64
13+
a = 5.0
14+
b = 2.0
15+
c = a // b
16+
17+
print(c)
18+
assert c == 2.0
19+
20+
def floordiv2():
21+
a: Const[f32] = f32(5.0)
22+
b: Const[f32] = f32(2.0)
23+
c: f32
24+
c = a // b
25+
26+
print(c)
27+
assert c == f32(2.0)
28+
29+
def floordiv3():
30+
a: f64
31+
b: f64
32+
c: f64
33+
a = 5.0
34+
b = -2.0
35+
c = a // b
36+
37+
print(c)
38+
assert c == -3.0
39+
40+
floordiv1()
41+
floordiv2()
42+
floordiv3()

integration_tests/symbolics_01.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ def main0():
66
y: S = Symbol('y')
77
x = pi
88
z: S = x + y
9+
x = z
10+
print(x)
911
print(z)
12+
assert(x == z)
1013
assert(z == pi + y)
1114
assert(z != S(2)*pi + y)
1215

16+
# testing PR 2404
17+
p: S = Symbol('pi')
18+
print(p)
19+
print(p != pi)
20+
assert(p != pi)
21+
1322
main0()

integration_tests/symbolics_02.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,80 @@
1-
from sympy import Symbol
1+
from sympy import Symbol, pi, Add, Mul, Pow
22
from lpython import S
33

44
def test_symbolic_operations():
55
x: S = Symbol('x')
66
y: S = Symbol('y')
7+
pi1: S = pi
8+
pi2: S = pi
79

810
# Addition
911
z: S = x + y
12+
z1: bool = z.func == Add
13+
z2: bool = z.func == Mul
1014
assert(z == x + y)
15+
assert(z1 == True)
16+
assert(z2 == False)
17+
if z.func == Add:
18+
assert True
19+
else:
20+
assert False
21+
assert(z.func == Add)
22+
assert(z.args[0] == x or z.args[0] == y)
23+
assert(z.args[1] == y or z.args[1] == x)
1124
print(z)
1225

1326
# Subtraction
1427
w: S = x - y
28+
w1: bool = w.func == Add
1529
assert(w == x - y)
30+
assert(w1 == True)
31+
if w.func == Add:
32+
assert True
33+
else:
34+
assert False
35+
assert(w.func == Add)
1636
print(w)
1737

1838
# Multiplication
1939
u: S = x * y
40+
u1: bool = u.func == Mul
2041
assert(u == x * y)
42+
assert(u1 == True)
43+
if u.func == Mul:
44+
assert True
45+
else:
46+
assert False
47+
assert(u.func == Mul)
48+
assert(u.args[0] == x)
49+
assert(u.args[1] == y)
2150
print(u)
2251

2352
# Division
2453
v: S = x / y
54+
v1: bool = v.func == Mul
2555
assert(v == x / y)
56+
assert(v1 == True)
57+
if v.func == Mul:
58+
assert True
59+
else:
60+
assert False
61+
assert(v.func == Mul)
2662
print(v)
2763

2864
# Power
2965
p: S = x ** y
66+
p1: bool = p.func == Pow
67+
p2: bool = p.func == Add
68+
p3: bool = p.func == Mul
3069
assert(p == x ** y)
70+
assert(p1 == True)
71+
assert(p2 == False)
72+
assert(p3 == False)
73+
if p.func == Pow:
74+
assert True
75+
else:
76+
assert False
77+
assert(p.func == Pow)
3178
print(p)
3279

3380
# Casting
@@ -37,4 +84,19 @@ def test_symbolic_operations():
3784
assert(c == S(0))
3885
print(c)
3986

87+
# Comparison
88+
b1: bool = pi1 == pi2
89+
print(b1)
90+
assert(b1 == True)
91+
b2: bool = pi1 != pi
92+
print(b2)
93+
assert(b2 == False)
94+
b3: bool = pi1 != x
95+
print(b3)
96+
assert(b3 == True)
97+
b4: bool = pi == Symbol("x")
98+
print(b4)
99+
assert(b4 == False)
100+
101+
40102
test_symbolic_operations()

integration_tests/symbolics_05.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@ def test_operations():
3232
assert((sin(x) + cos(x)).diff(x) == S(-1)*c + d)
3333
assert((sin(x) + cos(x) + exp(x) + pi).diff(x).expand().diff(x) == exp(x) + S(-1)*c + S(-1)*d)
3434

35+
# test args
36+
assert(a.args[0] == x + y)
37+
assert(a.args[1] == S(2))
38+
assert(b.args[0] == x + y + z)
39+
assert(b.args[1] == S(3))
40+
assert(c.args[0] == x)
41+
assert(d.args[0] == x)
3542

3643
test_operations()

integration_tests/symbolics_06.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ def test_elementary_functions():
2828
# test composite functions
2929
a: S = exp(x)
3030
b: S = sin(a)
31+
b1: bool = b.func == sin
3132
c: S = cos(b)
3233
d: S = log(c)
34+
d1: bool = d.func == log
3335
e: S = Abs(d)
3436
print(e)
37+
assert(b1 == True)
38+
if b.func == sin:
39+
assert True
40+
else:
41+
assert False
42+
assert(b.func == sin)
43+
assert(d1 == True)
44+
if d.func == log:
45+
assert True
46+
else:
47+
assert False
48+
assert(d.func == log)
3549
assert(e == Abs(log(cos(sin(exp(x))))))
3650

3751
test_elementary_functions()

integration_tests/symbolics_11.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from sympy import Symbol, sin, pi
2+
from lpython import S
3+
4+
def test_extraction_of_elements():
5+
x: S = Symbol("x")
6+
l1: list[S] = [x, pi, sin(x), Symbol("y")]
7+
ele1: S = l1[0]
8+
ele2: S = l1[1]
9+
ele3: S = l1[2]
10+
ele4: S = l1[3]
11+
12+
assert(ele1 == x)
13+
assert(ele2 == pi)
14+
assert(ele3 == sin(x))
15+
assert(ele4 == Symbol("y"))
16+
print(ele1, ele2, ele3, ele4)
17+
print(l1[0], l1[1], l1[2], l1[3])
18+
19+
test_extraction_of_elements()

integration_tests/symbolics_12.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from sympy import Symbol, E, log, exp
2+
from lpython import S
3+
4+
def main0():
5+
# Define symbolic variables
6+
x: S = Symbol('x')
7+
y: S = Symbol('y')
8+
9+
# Assign E to the variable x
10+
x = E
11+
12+
# Check if x is equal to E
13+
assert x == E
14+
15+
# Perform some symbolic operations
16+
z: S = x + y
17+
18+
# Check if z is equal to E + y
19+
assert z == E + y
20+
21+
# Check if x is not equal to 2E + y
22+
assert x != S(2) * E + y
23+
24+
# Evaluate some mathematical expressions
25+
expr1: S = log(E)
26+
expr2: S = exp(S(1))
27+
28+
# Check the results
29+
assert expr1 == S(1)
30+
assert expr2 == E ** S(1)
31+
32+
# Print the results
33+
print("x =", x)
34+
print("z =", z)
35+
print("log(E) =", expr1)
36+
print("exp(1) =", expr2)
37+
38+
39+
main0()

integration_tests/symbolics_13.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from lpython import S
2+
from sympy import pi
3+
4+
def func() -> S:
5+
return pi
6+
7+
def test_func():
8+
z: S = func()
9+
print(z)
10+
assert z == pi
11+
12+
test_func()

0 commit comments

Comments
 (0)