You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The operational stack can be indexed into to fetch individual elements through its implementations of Index<usize> and Index<OpStackElement> (and the corresponding IndexMut<…>). It can be useful to get a slice from the op stack.
Implement the combinations {Index, IndexMut} $\times$ {Range, RangeInclusive} $\times$ {usize, OpStackElement} for OpStack.
The text was updated successfully, but these errors were encountered:
#338 has uncovered that there are some rather fundamental issues when trying to add this feature. Summarizing for posteriority:
Currently, OpStack uses a Vec under the hood. The top of Triton VM's op stack, or op_stack[0], is the last element in the internal vector. To provide semantically correct access to some op_stack[i..j] range, the underlying vector has to be indexed “in reverse”, which does not produce a contiguous slice.
It is possible to allocate a new vector containing the correct stack elements and to then leak that new vector. I feel uncomfortable creating memory leaks like this.
Using a VecDeque, which seemed like the obvious next choice, also does not work, because it is implemented as a ring buffer. This means that a range of elements from a VecDeque are not necessarily contiguous in memory, requiring re-organization within the implementation of the Index trait again, leading back to the same problems the current implementation is facing.
The only real solution I can see is to implement a “reverse” vector, such that op_stack[0] is the always the first element in that data structure.
The operational stack can be indexed into to fetch individual elements through its implementations of
Index<usize>
andIndex<OpStackElement>
(and the correspondingIndexMut<…>
). It can be useful to get a slice from the op stack.Implement the combinations {$\times$ {$\times$ {
Index
,IndexMut
}Range
,RangeInclusive
}usize
,OpStackElement
} forOpStack
.The text was updated successfully, but these errors were encountered: