aboutsummaryrefslogtreecommitdiff
path: root/pkg/interpreter/interpreter.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-09-23 11:45:49 +0200
committerJulien Dessaux2021-09-23 11:45:49 +0200
commit759ee2aa10323d1960405c93f7cd4cf6d383ae7a (patch)
tree87648b4811b0264f1b54c454ed2569abe1abee94 /pkg/interpreter/interpreter.go
parentBegan coding the interpreter (only manages the minimal example for now!) (diff)
downloadgofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.tar.gz
gofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.tar.bz2
gofunge98-759ee2aa10323d1960405c93f7cd4cf6d383ae7a.zip
Each pointer needs its own stack, merging the two packages to avoid a circular dependency
Diffstat (limited to '')
-rw-r--r--pkg/interpreter/interpreter.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/pkg/interpreter/interpreter.go b/pkg/interpreter/interpreter.go
index ce2499d..b64e90a 100644
--- a/pkg/interpreter/interpreter.go
+++ b/pkg/interpreter/interpreter.go
@@ -25,7 +25,8 @@ func (i *Interpreter) Run() {
func (i *Interpreter) Step() {
var prev *pointer.Pointer = nil
for p := i.p; p != nil; p = p.Next {
- switch p.Get(*i.f) {
+ c := p.Get(*i.f)
+ switch c {
case '@':
if prev == nil {
i.p = p.Next
@@ -33,8 +34,13 @@ func (i *Interpreter) Step() {
prev.Next = p.Next
}
break
+ case '#':
+ p.Step(*i.f)
default:
- log.Fatalf("Non implemented instruction code %d : %c", p.Get(*i.f), p.Get(*i.f))
+ if !p.Redirect(c) {
+ log.Fatalf("Non implemented instruction code %d : %c", c, c)
+ }
}
+ p.Step(*i.f)
}
}