Skip to content

Commit

Permalink
Merge main into set_data_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kabra1110 committed Jul 11, 2023
2 parents 31080dc + a2715e6 commit 1a92511
Show file tree
Hide file tree
Showing 195 changed files with 5,670 additions and 2,729 deletions.
20 changes: 16 additions & 4 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ RUN(NAME bindc_04 LABELS llvm c NOFAST)
RUN(NAME bindc_07 LABELS cpython llvm c NOFAST)
RUN(NAME bindc_08 LABELS cpython llvm c)
RUN(NAME bindc_09 LABELS cpython llvm c)
RUN(NAME bindc_09b LABELS cpython llvm c)
RUN(NAME bindc_10 LABELS cpython llvm c NOFAST)
RUN(NAME bindc_11 LABELS cpython) # This is CPython test only
RUN(NAME exit_01 LABELS cpython llvm c NOFAST)
RUN(NAME exit_02 FAIL LABELS cpython llvm c NOFAST)
RUN(NAME exit_03 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Expand Down Expand Up @@ -418,6 +421,7 @@ RUN(NAME expr_15 LABELS cpython llvm c)
RUN(NAME expr_16 LABELS cpython c)
RUN(NAME expr_17 LABELS cpython llvm c)
RUN(NAME expr_18 FAIL LABELS cpython llvm c)
RUN(NAME expr_19 LABELS cpython llvm c)

RUN(NAME expr_01u LABELS cpython llvm c NOFAST)
RUN(NAME expr_02u LABELS cpython llvm c NOFAST)
Expand Down Expand Up @@ -456,6 +460,7 @@ RUN(NAME test_list_repeat LABELS cpython llvm NOFAST)
RUN(NAME test_list_reverse LABELS cpython llvm)
RUN(NAME test_list_pop LABELS cpython llvm NOFAST) # TODO: Remove NOFAST from here.
RUN(NAME test_list_pop2 LABELS cpython llvm NOFAST) # TODO: Remove NOFAST from here.
RUN(NAME test_list_compare LABELS cpython llvm)
RUN(NAME test_tuple_01 LABELS cpython llvm c)
RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST)
RUN(NAME test_tuple_03 LABELS cpython llvm c)
Expand Down Expand Up @@ -553,16 +558,19 @@ RUN(NAME test_ConstantEllipsis LABLES cpython llvm c)
RUN(NAME test_max_min LABELS cpython llvm c)
RUN(NAME test_global LABELS cpython llvm c)
RUN(NAME test_global_decl LABELS cpython llvm c)
RUN(NAME test_integer_bitnot LABELS cpython llvm c wasm)
RUN(NAME test_unsign_int_bitnot LABELS cpython llvm c)
RUN(NAME test_ifexp_01 LABELS cpython llvm c)
RUN(NAME test_ifexp_02 LABELS cpython llvm c)
RUN(NAME test_unary_minus LABELS cpython llvm c)
RUN(NAME test_unary_plus LABELS cpython llvm c)
RUN(NAME test_unary_op_01 LABELS cpython llvm c) # unary minus
RUN(NAME test_unary_op_02 LABELS cpython llvm c) # unary plus
RUN(NAME test_unary_op_03 LABELS cpython llvm c wasm) # unary bitinvert
RUN(NAME test_unary_op_04 LABELS cpython llvm c) # unary bitinvert
RUN(NAME test_unary_op_05 LABELS cpython llvm c) # unsigned unary minus, plus
RUN(NAME test_unary_op_06 LABELS cpython llvm c) # unsigned unary bitnot
RUN(NAME test_bool_binop LABELS cpython llvm c)
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
RUN(NAME structs_01 LABELS cpython llvm c)
RUN(NAME structs_02 LABELS cpython llvm c)
RUN(NAME structs_02b LABELS cpython llvm c NOFAST)
RUN(NAME structs_03 LABELS llvm c)
RUN(NAME structs_04 LABELS cpython llvm c)
RUN(NAME structs_05 LABELS cpython llvm c)
Expand Down Expand Up @@ -598,12 +606,14 @@ RUN(NAME structs_29 LABELS cpython llvm)
RUN(NAME structs_30 LABELS cpython llvm c)
RUN(NAME structs_31 LABELS cpython llvm c)
RUN(NAME structs_32 LABELS cpython llvm c)
RUN(NAME structs_33 LABELS cpython llvm c)

RUN(NAME symbolics_01 LABELS cpython_sym c_sym)
RUN(NAME symbolics_02 LABELS cpython_sym c_sym)
RUN(NAME symbolics_03 LABELS cpython_sym c_sym)
RUN(NAME symbolics_04 LABELS cpython_sym c_sym)
RUN(NAME symbolics_05 LABELS cpython_sym c_sym)
RUN(NAME symbolics_06 LABELS cpython_sym c_sym)

RUN(NAME sizeof_01 LABELS llvm c
EXTRAFILES sizeof_01b.c)
Expand Down Expand Up @@ -631,6 +641,8 @@ RUN(NAME vec_01 LABELS cpython llvm c NOFAST)
RUN(NAME test_str_comparison LABELS cpython llvm c)
RUN(NAME test_bit_length LABELS cpython llvm c)
RUN(NAME str_to_list_cast LABELS cpython llvm c)
RUN(NAME cast_01 LABELS cpython llvm c)
RUN(NAME cast_02 LABELS cpython llvm c)
RUN(NAME test_sys_01 LABELS cpython llvm c NOFAST)
RUN(NAME intent_01 LABELS cpython llvm)

Expand Down
9 changes: 4 additions & 5 deletions integration_tests/bindc_09.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum

from lpython import CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p, pointer, Pointer, i32, ccallable
from lpython import (CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p,
pointer, Pointer, i32, ccallable, InOut)

class Value(Enum):
TEN: i32 = 10
Expand All @@ -17,8 +18,7 @@ class Foo:
class FooC:
value: Value

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

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

p_c_pointer(pointer(foo), foo_ptr)
bar(foo_ptr)
bar(foo)
print(foo.value, foo.value.name)
assert foo.value == Value.FIVE

Expand Down
44 changes: 44 additions & 0 deletions integration_tests/bindc_09b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from enum import Enum

from lpython import CPtr, c_p_pointer, p_c_pointer, dataclass, empty_c_void_p, pointer, Pointer, i32, ccallable

class Value(Enum):
TEN: i32 = 10
TWO: i32 = 2
ONE: i32 = 1
FIVE: i32 = 5

@ccallable
@dataclass
class Foo:
value: Value

@ccallable
@dataclass
class FooC:
value: Value

def bar(foo_ptr: CPtr) -> None:
foo: Pointer[Foo] = c_p_pointer(foo_ptr, Foo)
foo.value = Value.FIVE

def barc(foo_ptr: CPtr) -> None:
foo: Pointer[FooC] = c_p_pointer(foo_ptr, FooC)
foo.value = Value.ONE

def main() -> None:
foo: Foo = Foo(Value.TEN)
fooc: FooC = FooC(Value.TWO)
foo_ptr: CPtr = empty_c_void_p()

p_c_pointer(pointer(foo), foo_ptr)
bar(foo_ptr)
print(foo.value)
assert foo.value == Value.FIVE.value

p_c_pointer(pointer(fooc), foo_ptr)
barc(foo_ptr)
print(fooc.value)
assert fooc.value == Value.ONE.value

main()
32 changes: 32 additions & 0 deletions integration_tests/bindc_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed,
dataclass, ccallable, ccall, i32)

@ccall
def _lfortran_malloc(size: i32) -> CPtr:
pass


def alloc(buf_size:i64) -> CPtr:
return _lfortran_malloc(i32(buf_size))


@ccallable
@packed
@dataclass
class S:
a: i16
b: i64


def main():
p1: CPtr = alloc(sizeof(S))
print(p1)
p2: Pointer[S] = c_p_pointer(p1, S)
p2.a = i16(5)
p2.b = i64(4)
print(p2.a, p2.b)
assert p2.a == i16(5)
assert p2.b == i64(4)


main()
34 changes: 34 additions & 0 deletions integration_tests/bindc_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import numpy, ctypes
from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed,
dataclass, ccallable, ccall, i32)

global_arrays = []


def alloc(buf_size:i64) -> CPtr:
xs = numpy.empty(buf_size, dtype=numpy.uint8)
global_arrays.append(xs)
p = ctypes.c_void_p(xs.ctypes.data)
return ctypes.cast(p.value, ctypes.c_void_p)


@ccallable
@packed
@dataclass
class S:
a: i16
b: i64


