Source file test/abi/fibish_closure.go

     1  // run
     2  
     3  //go:build !wasm
     4  // +build !wasm
     5  
     6  // Copyright 2021 The Go Authors. All rights reserved.
     7  // Use of this source code is governed by a BSD-style
     8  // license that can be found in the LICENSE file.
     9  
    10  package main
    11  
    12  import "fmt"
    13  
    14  // Test that register results are correctly returned (and passed)
    15  
    16  type MagicLastTypeNameForTestingRegisterABI func(int, MagicLastTypeNameForTestingRegisterABI) (int, int)
    17  
    18  //go:noinline
    19  func f(x int, unused MagicLastTypeNameForTestingRegisterABI) (int, int) {
    20  
    21  	if x < 3 {
    22  		return 0, x
    23  	}
    24  
    25  	a, b := f(x-2, unused)
    26  	c, d := f(x-1, unused)
    27  	return a + d, b + c
    28  }
    29  
    30  func main() {
    31  	x := 40
    32  	a, b := f(x, f)
    33  	fmt.Printf("f(%d)=%d,%d\n", x, a, b)
    34  }
    35  

View as plain text