2020-08-29 09:35:03 +03:00
|
|
|
package json
|
|
|
|
|
2020-08-30 11:52:59 +03:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2020-08-29 09:35:03 +03:00
|
|
|
type encodeCompileContext struct {
|
|
|
|
typ *rtype
|
|
|
|
withIndent bool
|
|
|
|
root bool
|
|
|
|
opcodeIndex int
|
|
|
|
indent int
|
2020-08-30 11:32:26 +03:00
|
|
|
|
|
|
|
parent *encodeCompileContext
|
2020-08-29 09:35:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeCompileContext) context() *encodeCompileContext {
|
|
|
|
return &encodeCompileContext{
|
|
|
|
typ: c.typ,
|
|
|
|
withIndent: c.withIndent,
|
|
|
|
root: c.root,
|
|
|
|
opcodeIndex: c.opcodeIndex,
|
|
|
|
indent: c.indent,
|
2020-08-30 11:32:26 +03:00
|
|
|
parent: c,
|
2020-08-29 09:35:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeCompileContext) withType(typ *rtype) *encodeCompileContext {
|
|
|
|
ctx := c.context()
|
|
|
|
ctx.typ = typ
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeCompileContext) incIndent() *encodeCompileContext {
|
|
|
|
ctx := c.context()
|
|
|
|
ctx.indent++
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeCompileContext) decIndent() *encodeCompileContext {
|
|
|
|
ctx := c.context()
|
|
|
|
ctx.indent--
|
|
|
|
return ctx
|
|
|
|
}
|
2020-08-30 11:32:26 +03:00
|
|
|
|
|
|
|
func (c *encodeCompileContext) incOpcodeIndex() {
|
|
|
|
c.opcodeIndex++
|
|
|
|
if c.parent != nil {
|
|
|
|
c.parent.incOpcodeIndex()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeCompileContext) decOpcodeIndex() {
|
|
|
|
c.opcodeIndex--
|
|
|
|
if c.parent != nil {
|
|
|
|
c.parent.decOpcodeIndex()
|
|
|
|
}
|
|
|
|
}
|
2020-08-30 11:52:59 +03:00
|
|
|
|
|
|
|
type encodeRuntimeContext []uintptr
|
|
|
|
|
|
|
|
func (c *encodeRuntimeContext) init(p uintptr) {
|
|
|
|
(*c)[0] = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *encodeRuntimeContext) ptr() *uintptr {
|
|
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(c))
|
|
|
|
return (*uintptr)(unsafe.Pointer(&header.Data))
|
|
|
|
}
|