dropArgs searches the stack for all the args by their IDs, accumulates their associated ref.Vals and drops any stack items above any of the arg IDs. If any of the IDs are not found the stack, false is returned. Args are assumed to be found in the stack in reverse order, i.e. the last arg is expected
(args []InterpretableV2)
| 381 | // WARNING: It is possible for multiple expressions with the same ID to exist (due to how macros are implemented) so it's |
| 382 | // possible that a dropped ID will remain on the stack. They should be removed when IDs on the stack are popped. |
| 383 | func (s *refValStack) dropArgs(args []InterpretableV2) ([]ref.Val, bool) { |
| 384 | result := make([]ref.Val, len(args)) |
| 385 | argloop: |
| 386 | for nIdx := len(args) - 1; nIdx >= 0; nIdx-- { |
| 387 | for idx := len(*s) - 1; idx >= 0; idx-- { |
| 388 | if (*s)[idx].ID == args[nIdx].ID() { |
| 389 | el := (*s)[idx] |
| 390 | *s = (*s)[:idx] |
| 391 | result[nIdx] = el.Val |
| 392 | continue argloop |
| 393 | } |
| 394 | } |
| 395 | return nil, false |
| 396 | } |
| 397 | return result, true |
| 398 | } |