Ran gofmt
This commit is contained in:
parent
eb3f581b00
commit
07a783b6ba
30
creature.go
30
creature.go
@ -102,7 +102,9 @@ func (machine *Machine) Execute (offset int) {
|
|||||||
// EQ
|
// EQ
|
||||||
// checks if the last two words on the stack are equal
|
// checks if the last two words on the stack are equal
|
||||||
equal := 0
|
equal := 0
|
||||||
if machine.Pop() == machine.Pop() { equal = 1 }
|
if machine.Pop() == machine.Pop() {
|
||||||
|
equal = 1
|
||||||
|
}
|
||||||
machine.Push(equal)
|
machine.Push(equal)
|
||||||
|
|
||||||
case 0x9:
|
case 0x9:
|
||||||
@ -110,7 +112,9 @@ func (machine *Machine) Execute (offset int) {
|
|||||||
// checks if the last word on the stack is greater than
|
// checks if the last word on the stack is greater than
|
||||||
// the second to last word on the stack
|
// the second to last word on the stack
|
||||||
greater := 0
|
greater := 0
|
||||||
if machine.Pop() > machine.Pop() { greater = 1 }
|
if machine.Pop() > machine.Pop() {
|
||||||
|
greater = 1
|
||||||
|
}
|
||||||
machine.Push(greater)
|
machine.Push(greater)
|
||||||
|
|
||||||
case 0xa:
|
case 0xa:
|
||||||
@ -118,7 +122,9 @@ func (machine *Machine) Execute (offset int) {
|
|||||||
// checks if the last word on the stack is less than the
|
// checks if the last word on the stack is less than the
|
||||||
// second to last word on the stack
|
// second to last word on the stack
|
||||||
less := 0
|
less := 0
|
||||||
if machine.Pop() > machine.Pop() { less = 1 }
|
if machine.Pop() > machine.Pop() {
|
||||||
|
less = 1
|
||||||
|
}
|
||||||
machine.Push(less)
|
machine.Push(less)
|
||||||
|
|
||||||
case 0xb:
|
case 0xb:
|
||||||
@ -126,7 +132,9 @@ func (machine *Machine) Execute (offset int) {
|
|||||||
// checks if the last two words on the stack are not
|
// checks if the last two words on the stack are not
|
||||||
// equal
|
// equal
|
||||||
notEqual := 0
|
notEqual := 0
|
||||||
if machine.Pop() != machine.Pop() { notEqual = 1 }
|
if machine.Pop() != machine.Pop() {
|
||||||
|
notEqual = 1
|
||||||
|
}
|
||||||
machine.Push(notEqual)
|
machine.Push(notEqual)
|
||||||
|
|
||||||
case 0xc:
|
case 0xc:
|
||||||
@ -156,7 +164,9 @@ func (machine *Machine) Execute (offset int) {
|
|||||||
// id specified by the last word on the stack. this may
|
// id specified by the last word on the stack. this may
|
||||||
// push and pop various things from the stack
|
// push and pop various things from the stack
|
||||||
id := machine.Pop()
|
id := machine.Pop()
|
||||||
if machine.functions == nil { break }
|
if machine.functions == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
function, exists := machine.functions[id]
|
function, exists := machine.functions[id]
|
||||||
if exists {
|
if exists {
|
||||||
function(machine)
|
function(machine)
|
||||||
@ -203,7 +213,7 @@ func (machine *Machine) Pop () (word int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peek returns the word at address in the block
|
// Peek returns the word at address in the block.
|
||||||
func (machine *Machine) Peek(address int) (word int) {
|
func (machine *Machine) Peek(address int) (word int) {
|
||||||
if address < len(machine.block) {
|
if address < len(machine.block) {
|
||||||
word = machine.block[address]
|
word = machine.block[address]
|
||||||
@ -211,7 +221,7 @@ func (machine *Machine) Peek (address int) (word int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poke sets the value at address in the block to word
|
// Poke sets the value at address in the block to word.
|
||||||
func (machine *Machine) Poke(address int, word int) {
|
func (machine *Machine) Poke(address int, word int) {
|
||||||
if address >= len(machine.block) {
|
if address >= len(machine.block) {
|
||||||
reallocatedBlock := make([]int, address*3/2)
|
reallocatedBlock := make([]int, address*3/2)
|
||||||
@ -240,7 +250,9 @@ func (machine *Machine) Register (id int, function MachineFunction) (err error)
|
|||||||
|
|
||||||
// Unregister removes a function that is registered at the specified ID.
|
// Unregister removes a function that is registered at the specified ID.
|
||||||
func (machine *Machine) Unregister(id int) {
|
func (machine *Machine) Unregister(id int) {
|
||||||
if machine.functions == nil { return }
|
if machine.functions == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
delete(machine.functions, id)
|
delete(machine.functions, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,5 +262,5 @@ func (machine *Machine) LoadMemory (block []int) {
|
|||||||
copy(machine.block, block)
|
copy(machine.block, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Milk milks the stack machine
|
// Milk milks the stack machine.
|
||||||
func (machine *Machine) Milk() {}
|
func (machine *Machine) Milk() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user