def main():
p1: CPtr = alloc(sizeof(S))
print(p1)
p2: Pointer[S] = c_p_pointer(p1, S)
p2.a = i16(5)
p2.b = i64(4)
print(p2.a, p2.b)
assert p2.a == i16(5)
assert p2.b == i64(4)


main()
18 changes: 18 additions & 0 deletions integration_tests/cast_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from lpython import i32, u8, u32, dataclass
from numpy import empty, uint8

@dataclass
class LPBHV_small:
dim : i32 = 4
a : u8[4] = empty(4, dtype=uint8)

def main0():
lphv_small : LPBHV_small = LPBHV_small()
i: i32
for i in range(4):
lphv_small.a[i] = u8(10 + i)
elt: u32 = u32(lphv_small.a[i])
print(elt)
assert elt == u32(10 + i)

main0()
79 changes: 79 additions & 0 deletions integration_tests/cast_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from lpython import u8, u16, u32, u64

def test_01():
x : u32 = u32(10)
print(x)
assert x == u32(10)

y: u16 = u16(x)
print(y)
assert y == u16(10)

z: u64 = u64(y)
print(z)
assert z == u64(10)

w: u8 = u8(z)
print(w)
assert w == u8(10)

def test_02():
x : u64 = u64(11)
print(x)
assert x == u64(11)

y: u8 = u8(x)
print(y)
assert y == u8(11)

z: u16 = u16(y)
print(z)
assert z == u16(11)

w: u32 = u32(z)
print(w)
assert w == u32(11)

def test_03():
x : u32 = u32(-10)
print(x)
assert x == u32(4294967286)

y: u16 = u16(x)
print(y)
assert y == u16(65526)

z: u64 = u64(y)
print(z)
assert z == u64(65526)

w: u8 = u8(z)
print(w)
assert w == u8(246)

def test_04():
x : u64 = u64(-11)
print(x)
# TODO: We are unable to store the following u64 in AST/R
# assert x == u64(18446744073709551605)

y: u8 = u8(x)
print(y)
assert y == u8(245)

z: u16 = u16(y)
print(z)
assert z == u16(245)

w: u32 = u32(z)
print(w)
assert w == u32(245)


def main0():
test_01()
test_02()
test_03()
test_04()

main0()
7 changes: 7 additions & 0 deletions integration_tests/expr_19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from lpython import (f64,)

result : f64 = f64(14)
divisor : f64 = f64(4)
result /= divisor

assert abs(result - f64(3.5)) < 1e-12
2 changes: 0 additions & 2 deletions integration_tests/structs_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def f(a: CPtr) -> None:
y = a2.y
assert x == 3
assert f64(y) == 3.25
a2 = c_p_pointer(a, A)
print(a, a2, pointer(a1))

def g():
b: CPtr = empty_c_void_p()
Expand Down
43 changes: 43 additions & 0 deletions integration_tests/structs_02b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from lpython import (i32, f32, dataclass, CPtr, Pointer, c_p_pointer, pointer,
ccallable, empty_c_void_p, f64, ccall, sizeof, i64)

@ccall
def _lfortran_malloc(size: i32) -> CPtr:
pass

def alloc(buf_size:i64) -> CPtr:
return _lfortran_malloc(i32(buf_size))

@ccallable
@dataclass
class A:
x: i32
y: f32

@ccallable
def f(a: CPtr) -> None:
x: i32
y: f32
a1: A = A(3, f32(3.25))
a2: Pointer[A]
a2 = pointer(a1)
print(a2, pointer(a1))
# TODO: does not work:
#x = a2.x
#y = a2.y
#assert x == 3
#assert f64(y) == 3.25
a2 = c_p_pointer(a, A)
print(a, a2, pointer(a1))
print(a2.x, a2.y)
assert a2.x == 5
assert a2.y == f32(6.0)

def g():
b: CPtr = alloc(sizeof(A))
b2: Pointer[A] = c_p_pointer(b, A)
b2.x = 5
b2.y = f32(6)
f(b)

g()
4 changes: 3 additions & 1 deletion integration_tests/structs_13.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from lpython import i32, i16, i64, CPtr, dataclass, ccall, Pointer, c_p_pointer, sizeof
from lpython import (i32, i16, i64, CPtr, dataclass, ccall, Pointer,
c_p_pointer, sizeof, ccallable)
from numpy import array

@ccallable
@dataclass
class A:
x: i32
Expand Down
Loading

0 comments on commit 1a92511

Please sign in to comment.