aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer/exec.go
blob: 9d55136e58f7af59b26e01752544a6f5fcd9e34a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package pointer

import (
	"log"

	"git.adyxax.org/adyxax/gofunge/pkg/field"
)

func (p *Pointer) Exec(f *field.Field) (done bool, returnValue *int) {
	c := p.Get(*f)
	for jumpingMode := false; jumpingMode || c == ' ' || c == ';'; c = p.StepAndGet(*f) {
		if jumpingMode {
			if c == ';' {
				jumpingMode = false
			}
			continue
		}
	}
	switch c {
	case '@':
		return true, nil
	case '#':
		p.Step(*f)
	case 'j':
		n := p.Ss.Pop()
		for j := 0; j < n; j++ {
			p.Step(*f)
		}
	case 'q':
		v := p.Ss.Pop()
		return true, &v
	default:
		if !p.Redirect(c) {
			log.Fatalf("Non implemented instruction code %d : %c", c, c)
		}
	}
	p.Step(*f)
	return
}