Source file
test/abi/uglyfib.go
1
2
3
4
5
6
7
8
9
10
11
12 package main
13
14 import "fmt"
15
16
17
18
19
20
21
22
23 func f(x int, xm1, xm2, p *int) {
24 var y = [2]int{x - 4, 0}
25 if x < 2 {
26 *p += x
27 return
28 }
29 x -= 3
30 g(*xm1, xm2, &x, p)
31 h(*xm2, &x, &y[0], p)
32 }
33
34
35
36 func g(x int, xm1, xm2, p *int) {
37 var y = [3]int{x - 4, 0, 0}
38 if x < 2 {
39 *p += x
40 return
41 }
42 x -= 3
43 k(*xm2, &x, &y[0], p)
44 h(*xm1, xm2, &x, p)
45 }
46
47
48
49 func h(x int, xm1, xm2, p *int) {
50 var y = [4]int{x - 4, 0, 0, 0}
51 if x < 2 {
52 *p += x
53 return
54 }
55 x -= 3
56 k(*xm1, xm2, &x, p)
57 f(*xm2, &x, &y[0], p)
58 }
59
60
61
62 func k(x int, xm1, xm2, p *int) {
63 var y = [5]int{x - 4, 0, 0, 0, 0}
64 if x < 2 {
65 *p += x
66 return
67 }
68 x -= 3
69 f(*xm2, &x, &y[0], p)
70 g(*xm1, xm2, &x, p)
71 }
72
73 func main() {
74 x := 40
75 var y int
76 xm1 := x - 1
77 xm2 := x - 2
78 f(x, &xm1, &xm2, &y)
79
80 fmt.Printf("Fib(%d)=%d\n", x, y)
81 }
82
View as plain text