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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [rob1.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
type Item interface {
10
        Print() string
11
}
12
 
13
type ListItem struct {
14
        item Item
15
        next *ListItem
16
}
17
 
18
type List struct {
19
        head *ListItem
20
}
21
 
22
func (list *List) Init() {
23
        list.head = nil
24
}
25
 
26
func (list *List) Insert(i Item) {
27
        item := new(ListItem)
28
        item.item = i
29
        item.next = list.head
30
        list.head = item
31
}
32
 
33
func (list *List) Print() string {
34
        r := ""
35
        i := list.head
36
        for i != nil {
37
                r += i.item.Print()
38
                i = i.next
39
        }
40
        return r
41
}
42
 
43
// Something to put in a list
44
type Integer struct {
45
        val int
46
}
47
 
48
func (this *Integer) Init(i int) *Integer {
49
        this.val = i
50
        return this
51
}
52
 
53
func (this *Integer) Print() string {
54
        return string(this.val + '0')
55
}
56
 
57
func main() {
58
        list := new(List)
59
        list.Init()
60
        for i := 0; i < 10; i = i + 1 {
61
                integer := new(Integer)
62
                integer.Init(i)
63
                list.Insert(integer)
64
        }
65
 
66
        r := list.Print()
67
        if r != "9876543210" {
68
                panic(r)
69
        }
70
}

powered by: WebSVN 2.1.0

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