Skip to content

Commit 467081e

Browse files
authored
Merge pull request #2465 from anutosh491/symbolics_15
Using basic_new_heap for assigning elements of symbolic list
2 parents 693afee + 382793e commit 467081e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ RUN(NAME symbolics_12 LABELS cpython_sym c_sym llvm_sym NOFAST)
720720
RUN(NAME symbolics_13 LABELS cpython_sym c_sym llvm_sym NOFAST)
721721
RUN(NAME symbolics_14 LABELS cpython_sym llvm_sym NOFAST)
722722
RUN(NAME test_gruntz LABELS cpython_sym c_sym llvm_sym NOFAST)
723+
RUN(NAME symbolics_15 LABELS c_sym llvm_sym NOFAST)
723724

724725
RUN(NAME sizeof_01 LABELS llvm c
725726
EXTRAFILES sizeof_01b.c)

integration_tests/symbolics_15.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from lpython import ccall, CPtr, p_c_pointer, pointer, i64, empty_c_void_p, Out
2+
import os
3+
4+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
5+
def basic_new_stack(x: CPtr) -> None:
6+
pass
7+
8+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
9+
def basic_new_heap() -> CPtr:
10+
pass
11+
12+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
13+
def basic_const_pi(x: CPtr) -> None:
14+
pass
15+
16+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
17+
def basic_assign(x: CPtr, y:CPtr) -> None:
18+
pass
19+
20+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
21+
def basic_str(x: CPtr) -> str:
22+
pass
23+
24+
@ccall(header="symengine/cwrapper.h", c_shared_lib="symengine", c_shared_lib_path=f"{os.environ['CONDA_PREFIX']}/lib")
25+
def basic_free_stack(x: CPtr) -> None:
26+
pass
27+
28+
def mmrv(r: Out[list[CPtr]]) -> None:
29+
# x: S = pi
30+
_x: i64 = i64(0)
31+
x: CPtr = empty_c_void_p()
32+
p_c_pointer(pointer(_x, i64), x)
33+
basic_new_stack(x)
34+
basic_const_pi(x)
35+
36+
# l1: list[S]
37+
l1: list[CPtr] = []
38+
39+
# l1 = [x]
40+
i: i32 = 0
41+
Len: i32 = 1
42+
for i in range(Len):
43+
tmp: CPtr = basic_new_heap()
44+
l1.append(tmp)
45+
basic_assign(l1[0], x)
46+
47+
# print(l1[0])
48+
s1: str = basic_str(l1[0])
49+
print(s1)
50+
assert s1 == "pi"
51+
52+
# r = l1
53+
r = l1
54+
55+
basic_free_stack(x)
56+
57+
def test_mrv():
58+
# ans : list[S]
59+
# temp : list[S]
60+
ans: list[CPtr] = []
61+
temp: list[CPtr] = []
62+
63+
# mmrv(ans)
64+
# temp = ans
65+
mmrv(ans)
66+
temp = ans
67+
68+
# print(temp[0])
69+
s2: str = basic_str(temp[0])
70+
print(s2)
71+
assert s2 == "pi"
72+
73+
test_mrv()

0 commit comments

Comments
 (0)