1
0
mirror of https://github.com/golang/go synced 2024-11-22 06:04:39 -07:00

apply gofmt to the LGTM-marked files from 34501

that have not changed since I applied gofmt.

R=gri
DELTA=456  (77 added, 3 deleted, 376 changed)
OCL=35378
CL=35383
This commit is contained in:
Russ Cox 2009-10-06 11:42:55 -07:00
parent 9d9a421e24
commit c62b3265a7
28 changed files with 447 additions and 373 deletions

View File

@ -21,12 +21,12 @@ func main() {
var s string = ""; var s string = "";
for i := 0; i < flag.NArg(); i++ { for i := 0; i < flag.NArg(); i++ {
if i > 0 { if i > 0 {
s += kSpace s += kSpace;
} }
s += flag.Arg(i) s += flag.Arg(i);
} }
if !*n_flag { if !*n_flag {
s += kNewline s += kNewline;
} }
os.Stdout.WriteString(s); os.Stdout.WriteString(s);
} }

View File

@ -16,9 +16,9 @@ type File struct {
func newFile(fd int, name string) *File { func newFile(fd int, name string) *File {
if fd < 0 { if fd < 0 {
return nil return nil;
} }
return &File{fd, name} return &File{fd, name};
} }
var ( var (
@ -32,43 +32,43 @@ func Open(name string, mode int, perm int) (file *File, err os.Error) {
if e != 0 { if e != 0 {
err = os.Errno(e); err = os.Errno(e);
} }
return newFile(r, name), err return newFile(r, name), err;
} }
func (file *File) Close() os.Error { func (file *File) Close() os.Error {
if file == nil { if file == nil {
return os.EINVAL return os.EINVAL;
} }
e := syscall.Close(file.fd); e := syscall.Close(file.fd);
file.fd = -1; // so it can't be closed again file.fd = -1; // so it can't be closed again
if e != 0 { if e != 0 {
return os.Errno(e); return os.Errno(e);
} }
return nil return nil;
} }
func (file *File) Read(b []byte) (ret int, err os.Error) { func (file *File) Read(b []byte) (ret int, err os.Error) {
if file == nil { if file == nil {
return -1, os.EINVAL return -1, os.EINVAL;
} }
r, e := syscall.Read(file.fd, b); r, e := syscall.Read(file.fd, b);
if e != 0 { if e != 0 {
err = os.Errno(e); err = os.Errno(e);
} }
return int(r), err return int(r), err;
} }
func (file *File) Write(b []byte) (ret int, err os.Error) { func (file *File) Write(b []byte) (ret int, err os.Error) {
if file == nil { if file == nil {
return -1, os.EINVAL return -1, os.EINVAL;
} }
r, e := syscall.Write(file.fd, b); r, e := syscall.Write(file.fd, b);
if e != 0 { if e != 0 {
err = os.Errno(e); err = os.Errno(e);
} }
return int(r), err return int(r), err;
} }
func (file *File) String() string { func (file *File) String() string {
return file.name return file.name;
} }

View File

@ -11,7 +11,10 @@ func main() {
fmt.Printf("%d %d\n", u64, int64(u64)); fmt.Printf("%d %d\n", u64, int64(u64));
// harder stuff // harder stuff
type T struct { a int; b string }; type T struct {
a int;
b string;
}
t := T{77, "Sunset Strip"}; t := T{77, "Sunset Strip"};
a := []int{1, 2, 3, 4}; a := []int{1, 2, 3, 4};
fmt.Printf("%v %v %v\n", u64, t, a); fmt.Printf("%v %v %v\n", u64, t, a);

View File

@ -6,13 +6,16 @@ package main
import "fmt" import "fmt"
type testType struct { a int; b string } type testType struct {
a int;
b string;
}
func (t *testType) String() string { func (t *testType) String() string {
return fmt.Sprint(t.a) + " " + t.b return fmt.Sprint(t.a) + " " + t.b;
} }
func main() { func main() {
t := &testType{77, "Sunset Strip"}; t := &testType{77, "Sunset Strip"};
fmt.Println(t) fmt.Println(t);
} }

View File

@ -9,7 +9,7 @@ import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'. // Send the sequence 2, 3, 4, ... to channel 'ch'.
func generate(ch chan int) { func generate(ch chan int) {
for i := 2; ; i++ { for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'. ch <- i; // Send 'i' to channel 'ch'.
} }
} }
@ -19,7 +19,7 @@ func filter(in, out chan int, prime int) {
for { for {
i := <-in; // Receive value of new variable 'i' from 'in'. i := <-in; // Receive value of new variable 'i' from 'in'.
if i%prime != 0 { if i%prime != 0 {
out <- i // Send 'i' to channel 'out'. out <- i; // Send 'i' to channel 'out'.
} }
} }
} }
@ -33,6 +33,6 @@ func main() {
fmt.Println(prime); fmt.Println(prime);
ch1 := make(chan int); ch1 := make(chan int);
go filter(ch, ch1, prime); go filter(ch, ch1, prime);
ch = ch1 ch = ch1;
} }
} }

View File

@ -11,7 +11,7 @@ func generate() chan int {
ch := make(chan int); ch := make(chan int);
go func() { go func() {
for i := 2; ; i++ { for i := 2; ; i++ {
ch <- i ch <- i;
} }
}(); }();
return ch; return ch;
@ -23,7 +23,7 @@ func filter(in chan int, prime int) chan int {
go func() { go func() {
for { for {
if i := <-in; i%prime != 0 { if i := <-in; i%prime != 0 {
out <- i out <- i;
} }
} }
}(); }();

View File

@ -32,32 +32,62 @@ func IsSorted(data SortInterface) bool {
type IntArray []int type IntArray []int
func (p IntArray) Len() int { return len(p); } func (p IntArray) Len() int {
func (p IntArray) Less(i, j int) bool { return p[i] < p[j]; } return len(p);
func (p IntArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; } }
func (p IntArray) Less(i, j int) bool {
return p[i] < p[j];
}
func (p IntArray) Swap(i, j int) {
p[i], p[j] = p[j], p[i];
}
type FloatArray []float type FloatArray []float
func (p FloatArray) Len() int { return len(p); } func (p FloatArray) Len() int {
func (p FloatArray) Less(i, j int) bool { return p[i] < p[j]; } return len(p);
func (p FloatArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; } }
func (p FloatArray) Less(i, j int) bool {
return p[i] < p[j];
}
func (p FloatArray) Swap(i, j int) {
p[i], p[j] = p[j], p[i];
}
type StringArray []string type StringArray []string
func (p StringArray) Len() int { return len(p); } func (p StringArray) Len() int {
func (p StringArray) Less(i, j int) bool { return p[i] < p[j]; } return len(p);
func (p StringArray) Swap(i, j int) { p[i], p[j] = p[j], p[i]; } }
func (p StringArray) Less(i, j int) bool {
return p[i] < p[j];
}
func (p StringArray) Swap(i, j int) {
p[i], p[j] = p[j], p[i];
}
// Convenience wrappers for common cases // Convenience wrappers for common cases
func SortInts(a []int) { Sort(IntArray(a)); } func SortInts(a []int) {
func SortFloats(a []float) { Sort(FloatArray(a)); } Sort(IntArray(a));
func SortStrings(a []string) { Sort(StringArray(a)); } }
func SortFloats(a []float) {
Sort(FloatArray(a));
}
func SortStrings(a []string) {
Sort(StringArray(a));
}
func IntsAreSorted(a []int) bool { return IsSorted(IntArray(a)); } func IntsAreSorted(a []int) bool {
func FloatsAreSorted(a []float) bool { return IsSorted(FloatArray(a)); } return IsSorted(IntArray(a));
func StringsAreSorted(a []string) bool { return IsSorted(StringArray(a)); } }
func FloatsAreSorted(a []float) bool {
return IsSorted(FloatArray(a));
}
func StringsAreSorted(a []string) bool {
return IsSorted(StringArray(a));
}

View File

@ -14,7 +14,7 @@ func ints() {
a := sort.IntArray(data); a := sort.IntArray(data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
panic() panic();
} }
} }
@ -23,7 +23,7 @@ func strings() {
a := sort.StringArray(data); a := sort.StringArray(data);
sort.Sort(a); sort.Sort(a);
if !sort.IsSorted(a) { if !sort.IsSorted(a) {
panic() panic();
} }
} }
@ -37,9 +37,15 @@ type dayArray struct {
data []*day; data []*day;
} }
func (p *dayArray) Len() int { return len(p.data); } func (p *dayArray) Len() int {
func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num; } return len(p.data);
func (p *dayArray) Swap(i, j int) { p.data[i], p.data[j] = p.data[j], p.data[i]; } }
func (p *dayArray) Less(i, j int) bool {
return p.data[i].num < p.data[j].num;
}
func (p *dayArray) Swap(i, j int) {
p.data[i], p.data[j] = p.data[j], p.data[i];
}
func days() { func days() {
Sunday := day{0, "SUN", "Sunday"}; Sunday := day{0, "SUN", "Sunday"};
@ -53,12 +59,12 @@ func days() {
a := dayArray{data}; a := dayArray{data};
sort.Sort(&a); sort.Sort(&a);
if !sort.IsSorted(&a) { if !sort.IsSorted(&a) {
panic() panic();
} }
for _, d := range data { for _, d := range data {
fmt.Printf("%s ", d.long_name) fmt.Printf("%s ", d.long_name);
} }
fmt.Printf("\n") fmt.Printf("\n");
} }

View File

@ -9,7 +9,9 @@ import "os"
func main() { func main() {
s := "hello"; s := "hello";
if s[1] != 'e' { os.Exit(1) } if s[1] != 'e' {
os.Exit(1);
}
s = "good bye"; s = "good bye";
var p *string = &s; var p *string = &s;
*p = "ciao"; *p = "ciao";

View File

@ -9,9 +9,9 @@ import "fmt"
func sum(a []int) int { // returns an int func sum(a []int) int { // returns an int
s := 0; s := 0;
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
s += a[i] s += a[i];
} }
return s return s;
} }

View File

@ -143,7 +143,7 @@ func walk(x interface{}, p *Prog, context string) {
p.Crefs[i] = &Cref{ p.Crefs[i] = &Cref{
Name: sel.Sel.Value, Name: sel.Sel.Value,
Expr: n, Expr: n,
Context: context Context: context,
}; };
break; break;
} }
@ -321,4 +321,3 @@ func walk(x interface{}, p *Prog, context string) {
} }
} }
} }

View File

@ -23,7 +23,7 @@ func usage() {
var ptrSizeMap = map[string]int64{ var ptrSizeMap = map[string]int64{
"386": 4, "386": 4,
"amd64": 8, "amd64": 8,
"arm": 4 "arm": 4,
} }
var expandName = map[string]string{ var expandName = map[string]string{

View File

@ -218,4 +218,3 @@ void
FLUSH(&p); FLUSH(&p);
} }
` `

View File

@ -93,4 +93,3 @@ func error(pos token.Position, msg string, args ...) {
fmt.Fprintf(os.Stderr, msg, args); fmt.Fprintf(os.Stderr, msg, args);
fmt.Fprintf(os.Stderr, "\n"); fmt.Fprintf(os.Stderr, "\n");
} }

View File

@ -17,7 +17,7 @@ import (
) )
var start = flag.String("start", "Start", "name of start production"); var start = flag.String("start", "Start", "name of start production")
func usage() { func usage() {

View File

@ -6,83 +6,83 @@ package PACKAGE
// emitted by compiler, not referred to by go programs // emitted by compiler, not referred to by go programs
func mal(int32) *any; func mal(int32) *any
func throwindex(); func throwindex()
func throwreturn(); func throwreturn()
func throwinit(); func throwinit()
func panicl(); func panicl()
func printbool(bool); func printbool(bool)
func printfloat(float64); func printfloat(float64)
func printint(int64); func printint(int64)
func printuint(uint64); func printuint(uint64)
func printstring(string); func printstring(string)
func printpointer(any); func printpointer(any)
func printiface(any); func printiface(any)
func printeface(any); func printeface(any)
func printslice(any); func printslice(any)
func printnl(); func printnl()
func printsp(); func printsp()
func catstring(string, string) string; func catstring(string, string) string
func cmpstring(string, string) int; func cmpstring(string, string) int
func slicestring(string, int, int) string; func slicestring(string, int, int) string
func indexstring(string, int) byte; func indexstring(string, int) byte
func intstring(int64) string; func intstring(int64) string
func slicebytetostring([]byte) string; func slicebytetostring([]byte) string
func sliceinttostring([]int) string; func sliceinttostring([]int) string
func stringiter(string, int) int; func stringiter(string, int) int
func stringiter2(string, int) (retk int, retv int); func stringiter2(string, int) (retk int, retv int)
func ifaceI2E(iface any) (ret any); func ifaceI2E(iface any) (ret any)
func ifaceE2I(typ *byte, iface any) (ret any); func ifaceE2I(typ *byte, iface any) (ret any)
func ifaceT2E(typ *byte, elem any) (ret any); func ifaceT2E(typ *byte, elem any) (ret any)
func ifaceE2T(typ *byte, elem any) (ret any); func ifaceE2T(typ *byte, elem any) (ret any)
func ifaceE2I2(typ *byte, iface any) (ret any, ok bool); func ifaceE2I2(typ *byte, iface any) (ret any, ok bool)
func ifaceE2T2(typ *byte, elem any) (ret any, ok bool); func ifaceE2T2(typ *byte, elem any) (ret any, ok bool)
func ifaceT2I(typ1 *byte, typ2 *byte, elem any) (ret any); func ifaceT2I(typ1 *byte, typ2 *byte, elem any) (ret any)
func ifaceI2T(typ *byte, iface any) (ret any); func ifaceI2T(typ *byte, iface any) (ret any)
func ifaceI2T2(typ *byte, iface any) (ret any, ok bool); func ifaceI2T2(typ *byte, iface any) (ret any, ok bool)
func ifaceI2I(typ *byte, iface any) (ret any); func ifaceI2I(typ *byte, iface any) (ret any)
func ifaceI2Ix(typ *byte, iface any) (ret any); func ifaceI2Ix(typ *byte, iface any) (ret any)
func ifaceI2I2(typ *byte, iface any) (ret any, ok bool); func ifaceI2I2(typ *byte, iface any) (ret any, ok bool)
func ifaceeq(i1 any, i2 any) (ret bool); func ifaceeq(i1 any, i2 any) (ret bool)
func efaceeq(i1 any, i2 any) (ret bool); func efaceeq(i1 any, i2 any) (ret bool)
func ifacethash(i1 any) (ret uint32); func ifacethash(i1 any) (ret uint32)
func efacethash(i1 any) (ret uint32); func efacethash(i1 any) (ret uint32)
// *byte is really *runtime.Type // *byte is really *runtime.Type
func makemap(key, val *byte, hint int) (hmap map[any]any); func makemap(key, val *byte, hint int) (hmap map[any]any)
func mapaccess1(hmap map[any]any, key any) (val any); func mapaccess1(hmap map[any]any, key any) (val any)
func mapaccess2(hmap map[any]any, key any) (val any, pres bool); func mapaccess2(hmap map[any]any, key any) (val any, pres bool)
func mapassign1(hmap map[any]any, key any, val any); func mapassign1(hmap map[any]any, key any, val any)
func mapassign2(hmap map[any]any, key any, val any, pres bool); func mapassign2(hmap map[any]any, key any, val any, pres bool)
func mapiterinit(hmap map[any]any, hiter *any); func mapiterinit(hmap map[any]any, hiter *any)
func mapiternext(hiter *any); func mapiternext(hiter *any)
func mapiter1(hiter *any) (key any); func mapiter1(hiter *any) (key any)
func mapiter2(hiter *any) (key any, val any); func mapiter2(hiter *any) (key any, val any)
// *byte is really *runtime.Type // *byte is really *runtime.Type
func makechan(elem *byte, hint int) (hchan chan any); func makechan(elem *byte, hint int) (hchan chan any)
func chanrecv1(hchan <-chan any) (elem any); func chanrecv1(hchan <-chan any) (elem any)
func chanrecv2(hchan <-chan any) (elem any, pres bool); func chanrecv2(hchan <-chan any) (elem any, pres bool)
func chansend1(hchan chan<- any, elem any); func chansend1(hchan chan<- any, elem any)
func chansend2(hchan chan<- any, elem any) (pres bool); func chansend2(hchan chan<- any, elem any) (pres bool)
func closechan(hchan any); func closechan(hchan any)
func closedchan(hchan any) bool; func closedchan(hchan any) bool
func newselect(size int) (sel *byte); func newselect(size int) (sel *byte)
func selectsend(sel *byte, hchan chan<- any, elem any) (selected bool); func selectsend(sel *byte, hchan chan<- any, elem any) (selected bool)
func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool); func selectrecv(sel *byte, hchan <-chan any, elem *any) (selected bool)
func selectdefault(sel *byte) (selected bool); func selectdefault(sel *byte) (selected bool)
func selectgo(sel *byte); func selectgo(sel *byte)
func makeslice(nel int, cap int, width int) (ary []any); func makeslice(nel int, cap int, width int) (ary []any)
func sliceslice(old []any, lb int, hb int, width int) (ary []any); func sliceslice(old []any, lb int, hb int, width int) (ary []any)
func slicearray(old *any, nel int, lb int, hb int, width int) (ary []any); func slicearray(old *any, nel int, lb int, hb int, width int) (ary []any)
func arraytoslice(old *any, nel int) (ary []any); func arraytoslice(old *any, nel int) (ary []any)
func closure(); // has args, but compiler fills in func closure() // has args, but compiler fills in
// only used on 32-bit // only used on 32-bit
func int64div(int64, int64) int64 func int64div(int64, int64) int64

View File

@ -4,10 +4,10 @@
package PACKAGE package PACKAGE
type Pointer *any; type Pointer *any
func Offsetof(any) int; func Offsetof(any) int
func Sizeof(any) int; func Sizeof(any) int
func Alignof(any) int; func Alignof(any) int
func Typeof(i interface { }) (typ interface{}); func Typeof(i interface{}) (typ interface{})
func Reflect(i interface { }) (typ interface{}, addr Pointer); func Reflect(i interface{}) (typ interface{}, addr Pointer)
func Unreflect(typ interface{}, addr Pointer) (ret interface { }); func Unreflect(typ interface{}, addr Pointer) (ret interface{})

View File

@ -17,7 +17,7 @@ import (
) )
const pkgDir = "src/pkg"; // relative to $GOROOT const pkgDir = "src/pkg" // relative to $GOROOT
var ( var (

View File

@ -47,7 +47,7 @@ type Header struct {
Ctime int64; Ctime int64;
} }
var zeroBlock = make([]byte, blockSize); var zeroBlock = make([]byte, blockSize)
// POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values. // POSIX specifies a sum of the unsigned byte values, but the Sun tar uses signed byte values.
// We compute and return both. // We compute and return both.
@ -58,17 +58,17 @@ func checksum(header []byte) (unsigned int64, signed int64) {
unsigned += ' '*8; unsigned += ' '*8;
signed += ' '*8; signed += ' '*8;
i += 7; i += 7;
continue continue;
} }
unsigned += int64(header[i]); unsigned += int64(header[i]);
signed += int64(int8(header[i])); signed += int64(int8(header[i]));
} }
return return;
} }
type slicer []byte type slicer []byte
func (sp *slicer) next(n int) (b []byte) { func (sp *slicer) next(n int) (b []byte) {
s := *sp; s := *sp;
b, *sp = s[0:n], s[n:len(s)]; b, *sp = s[0:n], s[n:len(s)];
return return;
} }

View File

@ -45,7 +45,7 @@ type Reader struct {
// NewReader creates a new Reader reading from r. // NewReader creates a new Reader reading from r.
func NewReader(r io.Reader) *Reader { func NewReader(r io.Reader) *Reader {
return &Reader{ r: r } return &Reader{r: r};
} }
// Next advances to the next entry in the tar archive. // Next advances to the next entry in the tar archive.
@ -57,7 +57,7 @@ func (tr *Reader) Next() (*Header, os.Error) {
if tr.err == nil { if tr.err == nil {
hdr = tr.readHeader(); hdr = tr.readHeader();
} }
return hdr, tr.err return hdr, tr.err;
} }
// Parse bytes as a NUL-terminated C-style string. // Parse bytes as a NUL-terminated C-style string.
@ -67,7 +67,7 @@ func cString(b []byte) string {
for n < len(b) && b[n] != 0 { for n < len(b) && b[n] != 0 {
n++; n++;
} }
return string(b[0:n]) return string(b[0:n]);
} }
func (tr *Reader) octal(b []byte) int64 { func (tr *Reader) octal(b []byte) int64 {
@ -83,12 +83,12 @@ func (tr *Reader) octal(b []byte) int64 {
if err != nil { if err != nil {
tr.err = err; tr.err = err;
} }
return int64(x) return int64(x);
} }
type ignoreWriter struct{} type ignoreWriter struct{}
func (ignoreWriter) Write(b []byte) (n int, err os.Error) { func (ignoreWriter) Write(b []byte) (n int, err os.Error) {
return len(b), nil return len(b), nil;
} }
// Skip any unread bytes in the existing file entry, as well as any alignment padding. // Skip any unread bytes in the existing file entry, as well as any alignment padding.
@ -105,34 +105,34 @@ func (tr *Reader) skipUnread() {
func (tr *Reader) verifyChecksum(header []byte) bool { func (tr *Reader) verifyChecksum(header []byte) bool {
if tr.err != nil { if tr.err != nil {
return false return false;
} }
given := tr.octal(header[148:156]); given := tr.octal(header[148:156]);
unsigned, signed := checksum(header); unsigned, signed := checksum(header);
return given == unsigned || given == signed return given == unsigned || given == signed;
} }
func (tr *Reader) readHeader() *Header { func (tr *Reader) readHeader() *Header {
header := make([]byte, blockSize); header := make([]byte, blockSize);
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil { if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil return nil;
} }
// Two blocks of zero bytes marks the end of the archive. // Two blocks of zero bytes marks the end of the archive.
if bytes.Equal(header, zeroBlock[0:blockSize]) { if bytes.Equal(header, zeroBlock[0:blockSize]) {
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil { if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil return nil;
} }
if !bytes.Equal(header, zeroBlock[0:blockSize]) { if !bytes.Equal(header, zeroBlock[0:blockSize]) {
tr.err = HeaderError; tr.err = HeaderError;
} }
return nil return nil;
} }
if !tr.verifyChecksum(header) { if !tr.verifyChecksum(header) {
tr.err = HeaderError; tr.err = HeaderError;
return nil return nil;
} }
// Unpack // Unpack
@ -191,7 +191,7 @@ func (tr *Reader) readHeader() *Header {
if tr.err != nil { if tr.err != nil {
tr.err = HeaderError; tr.err = HeaderError;
return nil return nil;
} }
// Maximum value of hdr.Size is 64 GB (12 octal digits), // Maximum value of hdr.Size is 64 GB (12 octal digits),
@ -199,7 +199,7 @@ func (tr *Reader) readHeader() *Header {
tr.nb = int64(hdr.Size); tr.nb = int64(hdr.Size);
tr.pad = -tr.nb & (blockSize-1); // blockSize is a power of two tr.pad = -tr.nb & (blockSize-1); // blockSize is a power of two
return hdr return hdr;
} }
// Read reads from the current entry in the tar archive. // Read reads from the current entry in the tar archive.
@ -212,5 +212,5 @@ func (tr *Reader) Read(b []uint8) (n int, err os.Error) {
n, err = tr.r.Read(b); n, err = tr.r.Read(b);
tr.nb -= int64(n); tr.nb -= int64(n);
tr.err = err; tr.err = err;
return return;
} }

View File

@ -45,7 +45,7 @@ var pairs = []testpair {
var bigtest = testpair{ var bigtest = testpair{
"Twas brillig, and the slithy toves", "Twas brillig, and the slithy toves",
"VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==" "VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==",
} }
func testEqual(t *testing.T, msg string, args ...) bool { func testEqual(t *testing.T, msg string, args ...) bool {
@ -145,7 +145,7 @@ func TestDecodeCorrupt(t *testing.T) {
type corrupt struct { type corrupt struct {
e string; e string;
p int; p int;
}; }
examples := []corrupt{ examples := []corrupt{
corrupt{"!!!!", 0}, corrupt{"!!!!", 0},
corrupt{"x===", 1}, corrupt{"x===", 1},

View File

@ -61,7 +61,7 @@ func mulWW_g(x, y Word) (z1, z0 Word) {
// and return the product as 2 Words. // and return the product as 2 Words.
if x < y { if x < y {
x, y = y, x x, y = y, x;
} }
if x < _B2 { if x < _B2 {
@ -289,7 +289,7 @@ func addVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c); c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c);
} }
return return;
} }
@ -298,7 +298,7 @@ func subVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c); c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c);
} }
return return;
} }
@ -308,7 +308,7 @@ func addVW_g(z, x *Word, y Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), c, 0); c, *z.at(i) = addWW_g(*x.at(i), c, 0);
} }
return return;
} }
@ -318,7 +318,7 @@ func subVW_g(z, x *Word, y Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), c, 0); c, *z.at(i) = subWW_g(*x.at(i), c, 0);
} }
return return;
} }
@ -328,7 +328,7 @@ func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
c, *z.at(i) = mulAddWWW_g(*x.at(i), y, c); c, *z.at(i) = mulAddWWW_g(*x.at(i), y, c);
} }
return return;
} }

