diff --git a/src/lib/http/request.go b/src/lib/http/request.go index b6c84461bc9..1335c48b428 100644 --- a/src/lib/http/request.go +++ b/src/lib/http/request.go @@ -190,7 +190,7 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) { } var f []string; - if f = strings.split(s, " "); len(f) != 3 { + if f = strings.Split(s, " "); len(f) != 3 { return nil, BadRequest } req.method, req.rawurl, req.proto = f[0], f[1], f[2]; diff --git a/src/lib/http/url.go b/src/lib/http/url.go index 7aac1f27e50..865b7864a29 100644 --- a/src/lib/http/url.go +++ b/src/lib/http/url.go @@ -156,7 +156,7 @@ export func ParseURL(rawurl string) (url *URL, err *os.Error) { } // If there's no @, split's default is wrong. Check explicitly. - if strings.index(url.authority, "@") < 0 { + if strings.Index(url.authority, "@") < 0 { url.host = url.authority; } else { url.userinfo, url.host = split(url.authority, '@', true); diff --git a/src/lib/io/io.go b/src/lib/io/io.go index 0a512e9e1a0..7c57f842f79 100644 --- a/src/lib/io/io.go +++ b/src/lib/io/io.go @@ -60,21 +60,21 @@ export func Readn(fd Read, buf []byte) (n int, err *os.Error) { // Convert something that implements Read into something // whose Reads are always Readn -type FullRead struct { +type _FullRead struct { fd Read; } -func (fd *FullRead) Read(p []byte) (n int, err *os.Error) { +func (fd *_FullRead) Read(p []byte) (n int, err *os.Error) { n, err = Readn(fd.fd, p); return n, err } -export func MakeFullReader(fd Read) Read { - if fr, ok := fd.(*FullRead); ok { - // already a FullRead +export func Make_FullReader(fd Read) Read { + if fr, ok := fd.(*_FullRead); ok { + // already a _FullRead return fd } - return &FullRead{fd} + return &_FullRead{fd} } // Copies n bytes (or until EOF is reached) from src to dst. diff --git a/src/lib/json/generic.go b/src/lib/json/generic.go index 1fef3fb1272..5333c83202c 100644 --- a/src/lib/json/generic.go +++ b/src/lib/json/generic.go @@ -131,7 +131,7 @@ func (j *_Map) String() string { export func Walk(j Json, path string) Json { for len(path) > 0 { var elem string; - if i := strings.index(path, "/"); i >= 0 { + if i := strings.Index(path, "/"); i >= 0 { elem = path[0:i]; path = path[i+1:len(path)]; } else { diff --git a/src/lib/malloc.go b/src/lib/malloc.go index 14d372b4f71..f10720b4cff 100644 --- a/src/lib/malloc.go +++ b/src/lib/malloc.go @@ -8,7 +8,7 @@ package malloc -type Stats struct { +export type Stats struct { alloc uint64; sys uint64; }; diff --git a/src/lib/net/dnsclient.go b/src/lib/net/dnsclient.go index 3622954401f..67af9b7524c 100644 --- a/src/lib/net/dnsclient.go +++ b/src/lib/net/dnsclient.go @@ -184,7 +184,7 @@ export func LookupHost(name string) (name1 string, addrs []string, err *os.Error // If name is rooted (trailing dot) or has enough dots, // try it by itself first. rooted := len(name) > 0 && name[len(name)-1] == '.'; - if rooted || strings.count(name, ".") >= cfg.ndots { + if rooted || strings.Count(name, ".") >= cfg.ndots { rname := name; if !rooted { rname += "."; diff --git a/src/lib/once.go b/src/lib/once.go index a086d772012..901fa4872af 100644 --- a/src/lib/once.go +++ b/src/lib/once.go @@ -11,30 +11,29 @@ package once -type Job struct { +type _Job struct { done bool; doit chan bool; // buffer of 1 } -type Request struct { +type _Request struct { f *(); - reply chan *Job + reply chan *_Job } -// TODO: Would like to use chan Request but 6g rejects it. -var service = make(chan *Request) -var jobmap = make(map[*()]*Job) +var service = make(chan _Request) +var jobmap = make(map[*()]*_Job) // Moderate access to the jobmap. // Even if accesses were thread-safe (they should be but are not) // something needs to serialize creation of new jobs. // That's what the Server does. -func Server() { +func server() { for { req := <-service; job, present := jobmap[req.f]; if !present { - job = new(Job); + job = new(_Job); job.doit = make(chan bool, 1); job.doit <- true; jobmap[req.f] = job @@ -48,13 +47,12 @@ export func Do(f *()) { // If not there, ask map server to make one. // TODO: Uncomment use of jobmap[f] once // maps are thread-safe. - var job *Job; + var job *_Job; var present bool; // job, present = jobmap[f] if !present { - c := make(chan *Job); - req := Request{f, c}; - service <- &req; + c := make(chan *_Job); + service <- _Request{f, c}; job = <-c } @@ -74,6 +72,6 @@ export func Do(f *()) { } func init() { - go Server() + go server() } diff --git a/src/lib/once_test.go b/src/lib/once_test.go index 21a889dd3cc..865c661da64 100644 --- a/src/lib/once_test.go +++ b/src/lib/once_test.go @@ -10,22 +10,22 @@ import ( ) var ncall int; -func Call() { +func call() { ncall++ } export func TestOnce(t *testing.T) { ncall = 0; - once.Do(&Call); + once.Do(&call); if ncall != 1 { - t.Fatalf("once.Do(&Call) didn't Call(): ncall=%d", ncall); + t.Fatalf("once.Do(&call) didn't call(): ncall=%d", ncall); } - once.Do(&Call); + once.Do(&call); if ncall != 1 { - t.Fatalf("second once.Do(&Call) did Call(): ncall=%d", ncall); + t.Fatalf("second once.Do(&call) did call(): ncall=%d", ncall); } - once.Do(&Call); + once.Do(&call); if ncall != 1 { - t.Fatalf("third once.Do(&Call) did Call(): ncall=%d", ncall); + t.Fatalf("third once.Do(&call) did call(): ncall=%d", ncall); } } diff --git a/src/lib/rand.go b/src/lib/rand.go index ebdfdf117f2..68f53c5e2b2 100644 --- a/src/lib/rand.go +++ b/src/lib/rand.go @@ -10,60 +10,54 @@ package rand -// rand, rand31, rand63 - return non-negative random int, int32, int64 +// rand, rand31, Int63 - return non-negative random int, int32, int64 // urand32 - return random uint32 -// nrand, nrand31, nrand63 - return 0 <= random < n +// nrand, nrand31, Int63n - return 0 <= random < n // frand, frand64, frand32 - return 0 <= random float, float64, float32 < 1 // perm gives a random permutation []int -const -( - LEN = 607; - TAP = 273; - MASK = (1<<63)-1; - A = 48271; - M = 2147483647; - Q = 44488; - R = 3399; +const ( + _LEN = 607; + _TAP = 273; + _MASK = (1<<63)-1; + _A = 48271; + _M = 2147483647; + _Q = 44488; + _R = 3399; ) -var -( - rng_cooked [LEN]int64; // cooked random numbers - rng_vec [LEN]int64; // current feedback register +var ( + rng_cooked [_LEN]int64; // cooked random numbers + rng_vec [_LEN]int64; // current feedback register rng_tap int; // index into vector rng_feed int; // index into vector ) -func -seedrand(x int32) int32 -{ +func seedrand(x int32) int32 { // seed rng x[n+1] = 48271 * x[n] mod (2**31 - 1) - hi := x / Q; - lo := x % Q; - x = A*lo - R*hi; + hi := x / _Q; + lo := x % _Q; + x = _A*lo - _R*hi; if x < 0 { - x += M; + x += _M; } return x; } -export func -srand(seed int32) -{ +export func Seed(seed int32) { rng_tap = 0; - rng_feed = LEN-TAP; + rng_feed = _LEN-_TAP; - seed = seed%M; + seed = seed%_M; if seed < 0 { - seed += M; + seed += _M; } if seed == 0 { seed = 89482311; } x := seed; - for i := -20; i < LEN; i++ { + for i := -20; i < _LEN; i++ { x = seedrand(x); if i >= 0 { var u int64; @@ -73,105 +67,84 @@ srand(seed int32) x = seedrand(x); u ^= int64(x); u ^= rng_cooked[i]; - rng_vec[i] = u & MASK; + rng_vec[i] = u & _MASK; } } } -export func -rand63() int64 -{ +export func Int63() int64 { rng_tap--; if rng_tap < 0 { - rng_tap += LEN; + rng_tap += _LEN; } rng_feed--; if rng_feed < 0 { - rng_feed += LEN; + rng_feed += _LEN; } - x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & MASK; + x := (rng_vec[rng_feed] + rng_vec[rng_tap]) & _MASK; rng_vec[rng_feed] = x; return x; } -export func -urand32() uint32 -{ - return uint32(rand63() >> 31); +export func Uint32() uint32 { + return uint32(Int63() >> 31); } -export func -rand31() int32 -{ - return int32(rand63() >> 32); +export func Int31() int32 { + return int32(Int63() >> 32); } -export func -rand() int -{ - u := uint(rand63()); +export func Int() int { + u := uint(Int63()); return int(u << 1 >> 1); // clear sign bit if int == int32 } -export func -nrand63(n int64) int64 -{ +export func Int63n(n int64) int64 { if n <= 0 { return 0 } max := int64((1<<63)-1 - (1<<63) % uint64(n)); - v := rand63(); + v := Int63(); for v > max { - v = rand63() + v = Int63() } return v % n } -export func -nrand31(n int32) int32 -{ - return int32(nrand63(int64(n))) +export func Int31n(n int32) int32 { + return int32(Int63n(int64(n))) } -export func -nrand(n int) int -{ - return int(nrand63(int64(n))) +export func Intn(n int) int { + return int(Int63n(int64(n))) } -export func -frand64() float64 -{ - x := float64(rand63()) / float64(MASK); +export func Float64() float64 { + x := float64(Int63()) / float64(_MASK); for x >= 1 { - x = float64(rand63()) / float64(MASK); + x = float64(Int63()) / float64(_MASK); } return x; } -export func -frand32() float32 -{ - return float32(frand64()) +export func Float32() float32 { + return float32(Float64()) } -export func -frand() float +export func Float() float { - return float(frand64()) + return float(Float64()) } -export func -perm(n int) []int -{ +export func Perm(n int) []int { m := make([]int, n); for i:=0; i>6); - p[1] = Tx | byte(rune)&Maskx; + if rune <= _Rune2Max { + p[0] = _T2 | byte(rune>>6); + p[1] = _Tx | byte(rune)&_Maskx; return 2; } @@ -233,17 +233,17 @@ export func EncodeRune(rune int, p []byte) int { rune = RuneError } - if rune <= Rune3Max { - p[0] = T3 | byte(rune>>12); - p[1] = Tx | byte(rune>>6)&Maskx; - p[2] = Tx | byte(rune)&Maskx; + if rune <= _Rune3Max { + p[0] = _T3 | byte(rune>>12); + p[1] = _Tx | byte(rune>>6)&_Maskx; + p[2] = _Tx | byte(rune)&_Maskx; return 3; } - p[0] = T4 | byte(rune>>18); - p[1] = Tx | byte(rune>>12)&Maskx; - p[2] = Tx | byte(rune>>6)&Maskx; - p[3] = Tx | byte(rune)&Maskx; + p[0] = _T4 | byte(rune>>18); + p[1] = _Tx | byte(rune>>12)&_Maskx; + p[2] = _Tx | byte(rune>>6)&_Maskx; + p[3] = _Tx | byte(rune)&_Maskx; return 4; } @@ -268,7 +268,7 @@ export func RuneCountInString(s string, i int, l int) int { if s[i] < RuneSelf { i++; } else { - rune, size, short := DecodeRuneInStringInternal(s, i, ei - i); + rune, size, short := decodeRuneInStringInternal(s, i, ei - i); i += size; } } diff --git a/src/lib/utf8_test.go b/src/lib/utf8_test.go index aebd3356583..0456649fdac 100644 --- a/src/lib/utf8_test.go +++ b/src/lib/utf8_test.go @@ -11,7 +11,7 @@ import ( "utf8"; ) -type Utf8Map struct { +export type Utf8Map struct { rune int; str string; } @@ -44,10 +44,11 @@ var utf8map = []Utf8Map { Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" }, } -func Bytes(s string) []byte { +// like io.StringBytes but leaves one extra byte at end +func bytes(s string) []byte { b := make([]byte, len(s)+1); if !syscall.StringToBytes(b, s) { - panic("StringToBytes failed"); + panic("StringTobytes failed"); } return b[0:len(s)]; } @@ -55,7 +56,7 @@ func Bytes(s string) []byte { export func TestFullRune(t *testing.T) { for i := 0; i < len(utf8map); i++ { m := utf8map[i]; - b := Bytes(m.str); + b := bytes(m.str); if !utf8.FullRune(b) { t.Errorf("FullRune(%q) (rune %04x) = false, want true", b, m.rune); } @@ -74,7 +75,7 @@ export func TestFullRune(t *testing.T) { } } -func EqualBytes(a, b []byte) bool { +func equalBytes(a, b []byte) bool { if len(a) != len(b) { return false; } @@ -89,11 +90,11 @@ func EqualBytes(a, b []byte) bool { export func TestEncodeRune(t *testing.T) { for i := 0; i < len(utf8map); i++ { m := utf8map[i]; - b := Bytes(m.str); + b := bytes(m.str); var buf [10]byte; n := utf8.EncodeRune(m.rune, buf); b1 := buf[0:n]; - if !EqualBytes(b, b1) { + if !equalBytes(b, b1) { t.Errorf("EncodeRune(0x%04x) = %q want %q", m.rune, b1, b); } } @@ -102,7 +103,7 @@ export func TestEncodeRune(t *testing.T) { export func TestDecodeRune(t *testing.T) { for i := 0; i < len(utf8map); i++ { m := utf8map[i]; - b := Bytes(m.str); + b := bytes(m.str); rune, size := utf8.DecodeRune(b); if rune != m.rune || size != len(b) { t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b)); @@ -113,7 +114,7 @@ export func TestDecodeRune(t *testing.T) { t.Errorf("DecodeRune(%q, 2) = 0x%04x, %d want 0x%04x, %d", s, rune, size, m.rune, len(b)); } - // there's an extra byte that Bytes left behind - make sure trailing byte works + // there's an extra byte that bytes left behind - make sure trailing byte works rune, size = utf8.DecodeRune(b[0:cap(b)]); if rune != m.rune || size != len(b) { t.Errorf("DecodeRune(%q) = 0x%04x, %d want 0x%04x, %d", b, rune, size, m.rune, len(b)); @@ -157,7 +158,7 @@ export func TestDecodeRune(t *testing.T) { } } -type RuneCountTest struct { +export type RuneCountTest struct { in string; out int; } @@ -173,7 +174,7 @@ export func TestRuneCount(t *testing.T) { if out := utf8.RuneCountInString(tt.in, 0, len(tt.in)); out != tt.out { t.Errorf("RuneCountInString(%q) = %d, want %d", tt.in, out, tt.out); } - if out := utf8.RuneCount(Bytes(tt.in)); out != tt.out { + if out := utf8.RuneCount(bytes(tt.in)); out != tt.out { t.Errorf("RuneCount(%q) = %d, want %d", tt.in, out, tt.out); } }