Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Last part extracted from #24369
I'm not 100% convinced we should do it this way... but this works today and should be backwards compatible in case we want any other changes.
Changes
Adds support for
arrayMap
,arrayExists
,arrayFilter
:This is where it gets a bit tricky. Those are added via an "inlined STL". Effectively the bytecode compiler does a round of static analysis and figures out if any of those STL functions will be called. If so, it appends source code for the function before your script.
All three functions are written as Hog functions behind the scenes, for example:
This was easier (and safer) to get working than implementing a back-and-forth layer between the VM and "native code". We can today call native code from the VM (all those STL functions), but to the do an UNO reverse and call a VM function from native code... requires a bigger refactor.
Currently those STL functions are inlined into the start of Hog bytecode. I'm not sure if we want to keep it that way, or ship the function bytecodes with each HogVM itself.
There are some positive things about having a STL written within Hog: 1) it's easier to extend, and 2) it requires less changes in all the different implementations of Hog (Python vs TS vs future Rust?)
Alternatives
The current option isn't very clean:
arrayMap
longerarrayReduce
can't depend onarrayMap
)The alternatives to this are to either:
Those options sound cleaner/better in some way.
Out of scope
Still out of scope for this PR is getting the elements chain matching working. This requires some extra fields and is a WIP here.
How did you test this code?
Hog snapshot test for inline STL functions.