Added peek and poke methods to read/write to block
This commit is contained in:
parent
601636a0ad
commit
a098a30da0
25
creature.go
25
creature.go
@ -1,9 +1,9 @@
|
||||
package creature
|
||||
|
||||
type Machine struct {
|
||||
stack []int
|
||||
Program []int
|
||||
Block []int
|
||||
stack []int
|
||||
block []int
|
||||
counter int
|
||||
pointer int
|
||||
}
|
||||
@ -26,6 +26,7 @@ func (machine *Machine) Execute (offset int) {
|
||||
// POP
|
||||
// pop the top word off of the stack, and discard it
|
||||
machine.Pop()
|
||||
|
||||
case 0x2:
|
||||
case 0x3:
|
||||
case 0x4:
|
||||
@ -81,3 +82,23 @@ func (machine *Machine) Pop () (word int) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Peek returns the word at address in the block
|
||||
func (machine *Machine) Peek (address int) (word int) {
|
||||
if address < len(machine.block) {
|
||||
word = machine.block[address]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Poke sets the value at address in the block to word
|
||||
func (machine *Machine) Poke (address int, word int) {
|
||||
if address >= len(machine.block) {
|
||||
reallocatedBlock := make([]int, address * 3 / 2)
|
||||
copy(reallocatedBlock, machine.block)
|
||||
machine.block = reallocatedBlock
|
||||
}
|
||||
}
|
||||
|
||||
// Milk milks the stack machine
|
||||
func (machine *Machine) Milk () {}
|
||||
|
Loading…
Reference in New Issue
Block a user