Skip to content

Commit b661d10

Browse files
committed
Add tests
1 parent 1d5a7e7 commit b661d10

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ RUN(NAME global_syms_04 LABELS cpython llvm c wasm wasm_x64)
525525
RUN(NAME global_syms_05 LABELS cpython llvm c)
526526
RUN(NAME global_syms_06 LABELS cpython llvm c)
527527

528+
RUN(NAME callback_01 LABELS cpython llvm)
529+
528530
# Intrinsic Functions
529531
RUN(NAME intrinsics_01 LABELS cpython llvm) # any
530532

integration_tests/callback_01.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from lpython import i32, Callable
2+
3+
4+
def f(x: i32) -> i32:
5+
return x + 1
6+
7+
def f2(x: i32) -> i32:
8+
return x + 10
9+
10+
def f3(x: i32) -> i32:
11+
return f(x) + f2(x)
12+
13+
14+
def g(func: Callable[[i32], i32], arg: i32) -> i32:
15+
ret: i32
16+
ret = func(arg)
17+
return ret
18+
19+
20+
def check():
21+
assert g(f, 10) == 11
22+
assert g(f2, 20) == 30
23+
assert g(f3, 5) == 21
24+
25+
26+
check()

src/runtime/lpython/lpython.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__slots__ = ["i8", "i16", "i32", "i64", "f32", "f64", "c32", "c64", "CPtr",
1010
"overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer",
1111
"p_c_pointer", "vectorize", "inline", "Union", "static", "with_goto",
12-
"packed", "Const", "sizeof", "ccallable", "ccallback"]
12+
"packed", "Const", "sizeof", "ccallable", "ccallback", "Callable"]
1313

1414
# data-types
1515

@@ -55,6 +55,7 @@ def __init__(self, type, dims):
5555
c64 = Type("c64")
5656
CPtr = Type("c_ptr")
5757
Const = ConstType("Const")
58+
Callable = Type("Callable")
5859
Union = ctypes.Union
5960
Pointer = PointerType("Pointer")
6061

0 commit comments

Comments
 (0)