feat: add support for named output variables (#113)
* feat: add support for named output variables Function output parameters are located at the start of the function frame, uninitialized, as they could be only set through return statements. Supporting named output variables requires to: - identify and allocate symbols corresponding to output names: done at ident parsing, with the funcRet() helper, - compute the location of output name in the frame: done with retRank() helper, - initialize the frame entry with the zero value of symbol type, as the symbol can be accessed and written at multiple times, and return not setting the variable (opposite to unnamed). Done with frameType() helper, which now takes into account output parameters. * refactor: simplify memory management Perform function frame analysis at pre-order, instead of post-order, to initialize memory frame, and track value types. Remove all operation involving unitialized types. Frame memory layout is now build incrementally, instead of having to perform dedicated tree walks on AST.
This commit is contained in:
committed by
Ludovic Fernandez
parent
22a6d011f4
commit
6657e9a18b
20
_test/variadic3.go
Normal file
20
_test/variadic3.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func f(a ...int) int {
|
||||
fmt.Println(a)
|
||||
res := 0
|
||||
for _, v := range a {
|
||||
res += v
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(f(1, 2, 3, 4))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// [1 2 3 4]
|
||||
// 10
|
||||
Reference in New Issue
Block a user