View File

@ -8,7 +8,9 @@ import "testing"
type funWW func(x, y, c Word) (z1, z0 Word) type funWW func(x, y, c Word) (z1, z0 Word)
type argWW struct { x, y, c, z1, z0 Word } type argWW struct {
x, y, c, z1, z0 Word;
}
var sumWW = []argWW{ var sumWW = []argWW{
argWW{0, 0, 0, 0, 0}, argWW{0, 0, 0, 0, 0},
@ -59,7 +61,10 @@ func addr(x []Word) *Word {
type funVV func(z, x, y *Word, n int) (c Word) type funVV func(z, x, y *Word, n int) (c Word)
type argVV struct { z, x, y []Word; c Word } type argVV struct {
z, x, y []Word;
c Word;
}
var sumVV = []argVV{ var sumVV = []argVV{
argVV{}, argVV{},
@ -112,7 +117,11 @@ func TestFunVV(t *testing.T) {
type funVW func(z, x *Word, y Word, n int) (c Word) type funVW func(z, x *Word, y Word, n int) (c Word)
type argVW struct { z, x []Word; y Word; c Word } type argVW struct {
z, x []Word;
y Word;
c Word;
}
var sumVW = []argVW{ var sumVW = []argVW{
argVW{}, argVW{},
@ -169,7 +178,11 @@ func TestFunVW(t *testing.T) {
type funVWW func(z, x *Word, y, r Word, n int) (c Word) type funVWW func(z, x *Word, y, r Word, n int) (c Word)
type argVWW struct { z, x []Word; y, r Word; c Word } type argVWW struct {
z, x []Word;
y, r Word;
c Word;
}
var prodVWW = []argVWW{ var prodVWW = []argVWW{
argVWW{}, argVWW{},
@ -218,7 +231,13 @@ func testFunVWW(t *testing.T, msg string, f funVWW, a argVWW) {
// their signature is not symmetric. Try to unify. // their signature is not symmetric. Try to unify.
type funWVW func(z *Word, xn Word, x *Word, y Word, n int) (r Word) type funWVW func(z *Word, xn Word, x *Word, y Word, n int) (r Word)
type argWVW struct { z []Word; xn Word; x []Word; y Word; r Word } type argWVW struct {
z []Word;
xn Word;
x []Word;
y Word;
r Word;
}
func testFunWVW(t *testing.T, msg string, f funWVW, a argWVW) { func testFunWVW(t *testing.T, msg string, f funWVW, a argWVW) {
n := len(a.z); n := len(a.z);

View File

@ -55,7 +55,7 @@ func (z *Int) Add(x, y *Int) *Int {
if len(z.abs) == 0 { if len(z.abs) == 0 {
z.neg = false; // 0 has no sign z.neg = false; // 0 has no sign
} }
return z return z;
} }
@ -80,7 +80,7 @@ func (z *Int) Sub(x, y *Int) *Int {
if len(z.abs) == 0 { if len(z.abs) == 0 {
z.neg = false; // 0 has no sign z.neg = false; // 0 has no sign
} }
return z return z;
} }
@ -92,7 +92,7 @@ func (z *Int) Mul(x, y *Int) *Int {
// (-x) * (-y) == x * y // (-x) * (-y) == x * y
z.abs = mulNN(z.abs, x.abs, y.abs); z.abs = mulNN(z.abs, x.abs, y.abs);
z.neg = len(z.abs) > 0 && x.neg != y.neg; // 0 has no sign z.neg = len(z.abs) > 0 && x.neg != y.neg; // 0 has no sign
return z return z;
} }

View File

@ -166,8 +166,10 @@ func cmpNN(x, y []Word) (r int) {
n := len(y); n := len(y);
if m != n || m == 0 { if m != n || m == 0 {
switch { switch {
case m < n: r = -1; case m < n:
case m > n: r = 1; r = -1;
case m > n:
r = 1;
} }
return; return;
} }
@ -178,8 +180,10 @@ func cmpNN(x, y []Word) (r int) {
} }
switch { switch {
case x[i] < y[i]: r = -1; case x[i] < y[i]:
case x[i] > y[i]: r = 1; r = -1;
case x[i] > y[i]:
r = 1;
} }
return; return;
} }
@ -228,7 +232,7 @@ func mulNN(z, x, y []Word) []Word {
} }
z = normN(z); z = normN(z);
return z return z;
} }
@ -280,10 +284,14 @@ func log2N(x []Word) int {
func hexValue(ch byte) int { func hexValue(ch byte) int {
var d byte; var d byte;
switch { switch {
case '0' <= ch && ch <= '9': d = ch - '0'; case '0' <= ch && ch <= '9':
case 'a' <= ch && ch <= 'f': d = ch - 'a' + 10; d = ch-'0';
case 'A' <= ch && ch <= 'F': d = ch - 'A' + 10; case 'a' <= ch && ch <= 'f':
default: return -1; d = ch-'a'+10;
case 'A' <= ch && ch <= 'F':
d = ch-'A'+10;
default:
return -1;
} }
return int(d); return int(d);
} }
@ -356,7 +364,7 @@ func stringN(x []Word, base int) string {
var r Word; var r Word;
q, r = divNW(q, q, 10); q, r = divNW(q, q, 10);
s[i] = "0123456789abcdef"[r]; s[i] = "0123456789abcdef"[r];
}; }
return string(s[i:len(s)]); return string(s[i:len(s)]);
} }

View File

@ -12,7 +12,9 @@ func TestCmpNN(t *testing.T) {
type funNN func(z, x, y []Word) []Word type funNN func(z, x, y []Word) []Word
type argNN struct { z, x, y []Word } type argNN struct {
z, x, y []Word;
}
var sumNN = []argNN{ var sumNN = []argNN{
argNN{}, argNN{},
@ -78,7 +80,11 @@ func TestFunNN(t *testing.T) {
} }
type strN struct { x []Word; b int; s string } type strN struct {
x []Word;
b int;
s string;
}
var tabN = []strN{ var tabN = []strN{
strN{nil, 10, "0"}, strN{nil, 10, "0"},
strN{[]Word{1}, 10, "1"}, strN{[]Word{1}, 10, "1"},