Fixed issue with pushing to stack

This commit is contained in:
Sasha Koshka
2022-08-28 18:26:44 -04:00
parent 850de8a2bf
commit 21aaaede8e
2 changed files with 24 additions and 1 deletions

View File

@@ -207,7 +207,7 @@ func (machine *Machine) instruction() (instruction int) {
// should be called then the stack pointer is really small compared to the
// actual stack size, or the stack pointer is bigger than the stack.
func (machine *Machine) reallocateStack() {
reallocatedStack := make([]int, machine.pointer*3/2)
reallocatedStack := make([]int, machine.pointer*2)
copy(reallocatedStack, machine.stack)
machine.stack = reallocatedStack
}
@@ -219,6 +219,7 @@ func (machine *Machine) Push(word int) {
if len(machine.stack) <= machine.pointer {
machine.reallocateStack()
}
machine.stack[machine.pointer] = word
}
// Pop pops the last word off of the stack, and returns it, decreasing the stack