Skip to content

Add interface decorator #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
current_procedure_abi_type = ASR::abiType::BindC;
} else if (name == "overload") {
overload = true;
} else if (name == "interface") {
// TODO: Implement @interface
} else {
throw SemanticError("Decorator: " + name + " is not supported",
x.base.base.loc);
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/lpython_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def bool(c: c64) -> bool:
pass


@interface
def len(s: str) -> i32:
"""
Return the length of the string `s`.
Expand Down Expand Up @@ -273,32 +274,41 @@ def round(b: bool) -> i32:
#: complex() as a generic procedure.
#: supported types for arguments:
#: (i32, i32), (f64, f64), (i32, f64), (f64, i32)
@interface
@overload
def complex(x: f64, y: f64) -> c64:
pass

@interface
@overload
def complex(x: i32, y: i32) -> c64:
pass

@interface
@overload
def complex(x: i32, y: f64) -> c64:
pass

@interface
@overload
def complex(x: f64, y: i32) -> c64:
pass


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


def lbound(x: i32[:], dim: i32) -> i32:
pass


def ubound(x: i32[:], dim: i32) -> i32:
pass


@ccall
def _lfortran_caimag(x: c32) -> f32:
pass
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/ltypes/ltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def overload(f):
return overloaded_f


def interface(f):
def inner_func():
raise Exception("Unexpected to be called by CPython")
return inner_func


# C interoperation support

Expand Down