aboutsummaryrefslogtreecommitdiff
path: root/pkg/pointer/exec.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 14:59:14 +0200
committerJulien Dessaux2021-09-23 14:59:14 +0200
commitf86b5724e530ec86eed04ebeb257293244f4be69 (patch)
tree0ceaddd9f08229899eb94f7134a048c5b36d9ba4 /pkg/pointer/exec.go
parentEach pointer needs its own stack, merging the two packages to avoid a circula... (diff)
downloadgofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.tar.gz
gofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.tar.bz2
gofunge98-f86b5724e530ec86eed04ebeb257293244f4be69.zip
Moved the character execution's to the pointer in order to handle the k command
Diffstat (limited to '')
-rw-r--r--pkg/pointer/exec.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/pointer/exec.go b/pkg/pointer/exec.go
new file mode 100644
index 0000000..9d55136
--- /dev/null
+++ b/pkg/pointer/exec.go
@@ -0,0 +1,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
+}