Skip to content
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

Forward references #10

Open
bartvm opened this issue Jan 17, 2018 · 0 comments
Open

Forward references #10

bartvm opened this issue Jan 17, 2018 · 0 comments

Comments

@bartvm
Copy link
Member

bartvm commented Jan 17, 2018

Python allows for forward references.

def f():
    return g()  # g has not been defined yet during parsing

def g():
    return 1

This is not a problem as long as the parser is called after the definition of g. To support forward references in general (e.g. in an @myia decorator) we have to postpone name resolution until after the entire scope has been parsed.

For local forward references we have to actually separate the name resolution from the parsing i.e. h should remain unresolved while parsing g under the assumption that it is a forward declaration (and then be resolved to h when we come across it). Note that this is related to #11 i.e. if we perform name resolution statically we need to ensure that there is only one name declaration corresponding to the forward reference (otherwise we need to do it dynamically by introducing environments).

def f():
    def g():
        return h()
    def h():
        return g()
@bartvm bartvm mentioned this issue Jan 21, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant