OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [func5.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
func caller(f func(int, int) int, a, b int, c chan int) {
10
        c <- f(a, b)
11
}
12
 
13
func gocall(f func(int, int) int, a, b int) int {
14
        c := make(chan int)
15
        go caller(f, a, b, c)
16
        return <-c
17
}
18
 
19
func call(f func(int, int) int, a, b int) int {
20
        return f(a, b)
21
}
22
 
23
func call1(f func(int, int) int, a, b int) int {
24
        return call(f, a, b)
25
}
26
 
27
var f func(int, int) int
28
 
29
func add(x, y int) int {
30
        return x + y
31
}
32
 
33
func fn() func(int, int) int {
34
        return f
35
}
36
 
37
var fc func(int, int, chan int)
38
 
39
func addc(x, y int, c chan int) {
40
        c <- x+y
41
}
42
 
43
func fnc() func(int, int, chan int) {
44
        return fc
45
}
46
 
47
func three(x int) {
48
        if x != 3 {
49
                println("wrong val", x)
50
                panic("fail")
51
        }
52
}
53
 
54
var notmain func()
55
 
56
func emptyresults() {}
57
func noresults()    {}
58
 
59
var nothing func()
60
 
61
func main() {
62
        three(call(add, 1, 2))
63
        three(call1(add, 1, 2))
64
        f = add
65
        three(call(f, 1, 2))
66
        three(call1(f, 1, 2))
67
        three(call(fn(), 1, 2))
68
        three(call1(fn(), 1, 2))
69
        three(call(func(a, b int) int { return a + b }, 1, 2))
70
        three(call1(func(a, b int) int { return a + b }, 1, 2))
71
 
72
        fc = addc
73
        c := make(chan int)
74
        go addc(1, 2, c)
75
        three(<-c)
76
        go fc(1, 2, c)
77
        three(<-c)
78
        go fnc()(1, 2, c)
79
        three(<-c)
80
        go func(a, b int, c chan int) { c <- a+b }(1, 2, c)
81
        three(<-c)
82
 
83
        emptyresults()
84
        noresults()
85
        nothing = emptyresults
86
        nothing()
87
        nothing = noresults
88
        nothing()
89
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.