]> Cypherpunks repositories - gostls13.git/commitdiff
- more go code
authorRobert Griesemer <gri@golang.org>
Sat, 12 Jul 2008 03:15:12 +0000 (20:15 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 12 Jul 2008 03:15:12 +0000 (20:15 -0700)
SVN=126934

usr/gri/gosrc/list.go [new file with mode: 0644]
usr/gri/gosrc/object.go
usr/gri/gosrc/type.go

diff --git a/usr/gri/gosrc/list.go b/usr/gri/gosrc/list.go
new file mode 100644 (file)
index 0000000..f72c04c
--- /dev/null
@@ -0,0 +1,93 @@
+// 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 List
+
+import Globals "globals"  // because of 6g warning
+import Object "object"
+import Type "type"
+
+
+// TODO This is hideous! We need to have a decent way to do lists.
+// Ideally open arrays that allow '+'.
+
+type Elem struct {
+       next *Elem;
+       str string;
+       obj *Object.Object;
+       typ *Type.Type;
+}
+
+
+export List
+type List struct {
+       len_ int;
+       first, last *Elem;
+};
+
+
+export NewList
+func NewList() *List {
+       return new(List);
+}
+
+
+func (L* List) len_() int {
+       return L.len_;
+}
+
+
+func (L *List) at(i int) *Elem {
+       if i < 0 || L.len_ <= i {
+               panic "index out of bounds";
+       }
+
+       p := L.first;
+       for ; i > 0; i-- {
+               p = p.next;
+       }
+       
+       return p;
+}
+
+
+func (L *List) Add() *Elem {
+       L.len_++;
+       e := new(Elem);
+       if L.first == nil {
+               L.first = e;
+       }
+       L.last.next = e;
+       L.last = e;
+}
+
+
+func (L *List) StrAt(i int) string {
+       return L.at(i).str;
+}
+
+
+func (L *List) ObjAt(i int) *Object.Object {
+       return L.at(i).obj;
+}
+
+
+func (L *List) TypAt(i int) *Type.Type {
+       return L.at(i).typ;
+}
+
+
+func (L *List) AddStr(str string) {
+       L.Add().str = str;
+}
+
+
+func (L *List) AddObj(obj *Object.Object) {
+       L.Add().obj = obj;
+}
+
+
+func (L *List) AddTyp(typ *Type.Type) {
+       L.Add().typ = typ;
+}
index cf1a432aaafd0b27814a9225c8bf3a2367c3205d..2e975e5dd8f8d6c37fdcaf8c516c1e4d168fb89f 100755 (executable)
@@ -15,9 +15,11 @@ const /* kind */ (
 )
 
 
+export Object
 type Object Globals.Object
 
 
+export NewObject
 func NewObject(kind int, name string) *Object {
        obj := new(Object);
        obj.mark = false;
index 975adec68fbe339bb503bc2b5c0e3e07c058829a..8b1fc75dd6670a8b6b193d1f1662193533670419 100644 (file)
@@ -24,9 +24,11 @@ const /* flag */ (
 )
 
 
+export Type
 type Type Globals.Type
 
 
+export NewType
 func NewType(form int) *Type {
        panic "UNIMPLEMENTED";
        return nil;