diff --git a/internal/cmd/generator/vm.go.tmpl b/internal/cmd/generator/vm.go.tmpl index 2091ba1..242c3a4 100644 --- a/internal/cmd/generator/vm.go.tmpl +++ b/internal/cmd/generator/vm.go.tmpl @@ -484,7 +484,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b oldOffset := ptrOffset ptrOffset += code.Jmp.CurLen * uintptrSize oldBaseIndent := ctx.BaseIndent - ctx.BaseIndent += code.Indent - 1 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go index 56a9604..30c927b 100644 --- a/internal/encoder/compiler.go +++ b/internal/encoder/compiler.go @@ -269,8 +269,8 @@ func linkRecursiveCode(c *Opcode) { lastCode.Length = lastCode.Idx + 2*uintptrSize // extend length to alloc slot for elemIdx + length - totalLength := uintptr(code.TotalLength() + 2) - nextTotalLength := uintptr(c.TotalLength() + 2) + totalLength := uintptr(code.TotalLength() + 3) + nextTotalLength := uintptr(c.TotalLength() + 3) c.End.Next.Op = OpRecursiveEnd diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index 2091ba1..242c3a4 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -484,7 +484,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b oldOffset := ptrOffset ptrOffset += code.Jmp.CurLen * uintptrSize oldBaseIndent := ctx.BaseIndent - ctx.BaseIndent += code.Indent - 1 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { diff --git a/internal/encoder/vm_color/vm.go b/internal/encoder/vm_color/vm.go index 0ac3179..0447c74 100644 --- a/internal/encoder/vm_color/vm.go +++ b/internal/encoder/vm_color/vm.go @@ -484,7 +484,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b oldOffset := ptrOffset ptrOffset += code.Jmp.CurLen * uintptrSize oldBaseIndent := ctx.BaseIndent - ctx.BaseIndent += code.Indent - 1 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { diff --git a/internal/encoder/vm_color_indent/vm.go b/internal/encoder/vm_color_indent/vm.go index cd619ca..b142463 100644 --- a/internal/encoder/vm_color_indent/vm.go +++ b/internal/encoder/vm_color_indent/vm.go @@ -484,7 +484,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b oldOffset := ptrOffset ptrOffset += code.Jmp.CurLen * uintptrSize oldBaseIndent := ctx.BaseIndent - ctx.BaseIndent += code.Indent - 1 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index a4eb235..cbcf3d0 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -484,7 +484,8 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b oldOffset := ptrOffset ptrOffset += code.Jmp.CurLen * uintptrSize oldBaseIndent := ctx.BaseIndent - ctx.BaseIndent += code.Indent - 1 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen {