mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: drop stack after inline
Some control-flow statements drop stack items, for example `return` when it is used inside of `range` loop. For inlined calls this `return` should drop only portion of stack which belongs to inlined call.
This commit is contained in:
parent
347212c0c5
commit
b66b853285
4 changed files with 74 additions and 1 deletions
|
@ -49,6 +49,9 @@ type codegen struct {
|
|||
labels map[labelWithType]uint16
|
||||
// A list of nested label names together with evaluation stack depth.
|
||||
labelList []labelWithStackSize
|
||||
// inlineLabelOffsets contains size of labelList at the start of inline call processing.
|
||||
// For such calls we need to drop only newly created part of stack.
|
||||
inlineLabelOffsets []int
|
||||
|
||||
// A label for the for-loop being currently visited.
|
||||
currentFor string
|
||||
|
@ -607,7 +610,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
c.setLabel(l)
|
||||
|
||||
cnt := 0
|
||||
for i := range c.labelList {
|
||||
start := 0
|
||||
if len(c.inlineLabelOffsets) > 0 {
|
||||
start = c.inlineLabelOffsets[len(c.inlineLabelOffsets)-1]
|
||||
}
|
||||
for i := start; i < len(c.labelList); i++ {
|
||||
cnt += c.labelList[i].sz
|
||||
}
|
||||
c.dropItems(cnt)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue