compiler: calculate stack size more precisely
When calculating number of local variables, only defining assignments (i.e. via `:=`) must be taken into account.
This commit is contained in:
parent
9b5dab57e8
commit
a43c9b9246
2 changed files with 21 additions and 1 deletions
|
@ -2,6 +2,7 @@ package compiler
|
|||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
)
|
||||
|
||||
// A funcScope represents the scope within the function context.
|
||||
|
@ -76,7 +77,9 @@ func (c *funcScope) stackSize() int64 {
|
|||
ast.Inspect(c.decl, func(n ast.Node) bool {
|
||||
switch n := n.(type) {
|
||||
case *ast.AssignStmt:
|
||||
size += len(n.Rhs)
|
||||
if n.Tok == token.DEFINE {
|
||||
size += len(n.Rhs)
|
||||
}
|
||||
case *ast.ReturnStmt, *ast.IfStmt:
|
||||
size++
|
||||
// This handles the inline GenDecl like "var x = 2"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue