compiler: support named returns
This commit is contained in:
parent
156a2eddc5
commit
b0a89e8a1a
3 changed files with 52 additions and 3 deletions
|
@ -421,9 +421,22 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
}
|
||||
c.dropItems(cnt)
|
||||
|
||||
// first result should be on top of the stack
|
||||
for i := len(n.Results) - 1; i >= 0; i-- {
|
||||
ast.Walk(c, n.Results[i])
|
||||
if len(n.Results) == 0 {
|
||||
results := c.scope.decl.Type.Results
|
||||
if results.NumFields() != 0 {
|
||||
// function with named returns
|
||||
for i := len(results.List) - 1; i >= 0; i-- {
|
||||
names := results.List[i].Names
|
||||
for j := len(names) - 1; j >= 0; j-- {
|
||||
c.emitLoadLocal(names[j].Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// first result should be on top of the stack
|
||||
for i := len(n.Results) - 1; i >= 0; i-- {
|
||||
ast.Walk(c, n.Results[i])
|
||||
}
|
||||
}
|
||||
|
||||
c.saveSequencePoint(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue