mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
compiler: remove finallyProcessIndex
from funcScope
This commit is contained in:
parent
2eb91066ea
commit
2aaaf30db7
3 changed files with 11 additions and 8 deletions
|
@ -121,7 +121,7 @@ func (c *codegen) traverseGlobals() (int, int, int) {
|
||||||
// store auxiliary variables after all others.
|
// store auxiliary variables after all others.
|
||||||
if hasDefer {
|
if hasDefer {
|
||||||
c.exceptionIndex = len(c.globals)
|
c.exceptionIndex = len(c.globals)
|
||||||
c.globals["<exception>"] = c.exceptionIndex
|
c.globals[exceptionVarName] = c.exceptionIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n, initLocals, deployLocals
|
return n, initLocals, deployLocals
|
||||||
|
|
|
@ -1296,7 +1296,9 @@ func (c *codegen) processDefers() {
|
||||||
c.setLabel(stmt.catchLabel)
|
c.setLabel(stmt.catchLabel)
|
||||||
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
||||||
emit.Int(c.prog.BinWriter, 1)
|
emit.Int(c.prog.BinWriter, 1)
|
||||||
c.emitStoreByIndex(varLocal, c.scope.finallyProcessedIndex)
|
|
||||||
|
finalIndex := c.getVarIndex("", finallyVarName).index
|
||||||
|
c.emitStoreByIndex(varLocal, finalIndex)
|
||||||
ast.Walk(c, stmt.expr)
|
ast.Walk(c, stmt.expr)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
// After panic, default values must be returns, except for named returns,
|
// After panic, default values must be returns, except for named returns,
|
||||||
|
@ -1309,12 +1311,12 @@ func (c *codegen) processDefers() {
|
||||||
|
|
||||||
c.setLabel(stmt.finallyLabel)
|
c.setLabel(stmt.finallyLabel)
|
||||||
before := c.newLabel()
|
before := c.newLabel()
|
||||||
c.emitLoadByIndex(varLocal, c.scope.finallyProcessedIndex)
|
c.emitLoadByIndex(varLocal, finalIndex)
|
||||||
emit.Jmp(c.prog.BinWriter, opcode.JMPIFL, before)
|
emit.Jmp(c.prog.BinWriter, opcode.JMPIFL, before)
|
||||||
ast.Walk(c, stmt.expr)
|
ast.Walk(c, stmt.expr)
|
||||||
c.setLabel(before)
|
c.setLabel(before)
|
||||||
emit.Int(c.prog.BinWriter, 0)
|
emit.Int(c.prog.BinWriter, 0)
|
||||||
c.emitStoreByIndex(varLocal, c.scope.finallyProcessedIndex)
|
c.emitStoreByIndex(varLocal, finalIndex)
|
||||||
emit.Opcodes(c.prog.BinWriter, opcode.ENDFINALLY)
|
emit.Opcodes(c.prog.BinWriter, opcode.ENDFINALLY)
|
||||||
c.setLabel(after)
|
c.setLabel(after)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,6 @@ type funcScope struct {
|
||||||
|
|
||||||
// deferStack is a stack containing encountered `defer` statements.
|
// deferStack is a stack containing encountered `defer` statements.
|
||||||
deferStack []deferInfo
|
deferStack []deferInfo
|
||||||
// finallyProcessed is a index of static slot with boolean flag determining
|
|
||||||
// if `defer` statement was already processed.
|
|
||||||
finallyProcessedIndex int
|
|
||||||
|
|
||||||
// Local variables
|
// Local variables
|
||||||
vars varScope
|
vars varScope
|
||||||
|
@ -59,6 +56,11 @@ type deferInfo struct {
|
||||||
expr *ast.CallExpr
|
expr *ast.CallExpr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
finallyVarName = "<finally>"
|
||||||
|
exceptionVarName = "<exception>"
|
||||||
|
)
|
||||||
|
|
||||||
func (c *codegen) newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
|
func (c *codegen) newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
|
||||||
var name string
|
var name string
|
||||||
if decl.Name != nil {
|
if decl.Name != nil {
|
||||||
|
@ -204,7 +206,6 @@ func (c *codegen) countLocalsInline(decl *ast.FuncDecl, pkg *types.Package, f *f
|
||||||
func (c *codegen) countLocalsWithDefer(f *funcScope) int {
|
func (c *codegen) countLocalsWithDefer(f *funcScope) int {
|
||||||
size, hasDefer := c.countLocals(f.decl)
|
size, hasDefer := c.countLocals(f.decl)
|
||||||
if hasDefer {
|
if hasDefer {
|
||||||
f.finallyProcessedIndex = size
|
|
||||||
size++
|
size++
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
|
|
Loading…
Reference in a new issue