wiremod / wire

Garry's Mod add-on that allows users to wire up components in order to make more elaborate automatic and user-controlled contraptions.
http://www.wiremod.com
Apache License 2.0
549 stars 333 forks source link

Add `declare function` E2 construct #2969

Closed stepa2 closed 8 months ago

stepa2 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

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