From f86b5724e530ec86eed04ebeb257293244f4be69 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 23 Sep 2021 14:59:14 +0200 Subject: Moved the character execution's to the pointer in order to handle the k command --- pkg/interpreter/interpreter.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'pkg/interpreter/interpreter.go') 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 } -- cgit v1.2.3