From 2837dabf7818666a9366d659d2da3b9055140740 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 23 Jan 2026 11:16:12 +0100 Subject: feat: make Next iterator instruction faster and more efficient Branching control is delegated directly to the Next instruction, which now takes the location of loop exit as first argument. It avoids the use of JumpFalse, plus the stack storage for the condition. --- comp/compiler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'comp/compiler.go') diff --git a/comp/compiler.go b/comp/compiler.go index 05a4b3f..ef379ea 100644 --- a/comp/compiler.go +++ b/comp/compiler.go @@ -408,8 +408,15 @@ func (c *Compiler) Generate(tokens parser.Tokens) (err error) { } case lang.Next: + var i int + if s, ok := c.Symbols[t.Str]; !ok { + t.Arg = []any{len(c.Code)} // current code location + fixList = append(fixList, t) + } else { + i = int(s.Value.Int()) - len(c.Code) + } k := stack[len(stack)-2] - c.emit(t, vm.Next, k.Index) + c.emit(t, vm.Next, i, k.Index) case lang.Range: // FIXME: handle all iterator types. -- cgit v1.2.3