package encoder

import (
	
	
	

	
)

type compileContext struct {
	opcodeIndex       uint32
	ptrIndex          int
	indent            uint32
	escapeKey         bool
	structTypeToCodes map[uintptr]Opcodes
	recursiveCodes    *Opcodes
}

func ( *compileContext) () {
	.indent++
}

func ( *compileContext) () {
	.indent--
}

func ( *compileContext) () {
	.incOpcodeIndex()
	.incPtrIndex()
}

func ( *compileContext) () {
	.decOpcodeIndex()
	.decPtrIndex()
}

func ( *compileContext) () {
	.opcodeIndex++
}

func ( *compileContext) () {
	.opcodeIndex--
}

func ( *compileContext) () {
	.ptrIndex++
}

func ( *compileContext) () {
	.ptrIndex--
}

const (
	bufSize = 1024
)

var (
	runtimeContextPool = sync.Pool{
		New: func() interface{} {
			return &RuntimeContext{
				Buf:      make([]byte, 0, bufSize),
				Ptrs:     make([]uintptr, 128),
				KeepRefs: make([]unsafe.Pointer, 0, 8),
				Option:   &Option{},
			}
		},
	}
)

type RuntimeContext struct {
	Context    context.Context
	Buf        []byte
	MarshalBuf []byte
	Ptrs       []uintptr
	KeepRefs   []unsafe.Pointer
	SeenPtr    []uintptr
	BaseIndent uint32
	Prefix     []byte
	IndentStr  []byte
	Option     *Option
}

func ( *RuntimeContext) ( uintptr,  int) {
	if len(.Ptrs) <  {
		.Ptrs = make([]uintptr, )
	}
	.Ptrs[0] = 
	.KeepRefs = .KeepRefs[:0]
	.SeenPtr = .SeenPtr[:0]
	.BaseIndent = 0
}

func ( *RuntimeContext) () uintptr {
	 := (*runtime.SliceHeader)(unsafe.Pointer(&.Ptrs))
	return uintptr(.Data)
}

func () *RuntimeContext {
	return runtimeContextPool.Get().(*RuntimeContext)
}

func ( *RuntimeContext) {
	runtimeContextPool.Put()
}