diff --git a/encode_vm.go b/encode_vm.go index 46d44d1..ebf8366 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -87,10 +87,58 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeComma(b) code = code.next + case opIntPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next + case opIntNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next case opUint: b = appendUint(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeComma(b) code = code.next + case opUintPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next + case opUintNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next case opIntString: b = append(b, '"') b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) @@ -107,6 +155,30 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = encodeFloat32(b, ptrToFloat32(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opFloat32Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeComma(b) + code = code.next + case opFloat32NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeComma(b) + code = code.next case opFloat64: v := ptrToFloat64(load(ctxptr, code.idx)) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -115,18 +187,98 @@ func encodeRun(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, opt Enco b = encodeFloat64(b, v) b = encodeComma(b) code = code.next + case opFloat64Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeComma(b) + code = code.next + case opFloat64NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeComma(b) + code = code.next case opString: b = encodeNoEscapedString(b, ptrToString(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opStringPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeComma(b) + code = code.next + case opStringNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeComma(b) + code = code.next case opBool: b = encodeBool(b, ptrToBool(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opBoolPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeComma(b) + code = code.next + case opBoolNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeComma(b) + code = code.next case opBytes: ptr := load(ctxptr, code.idx) slice := ptrToSlice(ptr) - if ptr == 0 || uintptr(slice.data) == 0 { + if ptr == 0 || slice.data == nil { b = encodeNull(b) } else { b = encodeByteSlice(b, ptrToBytes(ptr)) diff --git a/encode_vm_escaped.go b/encode_vm_escaped.go index 2c2c6d0..3d4e9e4 100644 --- a/encode_vm_escaped.go +++ b/encode_vm_escaped.go @@ -30,10 +30,58 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeComma(b) code = code.next + case opIntPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next + case opIntNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next case opUint: b = appendUint(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeComma(b) code = code.next + case opUintPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next + case opUintNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeComma(b) + code = code.next case opIntString: b = append(b, '"') b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) @@ -50,6 +98,30 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = encodeFloat32(b, ptrToFloat32(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opFloat32Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeComma(b) + code = code.next + case opFloat32NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeComma(b) + code = code.next case opFloat64: v := ptrToFloat64(load(ctxptr, code.idx)) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -58,14 +130,94 @@ func encodeRunEscaped(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, o b = encodeFloat64(b, v) b = encodeComma(b) code = code.next + case opFloat64Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeComma(b) + code = code.next + case opFloat64NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeComma(b) + code = code.next case opString: b = encodeEscapedString(b, ptrToString(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opStringPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeComma(b) + code = code.next + case opStringNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeComma(b) + code = code.next case opBool: b = encodeBool(b, ptrToBool(load(ctxptr, code.idx))) b = encodeComma(b) code = code.next + case opBoolPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeComma(b) + code = code.next + case opBoolNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeComma(b) + code = code.next case opBytes: ptr := load(ctxptr, code.idx) slice := ptrToSlice(ptr) diff --git a/encode_vm_escaped_indent.go b/encode_vm_escaped_indent.go index 0a24438..24dc1a9 100644 --- a/encode_vm_escaped_indent.go +++ b/encode_vm_escaped_indent.go @@ -29,10 +29,58 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeIndentComma(b) code = code.next + case opIntPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next + case opIntNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next case opUint: b = appendUint(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeIndentComma(b) code = code.next + case opUintPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next + case opUintNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next case opIntString: b = append(b, '"') b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) @@ -49,6 +97,30 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = encodeFloat32(b, ptrToFloat32(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opFloat32Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeIndentComma(b) + code = code.next + case opFloat32NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeIndentComma(b) + code = code.next case opFloat64: v := ptrToFloat64(load(ctxptr, code.idx)) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -57,14 +129,94 @@ func encodeRunEscapedIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcode b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opFloat64Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeIndentComma(b) + code = code.next + case opFloat64NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeIndentComma(b) + code = code.next case opString: b = encodeEscapedString(b, ptrToString(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opStringPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeIndentComma(b) + code = code.next + case opStringNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeIndentComma(b) + code = code.next case opBool: b = encodeBool(b, ptrToBool(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opBoolPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeIndentComma(b) + code = code.next + case opBoolNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeIndentComma(b) + code = code.next case opBytes: ptr := load(ctxptr, code.idx) slice := ptrToSlice(ptr) diff --git a/encode_vm_indent.go b/encode_vm_indent.go index a05bc9e..77307ab 100644 --- a/encode_vm_indent.go +++ b/encode_vm_indent.go @@ -29,10 +29,58 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeIndentComma(b) code = code.next + case opIntPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next + case opIntNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendInt(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next case opUint: b = appendUint(b, ptrToUint64(load(ctxptr, code.idx)), code) b = encodeIndentComma(b) code = code.next + case opUintPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next + case opUintNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = appendUint(b, ptrToUint64(p), code) + } + b = encodeIndentComma(b) + code = code.next case opIntString: b = append(b, '"') b = appendInt(b, ptrToUint64(load(ctxptr, code.idx)), code) @@ -49,6 +97,30 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = encodeFloat32(b, ptrToFloat32(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opFloat32Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeIndentComma(b) + code = code.next + case opFloat32NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeFloat32(b, ptrToFloat32(p)) + } + b = encodeIndentComma(b) + code = code.next case opFloat64: v := ptrToFloat64(load(ctxptr, code.idx)) if math.IsInf(v, 0) || math.IsNaN(v) { @@ -57,14 +129,94 @@ func encodeRunIndent(ctx *encodeRuntimeContext, b []byte, codeSet *opcodeSet, op b = encodeFloat64(b, v) b = encodeIndentComma(b) code = code.next + case opFloat64Ptr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeIndentComma(b) + code = code.next + case opFloat64NPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + v := ptrToFloat64(p) + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil, errUnsupportedFloat(v) + } + b = encodeFloat64(b, v) + } + b = encodeIndentComma(b) + code = code.next case opString: b = encodeNoEscapedString(b, ptrToString(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opStringPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeIndentComma(b) + code = code.next + case opStringNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeEscapedString(b, ptrToString(p)) + } + b = encodeIndentComma(b) + code = code.next case opBool: b = encodeBool(b, ptrToBool(load(ctxptr, code.idx))) b = encodeIndentComma(b) code = code.next + case opBoolPtr: + p := ptrToPtr(load(ctxptr, code.idx)) + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeIndentComma(b) + code = code.next + case opBoolNPtr: + p := load(ctxptr, code.idx) + for i := 0; i < code.ptrNum; i++ { + if p == 0 { + break + } + p = ptrToPtr(p) + } + if p == 0 { + b = encodeNull(b) + } else { + b = encodeBool(b, ptrToBool(p)) + } + b = encodeIndentComma(b) + code = code.next case opBytes: ptr := load(ctxptr, code.idx) slice := ptrToSlice(ptr)