Skip to content

Commit 638b052

Browse files
authored
Merge pull request #2218 from Smit-create/const_lp_dec
Allow Const argument in `@lpython`
2 parents 9350838 + 8b983e2 commit 638b052

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

integration_tests/lpython_decorator_02.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from numpy import array
2-
from lpython import i32, i64, f64, lpython, TypeVar
2+
from lpython import i32, i64, f64, lpython, TypeVar, Const
33

44
n = TypeVar("n")
55

@@ -17,6 +17,10 @@ def multiply_02(n: i32, x: i64[:], y: i64[:]) -> i64[n]:
1717
z[i] = x[i] * y[i]
1818
return z
1919

20+
@lpython
21+
def const_arg_sum(x: Const[i32]) -> i32:
22+
return 10 + x
23+
2024

2125
def test_01():
2226
size = 5
@@ -30,5 +34,6 @@ def test_01():
3034
z = multiply_02(size, x, y)
3135
for i in range(size):
3236
assert z[i] == x[i] * y[i]
37+
assert const_arg_sum(size) == size + 10
3338

3439
test_01()

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,8 @@ R"(#include <stdio.h>
697697
}
698698
} case ASR::ttypeType::Logical : {
699699
return "p";
700+
} case ASR::ttypeType::Const : {
701+
return get_type_format(ASR::down_cast<ASR::Const_t>(type)->m_type);
700702
} case ASR::ttypeType::Array : {
701703
return "O";
702704
} default: {

0 commit comments

Comments
 (0)