From e45d153b8045599a44355388e0cd7d487fd2ccdb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 29 Aug 2022 00:43:13 -0400 Subject: [PATCH] Test and poke operation fixed --- creature.go | 5 ++++- creature_test.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/creature.go b/creature.go index af82112..18bd92e 100644 --- a/creature.go +++ b/creature.go @@ -97,7 +97,9 @@ func (machine *Machine) Execute(offset int) (err error) { case POKE: // store a word at an address - machine.Poke(machine.Pop(), machine.Pop()) + address := machine.Pop() + word := machine.Pop() + machine.Poke(address, word) case ADD: // adds the last two words on the stack @@ -258,6 +260,7 @@ func (machine *Machine) Poke(address int, word int) { copy(reallocatedBlock, machine.block) machine.block = reallocatedBlock } + machine.block[address] = word } // Register registers a function at the specified ID. If there is already a diff --git a/creature_test.go b/creature_test.go index 5c3acb9..7ba7243 100644 --- a/creature_test.go +++ b/creature_test.go @@ -164,7 +164,7 @@ func TestPeekPoke(test *testing.T) { PEEK, }, []int { 632, - 29, + 13, }, test) secondResult := machine.Pop()