Skip to content

Commit db32da4

Browse files
committed
Merge main into set_data_structure
2 parents 31080dc + a2715e6 commit db32da4

File tree

195 files changed

+5704
-2729
lines changed

Some content is hidden

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

195 files changed

+5704
-2729
lines changed

integration_tests/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ RUN(NAME bindc_04 LABELS llvm c NOFAST)
374374
RUN(NAME bindc_07 LABELS cpython llvm c NOFAST)
375375
RUN(NAME bindc_08 LABELS cpython llvm c)
376376
RUN(NAME bindc_09 LABELS cpython llvm c)
377+
RUN(NAME bindc_09b LABELS cpython llvm c)
378+
RUN(NAME bindc_10 LABELS cpython llvm c NOFAST)
379+
RUN(NAME bindc_11 LABELS cpython) # This is CPython test only
377380
RUN(NAME exit_01 LABELS cpython llvm c NOFAST)
378381
RUN(NAME exit_02 FAIL LABELS cpython llvm c NOFAST)
379382
RUN(NAME exit_03 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
@@ -418,6 +421,7 @@ RUN(NAME expr_15 LABELS cpython llvm c)
418421
RUN(NAME expr_16 LABELS cpython c)
419422
RUN(NAME expr_17 LABELS cpython llvm c)
420423
RUN(NAME expr_18 FAIL LABELS cpython llvm c)
424+
RUN(NAME expr_19 LABELS cpython llvm c)
421425

422426
RUN(NAME expr_01u LABELS cpython llvm c NOFAST)
423427
RUN(NAME expr_02u LABELS cpython llvm c NOFAST)
@@ -456,6 +460,7 @@ RUN(NAME test_list_repeat LABELS cpython llvm NOFAST)
456460
RUN(NAME test_list_reverse LABELS cpython llvm)
457461
RUN(NAME test_list_pop LABELS cpython llvm NOFAST) # TODO: Remove NOFAST from here.
458462
RUN(NAME test_list_pop2 LABELS cpython llvm NOFAST) # TODO: Remove NOFAST from here.
463+
RUN(NAME test_list_compare LABELS cpython llvm)
459464
RUN(NAME test_tuple_01 LABELS cpython llvm c)
460465
RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST)
461466
RUN(NAME test_tuple_03 LABELS cpython llvm c)
@@ -553,16 +558,19 @@ RUN(NAME test_ConstantEllipsis LABLES cpython llvm c)
553558
RUN(NAME test_max_min LABELS cpython llvm c)
554559
RUN(NAME test_global LABELS cpython llvm c)
555560
RUN(NAME test_global_decl LABELS cpython llvm c)
556-
RUN(NAME test_integer_bitnot LABELS cpython llvm c wasm)
557-
RUN(NAME test_unsign_int_bitnot LABELS cpython llvm c)
558561
RUN(NAME test_ifexp_01 LABELS cpython llvm c)
559562
RUN(NAME test_ifexp_02 LABELS cpython llvm c)
560-
RUN(NAME test_unary_minus LABELS cpython llvm c)
561-
RUN(NAME test_unary_plus LABELS cpython llvm c)
563+
RUN(NAME test_unary_op_01 LABELS cpython llvm c) # unary minus
564+
RUN(NAME test_unary_op_02 LABELS cpython llvm c) # unary plus
565+
RUN(NAME test_unary_op_03 LABELS cpython llvm c wasm) # unary bitinvert
566+
RUN(NAME test_unary_op_04 LABELS cpython llvm c) # unary bitinvert
567+
RUN(NAME test_unary_op_05 LABELS cpython llvm c) # unsigned unary minus, plus
568+
RUN(NAME test_unary_op_06 LABELS cpython llvm c) # unsigned unary bitnot
562569
RUN(NAME test_bool_binop LABELS cpython llvm c)
563570
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
564571
RUN(NAME structs_01 LABELS cpython llvm c)
565572
RUN(NAME structs_02 LABELS cpython llvm c)
573+
RUN(NAME structs_02b LABELS cpython llvm c NOFAST)
566574
RUN(NAME structs_03 LABELS llvm c)
567575
RUN(NAME structs_04 LABELS cpython llvm c)
568576
RUN(NAME structs_05 LABELS cpython llvm c)
@@ -598,12 +606,14 @@ RUN(NAME structs_29 LABELS cpython llvm)
598606
RUN(NAME structs_30 LABELS cpython llvm c)
599607
RUN(NAME structs_31 LABELS cpython llvm c)
600608
RUN(NAME structs_32 LABELS cpython llvm c)
609+
RUN(NAME structs_33 LABELS cpython llvm c)
601610

602611
RUN(NAME symbolics_01 LABELS cpython_sym c_sym)
603612
RUN(NAME symbolics_02 LABELS cpython_sym c_sym)
604613
RUN(NAME symbolics_03 LABELS cpython_sym c_sym)
605614
RUN(NAME symbolics_04 LABELS cpython_sym c_sym)
606615
RUN(NAME symbolics_05 LABELS cpython_sym c_sym)
616+
RUN(NAME symbolics_06 LABELS cpython_sym c_sym)
607617

