Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using basic_new_heap for assigning elements of symbolic list #2465

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ RUN(NAME symbolics_12 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_13 LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_14 LABELS cpython_sym llvm_sym NOFAST)
RUN(NAME test_gruntz LABELS cpython_sym c_sym llvm_sym NOFAST)
RUN(NAME symbolics_15 LABELS c_sym llvm_sym NOFAST)

RUN(NAME sizeof_01 LABELS llvm c
EXTRAFILES sizeof_01b.c)
Expand Down
73 changes: 73 additions & 0 deletions integration_tests/symbolics_15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from lpython import ccall, CPtr, p_c_pointer, pointer, i64, empty_c_void_p, Out
import os

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_new_stack(x: CPtr) -> None:
pass

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_new_heap() -> CPtr:
pass

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_const_pi(x: CPtr) -> None:
pass

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_assign(x: CPtr, y:CPtr) -> None:
pass

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_str(x: CPtr) -> str:
pass

@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
def basic_free_stack(x: CPtr) -> None:
pass

def mmrv(r: Out[list[CPtr]]) -> None:
# x: S = pi
_x: i64 = i64(0)
x: CPtr = empty_c_void_p()
p_c_pointer(pointer(_x, i64), x)
basic_new_stack(x)
basic_const_pi(x)

# l1: list[S]
l1: list[CPtr] = []

# l1 = [x]
i: i32 = 0
Len: i32 = 1
for i in range(Len):
tmp: CPtr = basic_new_heap()
l1.append(tmp)
basic_assign(l1[0], x)

# print(l1[0])
s1: str = basic_str(l1[0])
print(s1)
assert s1 == "pi"

# r = l1
r = l1

basic_free_stack(x)

def test_mrv():
# ans : list[S]
# temp : list[S]
ans: list[CPtr] = []
temp: list[CPtr] = []

# mmrv(ans)
# temp = ans
mmrv(ans)
temp = ans

# print(temp[0])
s2: str = basic_str(temp[0])
print(s2)
assert s2 == "pi"

test_mrv()
Loading