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

Add declare function E2 construct #2969

Closed
wants to merge 6 commits into from

Conversation

stepa2
Copy link
Contributor

@stepa2 stepa2 commented Jan 5, 2024

Allows using a function before the line of code where it is defined.
Fixes #2910.

@strict

declare function test()

function use_test() {
    test() # Using declared-but-not-yet-defined function
}


declare function test() # Double-declaration is allowed

function test() { 
    print("Do something")
}

@Vurv78
Copy link
Contributor

Vurv78 commented Jan 5, 2024

It's unnecessary.

In the future there will be an analyzer and multiple passes so you could just call functions before they're declared regardless on @strict like rust or other modern aot languages

@stepa2
Copy link
Contributor Author

stepa2 commented Jan 5, 2024

This is both an temporal implementation for @strict until multipass analyzer is implemented and a more explicit way to do forward declaration in non-@strict chips.

After all, you can't forward declare functions on @strict otherwise.

@Vurv78
Copy link
Contributor

Vurv78 commented Jan 6, 2024

This is both an temporal implementation for @strict until multipass analyzer is implemented and a more explicit way to do forward declaration in non-@strict chips.

After all, you can't forward declare functions on @strict otherwise.

Temporary patches shouldn't lock us into syntax like this. Also not too happy with the compiler/parser implementation

@stepa2
Copy link
Contributor Author

stepa2 commented Jan 6, 2024

How do you suggest to add this feature without modifying syntax?

Only way I can see is to add special function, say undefined(), and treat all function bodies only containing undefined() call as declaration without definition.
However this will be a hack, because function anything() { undefined() } will be treated differently than function with any other body.

And what is wrong with implementation?
I just extracted function-related code to separate functions. Function definition check done in a simple way, so multiple-pass system is not required. Other than that, everything is done in way other E2 features are implemented.

@Vurv78
Copy link
Contributor

Vurv78 commented Jan 6, 2024

How do you suggest to add this feature without modifying syntax?

By waiting for the analyzer step to be implemented?

And what is wrong with implementation?

I can do a review later. But it's pointless if I'm against this idea entirely, which is why I didn't make one

@stepa2
Copy link
Contributor Author

stepa2 commented Jan 6, 2024

You've broke forward declaration without providing alternative for almost one month.
I implemented a working solution to this problem.

Why shouldn't this be available to other E2 users?

@Vurv78
Copy link
Contributor

Vurv78 commented Jan 6, 2024

You've broke forward declaration without providing alternative for almost one month.

During the holidays. Really can't be patient?

And I already gave a solution in your issue, just remove @strict. I never guaranteed backwards compatibility for chips with @strict. So no, nothing is "broken".

@Vurv78
Copy link
Contributor

Vurv78 commented Jan 6, 2024

Why shouldn't this be available to other E2 users?

I just gave my reason. You can scroll up to read it again.

@stepa2 stepa2 closed this Jan 7, 2024
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

Successfully merging this pull request may close these issues.

Expression 2: function predefinition is broken
2 participants