Skip to content

Commit 05e7bb2

Browse files
authored
Merge pull request #315 from Smit-create/i239
Add `interface` decorator
2 parents d9bd57d + 7c4a193 commit 05e7bb2

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
12301230
current_procedure_abi_type = ASR::abiType::BindC;
12311231
} else if (name == "overload") {
12321232
overload = true;
1233+
} else if (name == "interface") {
1234+
// TODO: Implement @interface
12331235
} else {
12341236
throw SemanticError("Decorator: " + name + " is not supported",
12351237
x.base.base.loc);

src/runtime/lpython_builtin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def bool(c: c64) -> bool:
148148
pass
149149

150150

151+
@interface
151152
def len(s: str) -> i32:
152153
"""
153154
Return the length of the string `s`.
@@ -273,32 +274,41 @@ def round(b: bool) -> i32:
273274
#: complex() as a generic procedure.
274275
#: supported types for arguments:
275276
#: (i32, i32), (f64, f64), (i32, f64), (f64, i32)
277+
@interface
276278
@overload
277279
def complex(x: f64, y: f64) -> c64:
278280
pass
279281

282+
@interface
280283
@overload
281284
def complex(x: i32, y: i32) -> c64:
282285
pass
283286

287+
@interface
284288
@overload
285289
def complex(x: i32, y: f64) -> c64:
286290
pass
287291

292+
@interface
288293
@overload
289294
def complex(x: f64, y: i32) -> c64:
290295
pass
291296

297+
298+
@interface
292299
def divmod(x: i32, y: i32) -> tuple[i32, i32]:
293300
#: TODO: Implement once we have tuple support in the LLVM backend
294301
pass
295302

303+
296304
def lbound(x: i32[:], dim: i32) -> i32:
297305
pass
298306

307+
299308
def ubound(x: i32[:], dim: i32) -> i32:
300309
pass
301310

311+
302312
@ccall
303313
def _lfortran_caimag(x: c32) -> f32:
304314
pass

src/runtime/ltypes/ltypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def overload(f):
9292
return overloaded_f
9393

9494

95+
def interface(f):
96+
def inner_func():
97+
raise Exception("Unexpected to be called by CPython")
98+
return inner_func
99+
95100

96101
# C interoperation support
97102

0 commit comments

Comments
 (0)