Skip to content

Add @interface decorator #239

Closed
Closed

Description

@certik

Currently we define a function interface using:

def complex(x: f64, y: f64) -> c64:
    pass

But that is the same syntax as for an empty function. I think we should add an @interface decorator into ltypes, which would probably raise an exception if the function was ever being called (by CPython). In LPython, that would declare an interface, meaning the function with that name must be provided in global scope at some point before compiling to LLVM.

Activity

  1. Smit-create commented on Apr 2, 2022

    @Smit-create
    Collaborator

    Do you mean something like this?

    def interface():
        raise Exception('Unexpected to be called')
    
    @interface
    def complex(x: f64, y: f64) -> c64:
        pass

    Internally, we will handle lpython when it sees an interface operator, and CPython is not expected to call this function at all.

  2. certik commented on Apr 2, 2022

    @certik
    ContributorAuthor

    Yes, exactly. (The CPython implementation I think has to be a nested function though.)

  3. Smit-create commented on Apr 3, 2022

    @Smit-create
    Collaborator

    Okay, I will try to get it implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions