From 79ccab759f08aafc96918d5ef3c8bdf56fcde6af Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 12 Jun 2021 22:01:45 +0900 Subject: [PATCH 1/3] Fix indent num contains recursive type --- internal/cmd/generator/vm.go.tmpl | 2 +- internal/encoder/vm/vm.go | 2 +- internal/encoder/vm_color/vm.go | 2 +- internal/encoder/vm_color_indent/vm.go | 2 +- internal/encoder/vm_indent/vm.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/cmd/generator/vm.go.tmpl b/internal/cmd/generator/vm.go.tmpl index 2091ba1..8bb1681 100644 --- a/internal/cmd/generator/vm.go.tmpl +++ b/internal/cmd/generator/vm.go.tmpl @@ -484,7 +484,7 @@ 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 + ctx.BaseIndent += code.Indent newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index 2091ba1..8bb1681 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -484,7 +484,7 @@ 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 + ctx.BaseIndent += code.Indent 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..8d7df85 100644 --- a/internal/encoder/vm_color/vm.go +++ b/internal/encoder/vm_color/vm.go @@ -484,7 +484,7 @@ 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 + ctx.BaseIndent += code.Indent 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..834aadf 100644 --- a/internal/encoder/vm_color_indent/vm.go +++ b/internal/encoder/vm_color_indent/vm.go @@ -484,7 +484,7 @@ 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 + ctx.BaseIndent += code.Indent 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..f9d7569 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -484,7 +484,7 @@ 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 + ctx.BaseIndent += code.Indent newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen { From 56e5d7a457810aa68fb264e87aa3f24f13a1ef84 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 12 Jun 2021 22:02:03 +0900 Subject: [PATCH 2/3] Fix index number about length for recursive type --- internal/encoder/compiler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From b972a9bab3d0d7bac6a4d778f17f77c38405c010 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 12 Jun 2021 22:38:52 +0900 Subject: [PATCH 3/3] Fix indent num --- internal/cmd/generator/vm.go.tmpl | 3 ++- internal/encoder/vm/vm.go | 3 ++- internal/encoder/vm_color/vm.go | 3 ++- internal/encoder/vm_color_indent/vm.go | 3 ++- internal/encoder/vm_indent/vm.go | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/cmd/generator/vm.go.tmpl b/internal/cmd/generator/vm.go.tmpl index 8bb1681..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 + 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/vm.go b/internal/encoder/vm/vm.go index 8bb1681..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 + 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 8d7df85..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 + 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 834aadf..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 + 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 f9d7569..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 + indentDiffFromTop := c.Indent - 1 + ctx.BaseIndent += code.Indent - indentDiffFromTop newLen := offsetNum + code.Jmp.CurLen + code.Jmp.NextLen if curlen < newLen {