mirror of https://github.com/goccy/go-json.git
Merge pull request #155 from goccy/feature/add-bytes-test
Fix encoding of primitive pointer types and []byte type
This commit is contained in:
commit
094f8da49e
|
@ -32,6 +32,27 @@ func TestCoverBool(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Bool",
|
||||
data: bool(true),
|
||||
},
|
||||
{
|
||||
name: "BoolPtr",
|
||||
data: boolptr(true),
|
||||
},
|
||||
{
|
||||
name: "BoolPtr3",
|
||||
data: boolptr3(true),
|
||||
},
|
||||
{
|
||||
name: "BoolPtrNil",
|
||||
data: (*bool)(nil),
|
||||
},
|
||||
{
|
||||
name: "BoolPtr3Nil",
|
||||
data: (***bool)(nil),
|
||||
},
|
||||
|
||||
// HeadBoolZero
|
||||
{
|
||||
name: "HeadBoolZero",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -32,6 +32,27 @@ func TestCoverFloat32(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Float32",
|
||||
data: float32(10),
|
||||
},
|
||||
{
|
||||
name: "Float32Ptr",
|
||||
data: float32ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Float32Ptr3",
|
||||
data: float32ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Float32PtrNil",
|
||||
data: (*float32)(nil),
|
||||
},
|
||||
{
|
||||
name: "Float32Ptr3Nil",
|
||||
data: (***float32)(nil),
|
||||
},
|
||||
|
||||
// HeadFloat32Zero
|
||||
{
|
||||
name: "HeadFloat32Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverFloat64(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Float64",
|
||||
data: float64(10),
|
||||
},
|
||||
{
|
||||
name: "Float64Ptr",
|
||||
data: float64ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Float64Ptr3",
|
||||
data: float64ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Float64PtrNil",
|
||||
data: (*float64)(nil),
|
||||
},
|
||||
{
|
||||
name: "Float64Ptr3Nil",
|
||||
data: (***float64)(nil),
|
||||
},
|
||||
|
||||
// HeadFloat64Zero
|
||||
{
|
||||
name: "HeadFloat64Zero",
|
||||
|
|
|
@ -6,19 +6,35 @@ import (
|
|||
)
|
||||
|
||||
func intptr(v int) *int { return &v }
|
||||
func intptr3(v int) ***int { vv := &v; vvv := &vv; return &vvv }
|
||||
func int8ptr(v int8) *int8 { return &v }
|
||||
func int8ptr3(v int8) ***int8 { vv := &v; vvv := &vv; return &vvv }
|
||||
func int16ptr(v int16) *int16 { return &v }
|
||||
func int16ptr3(v int16) ***int16 { vv := &v; vvv := &vv; return &vvv }
|
||||
func int32ptr(v int32) *int32 { return &v }
|
||||
func int32ptr3(v int32) ***int32 { vv := &v; vvv := &vv; return &vvv }
|
||||
func int64ptr(v int64) *int64 { return &v }
|
||||
func int64ptr3(v int64) ***int64 { vv := &v; vvv := &vv; return &vvv }
|
||||
func uptr(v uint) *uint { return &v }
|
||||
func uintptr3(v uint) ***uint { vv := &v; vvv := &vv; return &vvv }
|
||||
func uint8ptr(v uint8) *uint8 { return &v }
|
||||
func uint8ptr3(v uint8) ***uint8 { vv := &v; vvv := &vv; return &vvv }
|
||||
func uint16ptr(v uint16) *uint16 { return &v }
|
||||
func uint16ptr3(v uint16) ***uint16 { vv := &v; vvv := &vv; return &vvv }
|
||||
func uint32ptr(v uint32) *uint32 { return &v }
|
||||
func uint32ptr3(v uint32) ***uint32 { vv := &v; vvv := &vv; return &vvv }
|
||||
func uint64ptr(v uint64) *uint64 { return &v }
|
||||
func uint64ptr3(v uint64) ***uint64 { vv := &v; vvv := &vv; return &vvv }
|
||||
func float32ptr(v float32) *float32 { return &v }
|
||||
func float32ptr3(v float32) ***float32 { vv := &v; vvv := &vv; return &vvv }
|
||||
func float64ptr(v float64) *float64 { return &v }
|
||||
func float64ptr3(v float64) ***float64 { vv := &v; vvv := &vv; return &vvv }
|
||||
func stringptr(v string) *string { return &v }
|
||||
func stringptr3(v string) ***string { vv := &v; vvv := &vv; return &vvv }
|
||||
func boolptr(v bool) *bool { return &v }
|
||||
func boolptr3(v bool) ***bool { vv := &v; vvv := &vv; return &vvv }
|
||||
func bytesptr(v []byte) *[]byte { return &v }
|
||||
func bytesptr3(v []byte) ***[]byte { vv := &v; vvv := &vv; return &vvv }
|
||||
func sliceptr(v []int) *[]int { return &v }
|
||||
func arrayptr(v [2]int) *[2]int { return &v }
|
||||
func mapptr(v map[string]int) *map[string]int { return &v }
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverInt16(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Int16",
|
||||
data: int16(10),
|
||||
},
|
||||
{
|
||||
name: "Int16Ptr",
|
||||
data: int16ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Int16Ptr3",
|
||||
data: int16ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Int16PtrNil",
|
||||
data: (*int16)(nil),
|
||||
},
|
||||
{
|
||||
name: "Int16Ptr3Nil",
|
||||
data: (***int16)(nil),
|
||||
},
|
||||
|
||||
// HeadInt16Zero
|
||||
{
|
||||
name: "HeadInt16Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverInt32(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Int32",
|
||||
data: int32(10),
|
||||
},
|
||||
{
|
||||
name: "Int32Ptr",
|
||||
data: int32ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Int32Ptr3",
|
||||
data: int32ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Int32PtrNil",
|
||||
data: (*int32)(nil),
|
||||
},
|
||||
{
|
||||
name: "Int32Ptr3Nil",
|
||||
data: (***int32)(nil),
|
||||
},
|
||||
|
||||
// HeadInt32Zero
|
||||
{
|
||||
name: "HeadInt32Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverInt64(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Int64",
|
||||
data: int64(10),
|
||||
},
|
||||
{
|
||||
name: "Int64Ptr",
|
||||
data: int64ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Int64Ptr3",
|
||||
data: int64ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Int64PtrNil",
|
||||
data: (*int64)(nil),
|
||||
},
|
||||
{
|
||||
name: "Int64Ptr3Nil",
|
||||
data: (***int64)(nil),
|
||||
},
|
||||
|
||||
// HeadInt64Zero
|
||||
{
|
||||
name: "HeadInt64Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverInt8(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Int8",
|
||||
data: int8(10),
|
||||
},
|
||||
{
|
||||
name: "Int8Ptr",
|
||||
data: int8ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Int8Ptr3",
|
||||
data: int8ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Int8PtrNil",
|
||||
data: (*int8)(nil),
|
||||
},
|
||||
{
|
||||
name: "Int8Ptr3Nil",
|
||||
data: (***int8)(nil),
|
||||
},
|
||||
|
||||
// HeadInt8Zero
|
||||
{
|
||||
name: "HeadInt8Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverInt(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Int",
|
||||
data: 10,
|
||||
},
|
||||
{
|
||||
name: "IntPtr",
|
||||
data: intptr(10),
|
||||
},
|
||||
{
|
||||
name: "IntPtr3",
|
||||
data: intptr3(10),
|
||||
},
|
||||
{
|
||||
name: "IntPtrNil",
|
||||
data: (*int)(nil),
|
||||
},
|
||||
{
|
||||
name: "IntPtr3Nil",
|
||||
data: (***int)(nil),
|
||||
},
|
||||
|
||||
// HeadIntZero
|
||||
{
|
||||
name: "HeadIntZero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverString(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "String",
|
||||
data: string("a"),
|
||||
},
|
||||
{
|
||||
name: "StringPtr",
|
||||
data: stringptr("a"),
|
||||
},
|
||||
{
|
||||
name: "StringPtr3",
|
||||
data: stringptr3("a"),
|
||||
},
|
||||
{
|
||||
name: "StringPtrNil",
|
||||
data: (*string)(nil),
|
||||
},
|
||||
{
|
||||
name: "StringPtr3Nil",
|
||||
data: (***string)(nil),
|
||||
},
|
||||
|
||||
// HeadStringZero
|
||||
{
|
||||
name: "HeadStringZero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverUint16(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Uint16",
|
||||
data: uint16(10),
|
||||
},
|
||||
{
|
||||
name: "Uint16Ptr",
|
||||
data: uint16ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Uint16Ptr3",
|
||||
data: uint16ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Uint16PtrNil",
|
||||
data: (*uint16)(nil),
|
||||
},
|
||||
{
|
||||
name: "Uint16Ptr3Nil",
|
||||
data: (***uint16)(nil),
|
||||
},
|
||||
|
||||
// HeadUint16Zero
|
||||
{
|
||||
name: "HeadUint16Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverUint32(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Uint32",
|
||||
data: uint32(10),
|
||||
},
|
||||
{
|
||||
name: "Uint32Ptr",
|
||||
data: uint32ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Uint32Ptr3",
|
||||
data: uint32ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Uint32PtrNil",
|
||||
data: (*uint32)(nil),
|
||||
},
|
||||
{
|
||||
name: "Uint32Ptr3Nil",
|
||||
data: (***uint32)(nil),
|
||||
},
|
||||
|
||||
// HeadUint32Zero
|
||||
{
|
||||
name: "HeadUint32Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverUint64(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Uint64",
|
||||
data: uint64(10),
|
||||
},
|
||||
{
|
||||
name: "Uint64Ptr",
|
||||
data: uint64ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Uint64Ptr3",
|
||||
data: uint64ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Uint64PtrNil",
|
||||
data: (*uint64)(nil),
|
||||
},
|
||||
{
|
||||
name: "Uint64Ptr3Nil",
|
||||
data: (***uint64)(nil),
|
||||
},
|
||||
|
||||
// HeadUint64Zero
|
||||
{
|
||||
name: "HeadUint64Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverUint8(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Uint8",
|
||||
data: uint8(10),
|
||||
},
|
||||
{
|
||||
name: "Uint8Ptr",
|
||||
data: uint8ptr(10),
|
||||
},
|
||||
{
|
||||
name: "Uint8Ptr3",
|
||||
data: uint8ptr3(10),
|
||||
},
|
||||
{
|
||||
name: "Uint8PtrNil",
|
||||
data: (*uint8)(nil),
|
||||
},
|
||||
{
|
||||
name: "Uint8Ptr3Nil",
|
||||
data: (***uint8)(nil),
|
||||
},
|
||||
|
||||
// HeadUint8Zero
|
||||
{
|
||||
name: "HeadUint8Zero",
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestCoverUint(t *testing.T) {
|
|||
name string
|
||||
data interface{}
|
||||
}{
|
||||
{
|
||||
name: "Uint",
|
||||
data: uint(10),
|
||||
},
|
||||
{
|
||||
name: "UintPtr",
|
||||
data: uptr(10),
|
||||
},
|
||||
{
|
||||
name: "UintPtr3",
|
||||
data: uintptr3(10),
|
||||
},
|
||||
{
|
||||
name: "UintPtrNil",
|
||||
data: (*uint)(nil),
|
||||
},
|
||||
{
|
||||
name: "UintPtr3Nil",
|
||||
data: (***uint)(nil),
|
||||
},
|
||||
|
||||
// HeadUintZero
|
||||
{
|
||||
name: "HeadUintZero",
|
||||
|
|
|
@ -90,12 +90,26 @@ func compileHead(ctx *compileContext) (*Opcode, error) {
|
|||
case implementsMarshalText(typ):
|
||||
return compileMarshalText(ctx)
|
||||
}
|
||||
if typ.Kind() == reflect.Map {
|
||||
switch typ.Kind() {
|
||||
case reflect.Slice:
|
||||
ctx := ctx.withType(typ)
|
||||
elem := typ.Elem()
|
||||
if elem.Kind() == reflect.Uint8 {
|
||||
p := runtime.PtrTo(elem)
|
||||
if !p.Implements(marshalJSONType) && !p.Implements(marshalTextType) {
|
||||
if isPtr {
|
||||
return compileBytesPtr(ctx)
|
||||
}
|
||||
return compileBytes(ctx)
|
||||
}
|
||||
}
|
||||
return compileSlice(ctx)
|
||||
case reflect.Map:
|
||||
if isPtr {
|
||||
return compilePtr(ctx.withType(runtime.PtrTo(typ)))
|
||||
}
|
||||
return compileMap(ctx.withType(typ))
|
||||
} else if typ.Kind() == reflect.Struct {
|
||||
case reflect.Struct:
|
||||
code, err := compileStruct(ctx.withType(typ), isPtr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -103,16 +117,108 @@ func compileHead(ctx *compileContext) (*Opcode, error) {
|
|||
optimizeStructEnd(code)
|
||||
linkRecursiveCode(code)
|
||||
return code, nil
|
||||
} else if isPtr && typ.Implements(marshalTextType) {
|
||||
typ = orgType
|
||||
case reflect.Int:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileIntPtr(ctx)
|
||||
}
|
||||
return compileInt(ctx)
|
||||
case reflect.Int8:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileInt8Ptr(ctx)
|
||||
}
|
||||
return compileInt8(ctx)
|
||||
case reflect.Int16:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileInt16Ptr(ctx)
|
||||
}
|
||||
return compileInt16(ctx)
|
||||
case reflect.Int32:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileInt32Ptr(ctx)
|
||||
}
|
||||
return compileInt32(ctx)
|
||||
case reflect.Int64:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileInt64Ptr(ctx)
|
||||
}
|
||||
return compileInt64(ctx)
|
||||
case reflect.Uint, reflect.Uintptr:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileUintPtr(ctx)
|
||||
}
|
||||
return compileUint(ctx)
|
||||
case reflect.Uint8:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileUint8Ptr(ctx)
|
||||
}
|
||||
return compileUint8(ctx)
|
||||
case reflect.Uint16:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileUint16Ptr(ctx)
|
||||
}
|
||||
return compileUint16(ctx)
|
||||
case reflect.Uint32:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileUint32Ptr(ctx)
|
||||
}
|
||||
return compileUint32(ctx)
|
||||
case reflect.Uint64:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileUint64Ptr(ctx)
|
||||
}
|
||||
return compileUint64(ctx)
|
||||
case reflect.Float32:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileFloat32Ptr(ctx)
|
||||
}
|
||||
return compileFloat32(ctx)
|
||||
case reflect.Float64:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileFloat64Ptr(ctx)
|
||||
}
|
||||
return compileFloat64(ctx)
|
||||
case reflect.String:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileStringPtr(ctx)
|
||||
}
|
||||
return compileString(ctx)
|
||||
case reflect.Bool:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileBoolPtr(ctx)
|
||||
}
|
||||
return compileBool(ctx)
|
||||
case reflect.Interface:
|
||||
ctx := ctx.withType(typ)
|
||||
if isPtr {
|
||||
return compileInterfacePtr(ctx)
|
||||
}
|
||||
return compileInterface(ctx)
|
||||
default:
|
||||
if isPtr && typ.Implements(marshalTextType) {
|
||||
typ = orgType
|
||||
}
|
||||
code, err := compile(ctx.withType(typ), isPtr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
optimizeStructEnd(code)
|
||||
linkRecursiveCode(code)
|
||||
return code, nil
|
||||
}
|
||||
code, err := compile(ctx.withType(typ), isPtr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
optimizeStructEnd(code)
|
||||
linkRecursiveCode(code)
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func linkRecursiveCode(c *Opcode) {
|
||||
|
@ -418,6 +524,15 @@ func compileInt(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileIntPtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInt(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpIntPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt8(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpInt)
|
||||
code.setMaskAndRshiftNum(8)
|
||||
|
@ -425,6 +540,15 @@ func compileInt8(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt8Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInt8(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpIntPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt16(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpInt)
|
||||
code.setMaskAndRshiftNum(16)
|
||||
|
@ -432,6 +556,15 @@ func compileInt16(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt16Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInt16(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpIntPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt32(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpInt)
|
||||
code.setMaskAndRshiftNum(32)
|
||||
|
@ -439,6 +572,15 @@ func compileInt32(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt32Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInt32(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpIntPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt64(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpInt)
|
||||
code.setMaskAndRshiftNum(64)
|
||||
|
@ -446,6 +588,15 @@ func compileInt64(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileInt64Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInt64(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpIntPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpUint)
|
||||
code.setMaskAndRshiftNum(intSize)
|
||||
|
@ -453,6 +604,15 @@ func compileUint(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileUintPtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileUint(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpUintPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint8(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpUint)
|
||||
code.setMaskAndRshiftNum(8)
|
||||
|
@ -460,6 +620,15 @@ func compileUint8(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint8Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileUint8(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpUintPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint16(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpUint)
|
||||
code.setMaskAndRshiftNum(16)
|
||||
|
@ -467,6 +636,15 @@ func compileUint16(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint16Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileUint16(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpUintPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint32(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpUint)
|
||||
code.setMaskAndRshiftNum(32)
|
||||
|
@ -474,6 +652,15 @@ func compileUint32(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint32Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileUint32(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpUintPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint64(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpUint)
|
||||
code.setMaskAndRshiftNum(64)
|
||||
|
@ -481,6 +668,15 @@ func compileUint64(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileUint64Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileUint64(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpUintPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileIntString(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpIntString)
|
||||
code.setMaskAndRshiftNum(intSize)
|
||||
|
@ -557,12 +753,30 @@ func compileFloat32(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileFloat32Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileFloat32(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpFloat32Ptr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileFloat64(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpFloat64)
|
||||
ctx.incIndex()
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileFloat64Ptr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileFloat64(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpFloat64Ptr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileString(ctx *compileContext) (*Opcode, error) {
|
||||
var op OpType
|
||||
if ctx.typ == runtime.Type2RType(jsonNumberType) {
|
||||
|
@ -575,24 +789,64 @@ func compileString(ctx *compileContext) (*Opcode, error) {
|
|||
return code, nil
|
||||
}
|
||||
|
||||
func compileStringPtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileString(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if code.Op == OpNumber {
|
||||
code.Op = OpNumberPtr
|
||||
} else {
|
||||
code.Op = OpStringPtr
|
||||
}
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileBool(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpBool)
|
||||
ctx.incIndex()
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileBoolPtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileBool(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpBoolPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileBytes(ctx *compileContext) (*Opcode, error) {
|
||||
code := newOpCode(ctx, OpBytes)
|
||||
ctx.incIndex()
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileBytesPtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileBytes(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpBytesPtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInterface(ctx *compileContext) (*Opcode, error) {
|
||||
code := newInterfaceCode(ctx)
|
||||
ctx.incIndex()
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileInterfacePtr(ctx *compileContext) (*Opcode, error) {
|
||||
code, err := compileInterface(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
code.Op = OpInterfacePtr
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func compileSlice(ctx *compileContext) (*Opcode, error) {
|
||||
elem := ctx.typ.Elem()
|
||||
size := elem.Size()
|
||||
|
|
|
@ -96,6 +96,10 @@ func (c *Opcode) ToHeaderType() OpType {
|
|||
return OpStructHeadBool
|
||||
case OpBoolPtr:
|
||||
return OpStructHeadBoolPtr
|
||||
case OpBytes:
|
||||
return OpStructHeadBytes
|
||||
case OpBytesPtr:
|
||||
return OpStructHeadBytesPtr
|
||||
case OpMap:
|
||||
return OpStructHeadMap
|
||||
case OpMapPtr:
|
||||
|
@ -153,6 +157,10 @@ func (c *Opcode) ToFieldType() OpType {
|
|||
return OpStructFieldBool
|
||||
case OpBoolPtr:
|
||||
return OpStructFieldBoolPtr
|
||||
case OpBytes:
|
||||
return OpStructFieldBytes
|
||||
case OpBytesPtr:
|
||||
return OpStructFieldBytesPtr
|
||||
case OpMap:
|
||||
return OpStructFieldMap
|
||||
case OpMapPtr:
|
||||
|
|
|
@ -18,13 +18,16 @@ func store(base uintptr, idx uintptr, p uintptr) {
|
|||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uintptr, _ int) uintptr {
|
||||
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
|
||||
addr := base + idx
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
if p == 0 {
|
||||
return 0
|
||||
for i := 0; i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return ptrToPtr(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
|
|
|
@ -2024,9 +2024,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
b = append(b, '{')
|
||||
}
|
||||
b = append(b, code.Key...)
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p+code.Offset))
|
||||
b = append(b, '"')
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadBytesPtr:
|
||||
|
@ -2131,9 +2129,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
|
@ -4386,9 +4382,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.Next
|
||||
|
|
|
@ -18,13 +18,16 @@ func store(base uintptr, idx uintptr, p uintptr) {
|
|||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uintptr, _ int) uintptr {
|
||||
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
|
||||
addr := base + idx
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
if p == 0 {
|
||||
return 0
|
||||
for i := 0; i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return ptrToPtr(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
|
|
|
@ -2024,9 +2024,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
b = append(b, '{')
|
||||
}
|
||||
b = append(b, code.EscapedKey...)
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p+code.Offset))
|
||||
b = append(b, '"')
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
case encoder.OpStructPtrHeadBytesPtr:
|
||||
|
@ -2131,9 +2129,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
|
@ -4386,9 +4382,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(b)
|
||||
code = code.Next
|
||||
|
|
|
@ -19,13 +19,16 @@ func store(base uintptr, idx uintptr, p uintptr) {
|
|||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uintptr, _ int) uintptr {
|
||||
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
|
||||
addr := base + idx
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
if p == 0 {
|
||||
return 0
|
||||
for i := 0; i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return ptrToPtr(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
|
|
|
@ -2230,9 +2230,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
|
@ -4848,9 +4846,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, b, code.Indent-1)
|
||||
code = code.Next
|
||||
|
|
|
@ -19,13 +19,16 @@ func store(base uintptr, idx uintptr, p uintptr) {
|
|||
**(**uintptr)(unsafe.Pointer(&addr)) = p
|
||||
}
|
||||
|
||||
func loadNPtr(base uintptr, idx uintptr, _ int) uintptr {
|
||||
func loadNPtr(base uintptr, idx uintptr, ptrNum int) uintptr {
|
||||
addr := base + idx
|
||||
p := **(**uintptr)(unsafe.Pointer(&addr))
|
||||
if p == 0 {
|
||||
return 0
|
||||
for i := 0; i < ptrNum; i++ {
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
p = ptrToPtr(p)
|
||||
}
|
||||
return ptrToPtr(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func ptrToUint64(p uintptr) uint64 { return **(**uint64)(unsafe.Pointer(&p)) }
|
||||
|
|
|
@ -2236,9 +2236,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendComma(b)
|
||||
code = code.Next
|
||||
|
@ -4854,9 +4852,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt
|
|||
if p == 0 {
|
||||
b = appendNull(b)
|
||||
} else {
|
||||
b = append(b, '"')
|
||||
b = appendByteSlice(b, ptrToBytes(p))
|
||||
b = append(b, '"')
|
||||
}
|
||||
b = appendStructEnd(ctx, b, code.Indent-1)
|
||||
code = code.Next
|
||||
|
|
Loading…
Reference in New Issue