vm: fix XTUCK implementation, add tests

The code that we have actually implements XTUCK and not TUCK. And it's a bit
broken, so fix it and add some tests. The most interesting one (that required
to touch stack code) is the one when we have 1 element on the stack and are
trying to tell XTUCK to push 2 elements deep.
This commit is contained in:
Roman Khimov 2019-09-05 15:43:59 +03:00
parent 5f0f9e1638
commit 85831e3e92
3 changed files with 55 additions and 5 deletions

View file

@ -141,6 +141,8 @@ func (s *Stack) InsertBefore(e, mark *Element) *Element {
}
// InsertAt will insert the given item (n) deep on the stack.
// Be very careful using it and _always_ check both e and n before invocation
// as it will silently do wrong things otherwise.
func (s *Stack) InsertAt(e *Element, n int) *Element {
before := s.Peek(n)
if before == nil {