Overwatch-Script-To-Workshop icon indicating copy to clipboard operation
Overwatch-Script-To-Workshop copied to clipboard

A macro call involving only constant lambdas should inline at compile time

Open Protowalker opened this issue 3 years ago • 1 comments

Right now, if you do something like

(define => define => define => Vector) Vec: (define x) => (define y) => (define z) => Vector(x,y,z);
BigMessage(AllPlayers(), Vec(0)(0)(0));

it will turn each of the lambdas into a function group and put it into a subroutine. However, this can be inlined as such:

((define x) => (define y) => (define z) => Vector(x,y,z))(0)(0)(0)` becomes `((define y) => (define z) => Vector(0,y,z))(0)(0)
((define y) => (define z) => Vector(0,y,z))(0)(0)` becomes `((define z) => Vector(0,0,z))(0)
((define z) => Vector(0,0,z))(0)` becomes `Vector(0,0,0)

Another example would be:

(define => define) IsEven: (define x) => x%2==0;
(define => define => define) Filter: (define cond) => (define array) => FilteredArray(array, cond(ArrayElement()));
(define => define => define) Sort: (define cond) => (define array) => SortedArray(array, cond(ArrayElement()));
define val = Sort ((define x) => x % 3) (Filter (IsEven) ([12,9,3,1,4,5]));

This can be inlined at compile time as well. Filter (IsEven) ([12,9,3,1,4,5]) becomes FilteredArray([12, 9, 3, 1, 4, 5], IsEven(ArrayElement()))) Sort ((define x => x % 3 == 0)) (FilteredArray([12,9,3,1,4,5], IsEven(ArrayElement()))) becomes SortedArray(FilteredArray(..), ArrayElement() % 3 == 0)

Now all of the runtime checking is gone, saving elements, subroutines, and perf cost without hurting ergonomics.

Protowalker avatar Oct 26 '20 21:10 Protowalker

Something like this can be optimized as well:

() => {
        SmallMessage(AllPlayers(), 'okay!');
}();

ItsDeltin avatar Dec 17 '20 07:12 ItsDeltin