From d7372a47cd1ad725fd794f3092e54ded14264249 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 14 Oct 2021 15:00:28 +0900 Subject: [PATCH] Fix conversion from pointer to uint64 --- internal/cmd/generator/vm.go.tmpl | 130 +++++++++++------------ internal/encoder/int.go | 26 ++++- internal/encoder/vm/util.go | 14 ++- internal/encoder/vm/vm.go | 128 +++++++++++----------- internal/encoder/vm_color/util.go | 22 +++- internal/encoder/vm_color/vm.go | 128 +++++++++++----------- internal/encoder/vm_color_indent/util.go | 23 +++- internal/encoder/vm_color_indent/vm.go | 128 +++++++++++----------- internal/encoder/vm_indent/util.go | 14 ++- internal/encoder/vm_indent/vm.go | 128 +++++++++++----------- 10 files changed, 406 insertions(+), 335 deletions(-) diff --git a/internal/cmd/generator/vm.go.tmpl b/internal/cmd/generator/vm.go.tmpl index eccb961..7701501 100644 --- a/internal/cmd/generator/vm.go.tmpl +++ b/internal/cmd/generator/vm.go.tmpl @@ -40,7 +40,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpInt: - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpUintPtr: @@ -54,18 +54,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpUint: - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpIntString: b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpUintString: b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -195,7 +195,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b iface := (*nonEmptyInterface)(up) ifacePtr = iface.ptr if iface.itab != nil { - typ = iface.itab.typ + typ = iface.itab.typ } } else { iface := (*emptyInterface)(up) @@ -662,7 +662,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyInt: @@ -692,13 +692,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -731,7 +731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -762,14 +762,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -806,7 +806,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -840,7 +840,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -877,7 +877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -913,7 +913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -946,7 +946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyUint: @@ -976,13 +976,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -1015,7 +1015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1046,14 +1046,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1090,7 +1090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -1124,7 +1124,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -1161,7 +1161,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -1197,7 +1197,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3473,16 +3473,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3490,18 +3490,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3513,7 +3513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3522,7 +3522,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3534,7 +3534,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3545,7 +3545,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3553,16 +3553,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3570,18 +3570,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3593,7 +3593,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3602,7 +3602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3614,7 +3614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3625,7 +3625,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -4357,16 +4357,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4376,18 +4376,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4401,7 +4401,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4410,7 +4410,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4445,16 +4445,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4464,18 +4464,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4489,7 +4489,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4498,7 +4498,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { diff --git a/internal/encoder/int.go b/internal/encoder/int.go index 3a3482d..85f0796 100644 --- a/internal/encoder/int.go +++ b/internal/encoder/int.go @@ -53,7 +53,18 @@ func numMask(numBitSize uint8) uint64 { return 1<>(code.NumBitSize-1))&1 == 1 @@ -96,7 +107,18 @@ func AppendInt(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte { return append(out, b[i:]...) } -func AppendUint(_ *RuntimeContext, out []byte, u64 uint64, code *Opcode) []byte { +func AppendUint(_ *RuntimeContext, out []byte, p uintptr, code *Opcode) []byte { + var u64 uint64 + switch code.NumBitSize { + case 8: + u64 = (uint64)(**(**uint8)(unsafe.Pointer(&p))) + case 16: + u64 = (uint64)(**(**uint16)(unsafe.Pointer(&p))) + case 32: + u64 = (uint64)(**(**uint32)(unsafe.Pointer(&p))) + case 64: + u64 = **(**uint64)(unsafe.Pointer(&p)) + } mask := numMask(code.NumBitSize) n := u64 & mask if n < 10 { diff --git a/internal/encoder/vm/util.go b/internal/encoder/vm/util.go index f06f9c8..c0c58af 100644 --- a/internal/encoder/vm/util.go +++ b/internal/encoder/vm/util.go @@ -68,7 +68,19 @@ func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr { return p } -func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) } +func ptrToUint64(p uintptr, bitSize uint8) uint64 { + switch bitSize { + case 8: + return (uint64)(**(**uint8)(unsafe.Pointer(&p))) + case 16: + return (uint64)(**(**uint16)(unsafe.Pointer(&p))) + case 32: + return (uint64)(**(**uint32)(unsafe.Pointer(&p))) + case 64: + return **(**uint64)(unsafe.Pointer(&p)) + } + return 0 +} func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) } func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) } func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) } diff --git a/internal/encoder/vm/vm.go b/internal/encoder/vm/vm.go index 6853dc4..7701501 100644 --- a/internal/encoder/vm/vm.go +++ b/internal/encoder/vm/vm.go @@ -40,7 +40,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpInt: - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpUintPtr: @@ -54,18 +54,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpUint: - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpIntString: b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpUintString: b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -662,7 +662,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyInt: @@ -692,13 +692,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -731,7 +731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -762,14 +762,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -806,7 +806,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -840,7 +840,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -877,7 +877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -913,7 +913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -946,7 +946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyUint: @@ -976,13 +976,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -1015,7 +1015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1046,14 +1046,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1090,7 +1090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -1124,7 +1124,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -1161,7 +1161,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -1197,7 +1197,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3473,16 +3473,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3490,18 +3490,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3513,7 +3513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3522,7 +3522,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3534,7 +3534,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3545,7 +3545,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3553,16 +3553,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3570,18 +3570,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3593,7 +3593,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3602,7 +3602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3614,7 +3614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3625,7 +3625,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -4357,16 +4357,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4376,18 +4376,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4401,7 +4401,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4410,7 +4410,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4445,16 +4445,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4464,18 +4464,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4489,7 +4489,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4498,7 +4498,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { diff --git a/internal/encoder/vm_color/util.go b/internal/encoder/vm_color/util.go index 710087f..d1efe3c 100644 --- a/internal/encoder/vm_color/util.go +++ b/internal/encoder/vm_color/util.go @@ -61,7 +61,19 @@ func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr { return p } -func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) } +func ptrToUint64(p uintptr, bitSize uint8) uint64 { + switch bitSize { + case 8: + return (uint64)(**(**uint8)(unsafe.Pointer(&p))) + case 16: + return (uint64)(**(**uint16)(unsafe.Pointer(&p))) + case 32: + return (uint64)(**(**uint32)(unsafe.Pointer(&p))) + case 64: + return **(**uint64)(unsafe.Pointer(&p)) + } + return 0 +} func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) } func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) } func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) } @@ -92,17 +104,17 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} { })) } -func appendInt(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte { +func appendInt(ctx *encoder.RuntimeContext, b []byte, p uintptr, code *encoder.Opcode) []byte { format := ctx.Option.ColorScheme.Int b = append(b, format.Header...) - b = encoder.AppendInt(ctx, b, v, code) + b = encoder.AppendInt(ctx, b, p, code) return append(b, format.Footer...) } -func appendUint(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte { +func appendUint(ctx *encoder.RuntimeContext, b []byte, p uintptr, code *encoder.Opcode) []byte { format := ctx.Option.ColorScheme.Uint b = append(b, format.Header...) - b = encoder.AppendUint(ctx, b, v, code) + b = encoder.AppendUint(ctx, b, p, code) return append(b, format.Footer...) } diff --git a/internal/encoder/vm_color/vm.go b/internal/encoder/vm_color/vm.go index 256781d..c90bdf6 100644 --- a/internal/encoder/vm_color/vm.go +++ b/internal/encoder/vm_color/vm.go @@ -40,7 +40,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpInt: - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpUintPtr: @@ -54,18 +54,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpUint: - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpIntString: b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpUintString: b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -662,7 +662,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyInt: @@ -692,13 +692,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -731,7 +731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -762,14 +762,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -806,7 +806,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -840,7 +840,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -877,7 +877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -913,7 +913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -946,7 +946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyUint: @@ -976,13 +976,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -1015,7 +1015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1046,14 +1046,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1090,7 +1090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -1124,7 +1124,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -1161,7 +1161,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -1197,7 +1197,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3473,16 +3473,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3490,18 +3490,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3513,7 +3513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3522,7 +3522,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3534,7 +3534,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3545,7 +3545,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3553,16 +3553,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3570,18 +3570,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3593,7 +3593,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3602,7 +3602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3614,7 +3614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3625,7 +3625,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -4357,16 +4357,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4376,18 +4376,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4401,7 +4401,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4410,7 +4410,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4445,16 +4445,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4464,18 +4464,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4489,7 +4489,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4498,7 +4498,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { diff --git a/internal/encoder/vm_color_indent/util.go b/internal/encoder/vm_color_indent/util.go index 1399a25..22fac09 100644 --- a/internal/encoder/vm_color_indent/util.go +++ b/internal/encoder/vm_color_indent/util.go @@ -63,7 +63,20 @@ func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr { return p } -func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) } +func ptrToUint64(p uintptr, bitSize uint8) uint64 { + switch bitSize { + case 8: + return (uint64)(**(**uint8)(unsafe.Pointer(&p))) + case 16: + return (uint64)(**(**uint16)(unsafe.Pointer(&p))) + case 32: + return (uint64)(**(**uint32)(unsafe.Pointer(&p))) + case 64: + return **(**uint64)(unsafe.Pointer(&p)) + } + return 0 +} + func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) } func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) } func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) } @@ -94,17 +107,17 @@ func ptrToInterface(code *encoder.Opcode, p uintptr) interface{} { })) } -func appendInt(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte { +func appendInt(ctx *encoder.RuntimeContext, b []byte, p uintptr, code *encoder.Opcode) []byte { format := ctx.Option.ColorScheme.Int b = append(b, format.Header...) - b = encoder.AppendInt(ctx, b, v, code) + b = encoder.AppendInt(ctx, b, p, code) return append(b, format.Footer...) } -func appendUint(ctx *encoder.RuntimeContext, b []byte, v uint64, code *encoder.Opcode) []byte { +func appendUint(ctx *encoder.RuntimeContext, b []byte, p uintptr, code *encoder.Opcode) []byte { format := ctx.Option.ColorScheme.Uint b = append(b, format.Header...) - b = encoder.AppendUint(ctx, b, v, code) + b = encoder.AppendUint(ctx, b, p, code) return append(b, format.Footer...) } diff --git a/internal/encoder/vm_color_indent/vm.go b/internal/encoder/vm_color_indent/vm.go index c9011c8..5fda04b 100644 --- a/internal/encoder/vm_color_indent/vm.go +++ b/internal/encoder/vm_color_indent/vm.go @@ -40,7 +40,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpInt: - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpUintPtr: @@ -54,18 +54,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpUint: - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpIntString: b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpUintString: b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -662,7 +662,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyInt: @@ -692,13 +692,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -731,7 +731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -762,14 +762,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -806,7 +806,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -840,7 +840,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -877,7 +877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -913,7 +913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -946,7 +946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyUint: @@ -976,13 +976,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -1015,7 +1015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1046,14 +1046,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1090,7 +1090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -1124,7 +1124,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -1161,7 +1161,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -1197,7 +1197,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3473,16 +3473,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3490,18 +3490,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3513,7 +3513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3522,7 +3522,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3534,7 +3534,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3545,7 +3545,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3553,16 +3553,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3570,18 +3570,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3593,7 +3593,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3602,7 +3602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3614,7 +3614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3625,7 +3625,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -4357,16 +4357,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4376,18 +4376,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4401,7 +4401,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4410,7 +4410,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4445,16 +4445,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4464,18 +4464,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4489,7 +4489,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4498,7 +4498,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { diff --git a/internal/encoder/vm_indent/util.go b/internal/encoder/vm_indent/util.go index 2e3c35f..9982d0d 100644 --- a/internal/encoder/vm_indent/util.go +++ b/internal/encoder/vm_indent/util.go @@ -70,7 +70,19 @@ func loadNPtr(base uintptr, idx uint32, ptrNum uint8) uintptr { return p } -func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) } +func ptrToUint64(p uintptr, bitSize uint8) uint64 { + switch bitSize { + case 8: + return (uint64)(**(**uint8)(unsafe.Pointer(&p))) + case 16: + return (uint64)(**(**uint16)(unsafe.Pointer(&p))) + case 32: + return (uint64)(**(**uint32)(unsafe.Pointer(&p))) + case 64: + return **(**uint64)(unsafe.Pointer(&p)) + } + return 0 +} func ptrToFloat32(p uintptr) float32 { return **(**float32)(unsafe.Pointer(&p)) } func ptrToFloat64(p uintptr) float64 { return **(**float64)(unsafe.Pointer(&p)) } func ptrToBool(p uintptr) bool { return **(**bool)(unsafe.Pointer(&p)) } diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index 2502216..8ca28cd 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -40,7 +40,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpInt: - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpUintPtr: @@ -54,18 +54,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b store(ctxptr, code.Idx, p) fallthrough case encoder.OpUint: - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = appendComma(ctx, b) code = code.Next case encoder.OpIntString: b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendInt(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpUintString: b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(load(ctxptr, code.Idx)), code) + b = appendUint(ctx, b, load(ctxptr, code.Idx), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -662,7 +662,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyInt: @@ -692,13 +692,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -731,7 +731,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -762,14 +762,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -806,7 +806,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -840,7 +840,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -877,7 +877,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -913,7 +913,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -946,7 +946,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendStructHead(ctx, b) } b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructPtrHeadOmitEmptyUint: @@ -976,13 +976,13 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next } @@ -1015,7 +1015,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1046,14 +1046,14 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if code.Flags&encoder.AnonymousHeadFlags == 0 { b = appendStructHead(ctx, b) } - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v == 0 { code = code.NextField } else { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next @@ -1090,7 +1090,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -1124,7 +1124,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b } if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -1161,7 +1161,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -1197,7 +1197,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3473,16 +3473,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3490,18 +3490,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3513,7 +3513,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3522,7 +3522,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3534,7 +3534,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3545,7 +3545,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3553,16 +3553,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructFieldUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendComma(ctx, b) } code = code.Next @@ -3570,18 +3570,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) code = code.Next case encoder.OpStructFieldOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendComma(ctx, b) } @@ -3593,7 +3593,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendComma(ctx, b) code = code.Next @@ -3602,7 +3602,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendComma(ctx, b) } code = code.Next @@ -3614,7 +3614,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendComma(ctx, b) @@ -3625,7 +3625,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendComma(ctx, b) } @@ -4357,16 +4357,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndInt: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyInt: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4376,18 +4376,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyIntString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, u64, code) + b = appendInt(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4401,7 +4401,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4410,7 +4410,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4424,7 +4424,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4435,7 +4435,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendInt(ctx, b, ptrToUint64(p), code) + b = appendInt(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4445,16 +4445,16 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b case encoder.OpStructEndUint: p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUint: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4464,18 +4464,18 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p := load(ctxptr, code.Idx) b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p+uintptr(code.Offset)), code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) code = code.Next case encoder.OpStructEndOmitEmptyUintString: p := load(ctxptr, code.Idx) - u64 := ptrToUint64(p + uintptr(code.Offset)) + u64 := ptrToUint64(p+uintptr(code.Offset), code.NumBitSize) v := u64 & ((1 << code.NumBitSize) - 1) if v != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, u64, code) + b = appendUint(ctx, b, p+uintptr(code.Offset), code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else { @@ -4489,7 +4489,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p == 0 { b = appendNull(ctx, b) } else { - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) } b = appendStructEnd(ctx, code, b) code = code.Next @@ -4498,7 +4498,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b p = ptrToNPtr(p+uintptr(code.Offset), code.PtrNum) if p != 0 { b = appendStructKey(ctx, code, b) - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = appendStructEnd(ctx, code, b) } else { b = appendStructEndSkipLast(ctx, code, b) @@ -4512,7 +4512,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b b = appendNull(ctx, b) } else { b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') } b = appendStructEnd(ctx, code, b) @@ -4523,7 +4523,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b if p != 0 { b = appendStructKey(ctx, code, b) b = append(b, '"') - b = appendUint(ctx, b, ptrToUint64(p), code) + b = appendUint(ctx, b, p, code) b = append(b, '"') b = appendStructEnd(ctx, code, b) } else {