Overwatch-Script-To-Workshop
Overwatch-Script-To-Workshop copied to clipboard
A macro call involving only constant lambdas should inline at compile time
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.
Something like this can be optimized as well:
() => {
SmallMessage(AllPlayers(), 'okay!');
}();