diff options
| author | Marc Vertes <mvertes@free.fr> | 2026-01-23 11:16:12 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2026-01-23 11:16:12 +0100 |
| commit | 2837dabf7818666a9366d659d2da3b9055140740 (patch) | |
| tree | 3d4fce18fe750044b519e571845d4b476f958656 /comp | |
| parent | abd8581bac36018be2f090e05fdd00ea74f6ca4b (diff) | |
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.
Diffstat (limited to 'comp')
| -rw-r--r-- | comp/compiler.go | 9 |
1 files changed, 8 insertions, 1 deletions
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. |
