aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer
diff options
context:
space:
mode:
authorJulien Dessaux2021-10-06 18:35:21 +0200
committerJulien Dessaux2021-10-06 18:35:21 +0200
commitd141d68c1b613e8b327cfcbef07154c9118b622a (patch)
tree9c092e23c0d3a33a3b8918abc419932e4db58d9d /pkg/pointer
parentFixed edge case in the k command (diff)
downloadgofunge98-d141d68c1b613e8b327cfcbef07154c9118b622a.tar.gz
gofunge98-d141d68c1b613e8b327cfcbef07154c9118b622a.tar.bz2
gofunge98-d141d68c1b613e8b327cfcbef07154c9118b622a.zip
simplified some code
Diffstat (limited to '')
-rw-r--r--pkg/pointer/exec.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/pkg/pointer/exec.go b/pkg/pointer/exec.go
index aae7a81..e2c55e3 100644
--- a/pkg/pointer/exec.go
+++ b/pkg/pointer/exec.go
@@ -84,13 +84,11 @@ func (p *Pointer) eval(c int, f *field.Field) (done bool, returnValue *int) {
}
}
case '!':
- v := p.ss.head.Pop()
- if v == 0 {
- v = 1
+ if p.ss.head.Pop() == 0 {
+ p.ss.head.Push(1)
} else {
- v = 0
+ p.ss.head.Push(0)
}
- p.ss.head.Push(v)
case '`':
b, a := p.ss.head.Pop(), p.ss.head.Pop()
if a > b {
@@ -100,12 +98,12 @@ func (p *Pointer) eval(c int, f *field.Field) (done bool, returnValue *int) {
}
p.ss.head.Push(a)
case '_':
- v := p.ss.head.Pop()
- if v == 0 {
- p.Redirect('>')
+ if p.ss.head.Pop() == 0 {
+ p.dx = 1
} else {
- p.Redirect('<')
+ p.dx = -1
}
+ p.dy = 0
case '|':
v := p.ss.head.Pop()
if v == 0 {
@@ -133,16 +131,16 @@ func (p *Pointer) eval(c int, f *field.Field) (done bool, returnValue *int) {
b, a := p.ss.head.Pop(), p.ss.head.Pop()
if b == 0 {
p.ss.head.Push(0)
- return
+ } else {
+ p.ss.head.Push(a / b)
}
- p.ss.head.Push(a / b)
case '%':
b, a := p.ss.head.Pop(), p.ss.head.Pop()
if b == 0 {
p.ss.head.Push(0)
- return
+ } else {
+ p.ss.head.Push(a % b)
}
- p.ss.head.Push(a % b)
case '"':
p.stringMode = true
case '\'':