Fix index number

This commit is contained in:
Masaaki Goshima 2020-09-01 23:23:07 +09:00
parent 18a6e4cffe
commit 4f4060f808
2 changed files with 14 additions and 11 deletions

View File

@ -954,7 +954,7 @@ func (e *Encoder) compileStruct(ctx *encodeCompileContext, isPtr bool) (*opcode,
} }
structEndCode.displayIdx = ctx.opcodeIndex structEndCode.displayIdx = ctx.opcodeIndex
structEndCode.idx = opcodeOffset(ctx.opcodeIndex) structEndCode.idx = opcodeOffset(ctx.ptrIndex)
ctx.incIndex() ctx.incIndex()
if ctx.withIndent { if ctx.withIndent {

View File

@ -95,6 +95,18 @@ func (c *opcode) decOpcodeIndex() {
for code := c; code.op != opEnd; { for code := c; code.op != opEnd; {
code.displayIdx-- code.displayIdx--
code.idx -= uintptrSize code.idx -= uintptrSize
if code.headIdx > 0 {
code.headIdx -= uintptrSize
}
if code.elemIdx > 0 {
code.elemIdx -= uintptrSize
}
if code.mapIter > 0 {
code.mapIter -= uintptrSize
}
if code.length > 0 && code.op.codeType() != codeArrayHead && code.op.codeType() != codeArrayElem {
code.length -= uintptrSize
}
switch code.op.codeType() { switch code.op.codeType() {
case codeArrayElem, codeSliceElem, codeMapKey: case codeArrayElem, codeSliceElem, codeMapKey:
code = code.end code = code.end
@ -106,7 +118,7 @@ func (c *opcode) decOpcodeIndex() {
func (c *opcode) dumpHead(code *opcode) string { func (c *opcode) dumpHead(code *opcode) string {
var length uintptr var length uintptr
if code.op.codeType() == codeArrayElem { if code.op.codeType() == codeArrayHead {
length = code.length length = code.length
} else { } else {
length = code.length / uintptrSize length = code.length / uintptrSize
@ -382,12 +394,3 @@ func newRecursiveCode(ctx *encodeCompileContext, jmp *compiledCode) *opcode {
jmp: jmp, jmp: jmp,
} }
} }
//func newRecursiveCode(recursive *recursiveCode) *opcode {
//code := copyOpcode(recursive.jmp.code)
//head := (*structFieldCode)(unsafe.Pointer(code))
//head.end.next = newEndOp(&encodeCompileContext{})
//code.op = code.op.ptrHeadToHead()
// return code
//}