Skip to content

Commit

Permalink
Merge pull request lcompilers#2218 from Smit-create/const_lp_dec
Browse files Browse the repository at this point in the history
Allow Const argument in `@lpython`
  • Loading branch information
certik committed Jul 29, 2023
2 parents 9350838 + 8b983e2 commit 638b052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion integration_tests/lpython_decorator_02.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import array
from lpython import i32, i64, f64, lpython, TypeVar
from lpython import i32, i64, f64, lpython, TypeVar, Const

n = TypeVar("n")

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

@lpython
def const_arg_sum(x: Const[i32]) -> i32:
return 10 + x


def test_01():
size = 5
Expand All @@ -30,5 +34,6 @@ def test_01():
z = multiply_02(size, x, y)
for i in range(size):
assert z[i] == x[i] * y[i]
assert const_arg_sum(size) == size + 10

test_01()
2 changes: 2 additions & 0 deletions src/libasr/codegen/asr_to_c_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ R"(#include <stdio.h>
}
} case ASR::ttypeType::Logical : {
return "p";
} case ASR::ttypeType::Const : {
return get_type_format(ASR::down_cast<ASR::Const_t>(type)->m_type);
} case ASR::ttypeType::Array : {
return "O";
} default: {
Expand Down

0 comments on commit 638b052

Please sign in to comment.