summaryrefslogtreecommitdiff
path: root/gcc/testsuite/go.test/test/ken/rob1.go
blob: 03350662a2e4120b15519bf4c76c8ec4f62eb9a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// $G $D/$F.go && $L $F.$A && ./$A.out

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

type Item interface {
	Print();
}

type ListItem struct {
	item    Item;
	next    *ListItem;
}

type List struct {
	head    *ListItem;
}

func (list *List) Init() {
	list.head = nil;
}

func (list *List) Insert(i Item) {
	item := new(ListItem);
	item.item = i;
	item.next = list.head;
	list.head = item;
}

func (list *List) Print() {
	i := list.head;
	for i != nil {
		i.item.Print();
		i = i.next;
	}
}

// Something to put in a list
type Integer struct {
	val		int;
}

func (this *Integer) Init(i int) *Integer {
	this.val = i;
	return this;
}

func (this *Integer) Print() {
	print(this.val);
}

func
main() {
	list := new(List);
	list.Init();
	for i := 0; i < 10; i = i + 1 {
		integer := new(Integer);
		integer.Init(i);
		list.Insert(integer);
	}

	list.Print();
	print("\n");
}