mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 09:29:38 +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.
|
||||
if hasDefer {
|
||||
c.exceptionIndex = len(c.globals)
|
||||
c.globals["<exception>"] = c.exceptionIndex
|
||||
c.globals[exceptionVarName] = c.exceptionIndex
|
||||
}
|
||||
}
|
||||
return n, initLocals, deployLocals
|
||||
|
|
|
@ -1296,7 +1296,9 @@ func (c *codegen) processDefers() {
|
|||
c.setLabel(stmt.catchLabel)
|
||||
c.emitStoreByIndex(varGlobal, c.exceptionIndex)
|
||||
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)
|
||||
if i == 0 {
|
||||
// After panic, default values must be returns, except for named returns,
|
||||
|
@ -1309,12 +1311,12 @@ func (c *codegen) processDefers() {
|
|||
|
||||
c.setLabel(stmt.finallyLabel)
|
||||
before := c.newLabel()
|
||||
c.emitLoadByIndex(varLocal, c.scope.finallyProcessedIndex)
|
||||
c.emitLoadByIndex(varLocal, finalIndex)
|
||||
emit.Jmp(c.prog.BinWriter, opcode.JMPIFL, before)
|
||||
ast.Walk(c, stmt.expr)
|
||||
c.setLabel(before)
|
||||
emit.Int(c.prog.BinWriter, 0)
|
||||
c.emitStoreByIndex(varLocal, c.scope.finallyProcessedIndex)
|
||||
c.emitStoreByIndex(varLocal, finalIndex)
|
||||
emit.Opcodes(c.prog.BinWriter, opcode.ENDFINALLY)
|
||||
c.setLabel(after)
|
||||
}
|
||||
|
|
|
@ -34,9 +34,6 @@ type funcScope struct {
|
|||
|
||||
// deferStack is a stack containing encountered `defer` statements.
|
||||
deferStack []deferInfo
|
||||
// finallyProcessed is a index of static slot with boolean flag determining
|
||||
// if `defer` statement was already processed.
|
||||
finallyProcessedIndex int
|
||||
|
||||
// Local variables
|
||||
vars varScope
|
||||
|
@ -59,6 +56,11 @@ type deferInfo struct {
|
|||
expr *ast.CallExpr
|
||||
}
|
||||
|
||||
const (
|
||||
finallyVarName = "<finally>"
|
||||
exceptionVarName = "<exception>"
|
||||
)
|
||||
|
||||
func (c *codegen) newFuncScope(decl *ast.FuncDecl, label uint16) *funcScope {
|
||||
var name string
|
||||
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 {
|
||||
size, hasDefer := c.countLocals(f.decl)
|
||||
if hasDefer {
|
||||
f.finallyProcessedIndex = size
|
||||
size++
|
||||
}
|
||||
return size
|
||||
|
|
Loading…
Reference in a new issue