diff options
author | Julien Dessaux | 2021-09-23 14:59:14 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-09-23 14:59:14 +0200 |
commit | f86b5724e530ec86eed04ebeb257293244f4be69 (patch) | |
tree | 0ceaddd9f08229899eb94f7134a048c5b36d9ba4 /pkg/interpreter/interpreter.go | |
parent | Each pointer needs its own stack, merging the two packages to avoid a circula... (diff) | |
download | gofunge98-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/interpreter/interpreter.go | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/pkg/interpreter/interpreter.go b/pkg/interpreter/interpreter.go index b64e90a..76917b7 100644 --- a/pkg/interpreter/interpreter.go +++ b/pkg/interpreter/interpreter.go @@ -1,8 +1,6 @@ package interpreter import ( - "log" - "git.adyxax.org/adyxax/gofunge/pkg/field" "git.adyxax.org/adyxax/gofunge/pkg/pointer" ) @@ -16,31 +14,29 @@ func NewInterpreter(f *field.Field, p *pointer.Pointer) *Interpreter { return &Interpreter{f: f, p: p} } -func (i *Interpreter) Run() { +func (i *Interpreter) Run() int { for i.p != nil { - i.Step() + if v := i.Step(); v != nil { + return *v + } } + return 0 } -func (i *Interpreter) Step() { +func (i *Interpreter) Step() *int { var prev *pointer.Pointer = nil for p := i.p; p != nil; p = p.Next { - c := p.Get(*i.f) - switch c { - case '@': + done, v := p.Exec(i.f) + if v != nil { + return v + } + if done { if prev == nil { i.p = p.Next } else { prev.Next = p.Next } - break - case '#': - p.Step(*i.f) - default: - if !p.Redirect(c) { - log.Fatalf("Non implemented instruction code %d : %c", c, c) - } } - p.Step(*i.f) } + return nil } |