608618
RUN(NAME sizeof_01 LABELS llvm c
609619
EXTRAFILES sizeof_01b.c)
@@ -631,6 +641,8 @@ RUN(NAME vec_01 LABELS cpython llvm c NOFAST)
631641
RUN(NAME test_str_comparison LABELS cpython llvm c)
632642
RUN(NAME test_bit_length LABELS cpython llvm c)
633643
RUN(NAME str_to_list_cast LABELS cpython llvm c)
644+
RUN(NAME cast_01 LABELS cpython llvm c)
645+
RUN(NAME cast_02 LABELS cpython llvm c)
634646
RUN(NAME test_sys_01 LABELS cpython llvm c NOFAST)
635647
RUN(NAME intent_01 LABELS cpython llvm)
636648

integration_tests/bindc_09.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum
22

3-
from lpython import CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p, pointer, Pointer, i32, ccallable
3+
from lpython import (CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p,
4+
pointer, Pointer, i32, ccallable, InOut)
45

56
class Value(Enum):
67
TEN: i32 = 10
@@ -17,8 +18,7 @@ class Foo:
1718
class FooC:
1819
value: Value
1920

20-
def bar(foo_ptr: CPtr) -> None:
21-
foo: Pointer[Foo] = c_p_pointer(foo_ptr, Foo)
21+
def bar(foo: InOut[Foo]) -> None:
2222
foo.value = Value.FIVE
2323

2424
def barc(foo_ptr: CPtr) -> None:
@@ -30,8 +30,7 @@ def main() -> None:
3030
fooc: FooC = FooC(Value.TWO)
3131
foo_ptr: CPtr = empty_c_void_p()
3232

33-
p_c_pointer(pointer(foo), foo_ptr)
34-
bar(foo_ptr)
33+
bar(foo)
3534
print(foo.value, foo.value.name)
3635
assert foo.value == Value.FIVE
3736

integration_tests/bindc_09b.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from enum import Enum
2+
3+
from lpython import CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p, pointer, Pointer, i32, ccallable
4+
5+
class Value(Enum):
6+
TEN: i32 = 10
7+
TWO: i32 = 2
8+
ONE: i32 = 1
9+
FIVE: i32 = 5
10+
11+
@ccallable
12+
@dataclass
13+
class Foo:
14+
value: Value
15+
16+
@ccallable
17+
@dataclass
18+
class FooC:
19+
value: Value
20+
21+
def bar(foo_ptr: CPtr) -> None:
22+
foo: Pointer[Foo] = c_p_pointer(foo_ptr, Foo)
23+
foo.value = Value.FIVE
24+
25+
def barc(foo_ptr: CPtr) -> None:
26+
foo: Pointer[FooC] = c_p_pointer(foo_ptr, FooC)
27+
foo.value = Value.ONE
28+
29+
def main() -> None:
30+
foo: Foo = Foo(Value.TEN)
31+
fooc: FooC = FooC(Value.TWO)
32+
foo_ptr: CPtr = empty_c_void_p()
33+
34+
p_c_pointer(pointer(foo), foo_ptr)
35+
bar(foo_ptr)
36+
print(foo.value)
37+
assert foo.value == Value.FIVE.value
38+
39+
p_c_pointer(pointer(fooc), foo_ptr)
40+
barc(foo_ptr)
41+
print(fooc.value)
42+
assert fooc.value == Value.ONE.value
43+
44+
main()

integration_tests/bindc_10.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed,
2+
dataclass, ccallable, ccall, i32)
3+
4+
@ccall
5+
def _lfortran_malloc(size: i32) -> CPtr:
6+
pass
7+
8+
9+
def alloc(buf_size:i64) -> CPtr:
10+
return _lfortran_malloc(i32(buf_size))
11+
12+
13+
@ccallable
14+
@packed
15+
@dataclass
16+
class S:
17+
a: i16
18+
b: i64
19+
20+
21+
def main():
22+
p1: CPtr = alloc(sizeof(S))
23+
print(p1)
24+
p2: Pointer[S] = c_p_pointer(p1, S)
25+
p2.a = i16(5)
26+
p2.b = i64(4)
27+
print(p2.a, p2.b)
28+
assert p2.a == i16(5)
29+
assert p2.b == i64(4)
30+
31+
32+
main()

integration_tests/bindc_11.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy, ctypes
2+
from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed,
3+
dataclass, ccallable, ccall, i32)
4+
5+
global_arrays = []
6+
7+
8+
def alloc(buf_size:i64) -> CPtr:
9+
xs = numpy.empty(buf_size, dtype=numpy.uint8)
10+
global_arrays.append(xs)
11+
p = ctypes.c_void_p(xs.ctypes.data)
12+
return ctypes.cast(p.value, ctypes.c_void_p)
13+
14+
15+
@ccallable
16+
@packed
17+
@dataclass
18+
class S:
19+
a: i16
20+
b: i64
21+
22+
23+
def main():
24+
p1: CPtr = alloc(sizeof(S))
25+
print(p1)
26+
p2: Pointer[S] = c_p_pointer(p1, S)
27+
p2.a = i16(5)
28+
p2.b = i64(4)
29+
print(p2.a, p2.b)
30+
assert p2.a == i16(5)
31+
assert p2.b == i64(4)
32+
33+
34+
main()

