Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Apr 24, 2023
1 parent 1d5a7e7 commit b661d10
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ RUN(NAME global_syms_04 LABELS cpython llvm c wasm wasm_x64)
RUN(NAME global_syms_05 LABELS cpython llvm c)
RUN(NAME global_syms_06 LABELS cpython llvm c)

RUN(NAME callback_01 LABELS cpython llvm)

# Intrinsic Functions
RUN(NAME intrinsics_01 LABELS cpython llvm) # any

Expand Down
26 changes: 26 additions & 0 deletions integration_tests/callback_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from lpython import i32, Callable


def f(x: i32) -> i32:
return x + 1

def f2(x: i32) -> i32:
return x + 10

def f3(x: i32) -> i32:
return f(x) + f2(x)


def g(func: Callable[[i32], i32], arg: i32) -> i32:
ret: i32
ret = func(arg)
return ret


def check():
assert g(f, 10) == 11
assert g(f2, 20) == 30
assert g(f3, 5) == 21


check()
3 changes: 2 additions & 1 deletion src/runtime/lpython/lpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
__slots__ = ["i8", "i16", "i32", "i64", "f32", "f64", "c32", "c64", "CPtr",
"overload", "ccall", "TypeVar", "pointer", "c_p_pointer", "Pointer",
"p_c_pointer", "vectorize", "inline", "Union", "static", "with_goto",
"packed", "Const", "sizeof", "ccallable", "ccallback"]
"packed", "Const", "sizeof", "ccallable", "ccallback", "Callable"]

# data-types

Expand Down Expand Up @@ -55,6 +55,7 @@ def __init__(self, type, dims):
c64 = Type("c64")
CPtr = Type("c_ptr")
Const = ConstType("Const")
Callable = Type("Callable")
Union = ctypes.Union
Pointer = PointerType("Pointer")

Expand Down

0 comments on commit b661d10

Please sign in to comment.