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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $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
 
8
package main
9
 
10
func assertequal(is, shouldbe int, msg string) {
11
        if is != shouldbe {
12
                print("assertion fail", msg, "\n")
13
                panic(1)
14
        }
15
}
16
 
17
func f1() {
18
}
19
 
20
func f2(a int) {
21
}
22
 
23
func f3(a, b int) int {
24
        return a + b
25
}
26
 
27
func f4(a, b int, c float32) int {
28
        return (a+b)/2 + int(c)
29
}
30
 
31
func f5(a int) int {
32
        return 5
33
}
34
 
35
func f6(a int) (r int) {
36
        return 6
37
}
38
 
39
func f7(a int) (x int, y float32) {
40
        return 7, 7.0
41
}
42
 
43
 
44
func f8(a int) (x int, y float32) {
45
        return 8, 8.0
46
}
47
 
48
type T struct {
49
        x, y int
50
}
51
 
52
func (t *T) m10(a int, b float32) int {
53
        return (t.x + a) * (t.y + int(b))
54
}
55
 
56
 
57
func f9(a int) (i int, f float32) {
58
        i = 9
59
        f = 9.0
60
        return
61
}
62
 
63
 
64
func main() {
65
        f1()
66
        f2(1)
67
        r3 := f3(1, 2)
68
        assertequal(r3, 3, "3")
69
        r4 := f4(0, 2, 3.0)
70
        assertequal(r4, 4, "4")
71
        r5 := f5(1)
72
        assertequal(r5, 5, "5")
73
        r6 := f6(1)
74
        assertequal(r6, 6, "6")
75
        r7, s7 := f7(1)
76
        assertequal(r7, 7, "r7")
77
        assertequal(int(s7), 7, "s7")
78
        r8, s8 := f8(1)
79
        assertequal(r8, 8, "r8")
80
        assertequal(int(s8), 8, "s8")
81
        r9, s9 := f9(1)
82
        assertequal(r9, 9, "r9")
83
        assertequal(int(s9), 9, "s9")
84
        var t *T = new(T)
85
        t.x = 1
86
        t.y = 2
87
        r10 := t.m10(1, 3.0)
88
        assertequal(r10, 10, "10")
89
}

powered by: WebSVN 2.1.0

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