integration_tests/cast_01.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from lpython import i32, u8, u32, dataclass
2+
from numpy import empty, uint8
3+
4+
@dataclass
5+
class LPBHV_small:
6+
dim : i32 = 4
7+
a : u8[4] = empty(4, dtype=uint8)
8+
9+
def main0():
10+
lphv_small : LPBHV_small = LPBHV_small()
11+
i: i32
12+
for i in range(4):
13+
lphv_small.a[i] = u8(10 + i)
14+
elt: u32 = u32(lphv_small.a[i])
15+
print(elt)
16+
assert elt == u32(10 + i)
17+
18+
main0()

integration_tests/cast_02.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from lpython import u8, u16, u32, u64
2+
3+
def test_01():
4+
x : u32 = u32(10)
5+
print(x)
6+
assert x == u32(10)
7+
8+
y: u16 = u16(x)
9+
print(y)
10+
assert y == u16(10)
11+
12+
z: u64 = u64(y)
13+
print(z)
14+
assert z == u64(10)
15+
16+
w: u8 = u8(z)
17+
print(w)
18+
assert w == u8(10)
19+
20+
def test_02():
21+
x : u64 = u64(11)
22+
print(x)
23+
assert x == u64(11)
24+
25+
y: u8 = u8(x)
26+
print(y)
27+
assert y == u8(11)
28+
29+
z: u16 = u16(y)
30+
print(z)
31+
assert z == u16(11)
32+
33+
w: u32 = u32(z)
34+
print(w)
35+
assert w == u32(11)
36+
37+
def test_03():
38+
x : u32 = u32(-10)
39+
print(x)
40+
assert x == u32(4294967286)
41+
42+
y: u16 = u16(x)
43+
print(y)
44+
assert y == u16(65526)
45+
46+
z: u64 = u64(y)
47+
print(z)
48+
assert z == u64(65526)
49+
50+
w: u8 = u8(z)
51+
print(w)
52+
assert w == u8(246)
53+
54+
def test_04():
55+
x : u64 = u64(-11)
56+
print(x)
57+
# TODO: We are unable to store the following u64 in AST/R
58+
# assert x == u64(18446744073709551605)
59+
60+
y: u8 = u8(x)
61+
print(y)
62+
assert y == u8(245)
63+
64+
z: u16 = u16(y)
65+
print(z)
66+
assert z == u16(245)
67+
68+
w: u32 = u32(z)
69+
print(w)
70+
assert w == u32(245)
71+
72+
73+
def main0():
74+
test_01()
75+
test_02()
76+
test_03()
77+
test_04()
78+
79+
main0()

integration_tests/expr_19.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from lpython import (f64,)
2+
3+
result : f64 = f64(14)
4+
divisor : f64 = f64(4)
5+
result /= divisor
6+
7+
assert abs(result - f64(3.5)) < 1e-12

integration_tests/structs_02.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def f(a: CPtr) -> None:
1717
y = a2.y
1818
assert x == 3
1919
assert f64(y) == 3.25
20-
a2 = c_p_pointer(a, A)
21-
print(a, a2, pointer(a1))
2220

2321
def g():
2422
b: CPtr = empty_c_void_p()

integration_tests/structs_02b.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from lpython import (i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer,
2+
ccallable, empty_c_void_p, f64, ccall, sizeof, i64)
3+
4+
@ccall
5+
def _lfortran_malloc(size: i32) -> CPtr:
6+
pass
7+
8+
def alloc(buf_size:i64) -> CPtr:
9+
return _lfortran_malloc(i32(buf_size))
10+
11+
@ccallable
12+
@dataclass
13+
class A:
14+
x: i32
15+
y: f32
16+
17+
@ccallable
18+
def f(a: CPtr) -> None:
19+
x: i32
20+
y: f32
21+
a1: A = A(3, f32(3.25))
22+
a2: Pointer[A]
23+
a2 = pointer(a1)
24+
print(a2, pointer(a1))
25+
# TODO: does not work:
26+
#x = a2.x
27+
#y = a2.y
28+
#assert x == 3
29+
#assert f64(y) == 3.25
30+
a2 = c_p_pointer(a, A)
31+
print(a, a2, pointer(a1))
32+
print(a2.x, a2.y)
33+
assert a2.x == 5
34+
assert a2.y == f32(6.0)
35+
36+
def g():
37+
b: CPtr = alloc(sizeof(A))
38+
b2: Pointer[A] = c_p_pointer(b, A)
39+
b2.x = 5
40+
b2.y = f32(6)
41+
f(b)
42+
43+
g()

0 commit comments

Comments
 (0)