From: Robert Griesemer Date: Sat, 12 Jul 2008 03:15:12 +0000 (-0700) Subject: - more go code X-Git-Tag: weekly.2009-11-06~3516 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5a81d1f29fad531a639379f78d0049638449b603;p=gostls13.git - more go code SVN=126934 --- diff --git a/usr/gri/gosrc/list.go b/usr/gri/gosrc/list.go new file mode 100644 index 0000000000..f72c04ca43 --- /dev/null +++ b/usr/gri/gosrc/list.go @@ -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; +} diff --git a/usr/gri/gosrc/object.go b/usr/gri/gosrc/object.go index cf1a432aaa..2e975e5dd8 100755 --- a/usr/gri/gosrc/object.go +++ b/usr/gri/gosrc/object.go @@ -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; diff --git a/usr/gri/gosrc/type.go b/usr/gri/gosrc/type.go index 975adec68f..8b1fc75dd6 100644 --- a/usr/gri/gosrc/type.go +++ b/usr/gri/gosrc/type.go @@ -24,9 +24,11 @@ const /* flag */ ( ) +export Type type Type Globals.Type +export NewType func NewType(form int) *Type { panic "UNIMPLEMENTED"; return nil;