forked from gopherjs/gopherjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
optional.go.patch
4811 lines (4345 loc) · 122 KB
/
optional.go.patch
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -r 87dea3f5ebe7 src/pkg/bytes/buffer_test.go
--- a/src/pkg/bytes/buffer_test.go
+++ b/src/pkg/bytes/buffer_test.go
@@ -231,12 +231,12 @@
empty(t, "TestMixedReadsAndWrites (2)", &buf, s, make([]byte, buf.Len()))
}
-func TestNil(t *testing.T) {
- var b *Buffer
- if b.String() != "<nil>" {
- t.Errorf("expected <nil>; got %q", b.String())
- }
-}
+// func TestNil(t *testing.T) {
+// var b *Buffer
+// if b.String() != "<nil>" {
+// t.Errorf("expected <nil>; got %q", b.String())
+// }
+// }
func TestReadFrom(t *testing.T) {
var buf Buffer
diff -r 87dea3f5ebe7 src/pkg/crypto/md5/md5block.go
--- a/src/pkg/crypto/md5/md5block.go
+++ b/src/pkg/crypto/md5/md5block.go
@@ -1,16 +1,14 @@
// DO NOT EDIT.
// Generate with: go run gen.go -full | gofmt >md5block.go
-// +build !amd64,!386,!arm
-
package md5
import (
- "runtime"
+ // "runtime"
"unsafe"
)
-const x86 = runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
+const x86 = false // runtime.GOARCH == "amd64" || runtime.GOARCH == "386"
var littleEndian bool
diff -r 87dea3f5ebe7 src/pkg/crypto/md5/md5block_decl.go
--- a/src/pkg/crypto/md5/md5block_decl.go
+++ b/src/pkg/crypto/md5/md5block_decl.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build amd64 386 arm
+// +build xxx
package md5
diff -r 87dea3f5ebe7 src/pkg/crypto/sha1/sha1block.go
--- a/src/pkg/crypto/sha1/sha1block.go
+++ b/src/pkg/crypto/sha1/sha1block.go
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !amd64,!386
-
// SHA1 block step.
// In its own file so that a faster assembly or C version
// can be substituted easily.
diff -r 87dea3f5ebe7 src/pkg/crypto/sha1/sha1block_decl.go
--- a/src/pkg/crypto/sha1/sha1block_decl.go
+++ b/src/pkg/crypto/sha1/sha1block_decl.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build amd64 386
+// +build xxx
package sha1
diff -r 87dea3f5ebe7 src/pkg/go/build/build.go
--- a/src/pkg/go/build/build.go
+++ b/src/pkg/go/build/build.go
@@ -458,111 +458,117 @@
}
binaryOnly := false
- if IsLocalImport(path) {
- pkga = "" // local imports have no installed path
- if srcDir == "" {
- return p, fmt.Errorf("import %q: import relative to unknown directory", path)
- }
- if !ctxt.isAbsPath(path) {
- p.Dir = ctxt.joinPath(srcDir, path)
- }
- // Determine canonical import path, if any.
- if ctxt.GOROOT != "" {
- root := ctxt.joinPath(ctxt.GOROOT, "src", "pkg")
- if sub, ok := ctxt.hasSubdir(root, p.Dir); ok {
- p.Goroot = true
- p.ImportPath = sub
- p.Root = ctxt.GOROOT
- goto Found
+ find := func() error {
+ if IsLocalImport(path) {
+ pkga = "" // local imports have no installed path
+ if srcDir == "" {
+ return fmt.Errorf("import %q: import relative to unknown directory", path)
}
- }
- all := ctxt.gopath()
- for i, root := range all {
- rootsrc := ctxt.joinPath(root, "src")
- if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok {
- // We found a potential import path for dir,
- // but check that using it wouldn't find something
- // else first.
- if ctxt.GOROOT != "" {
- if dir := ctxt.joinPath(ctxt.GOROOT, "src", "pkg", sub); ctxt.isDir(dir) {
- p.ConflictDir = dir
- goto Found
+ if !ctxt.isAbsPath(path) {
+ p.Dir = ctxt.joinPath(srcDir, path)
+ }
+ // Determine canonical import path, if any.
+ if ctxt.GOROOT != "" {
+ root := ctxt.joinPath(ctxt.GOROOT, "src", "pkg")
+ if sub, ok := ctxt.hasSubdir(root, p.Dir); ok {
+ p.Goroot = true
+ p.ImportPath = sub
+ p.Root = ctxt.GOROOT
+ return nil
+ }
+ }
+ all := ctxt.gopath()
+ for i, root := range all {
+ rootsrc := ctxt.joinPath(root, "src")
+ if sub, ok := ctxt.hasSubdir(rootsrc, p.Dir); ok {
+ // We found a potential import path for dir,
+ // but check that using it wouldn't find something
+ // else first.
+ if ctxt.GOROOT != "" {
+ if dir := ctxt.joinPath(ctxt.GOROOT, "src", "pkg", sub); ctxt.isDir(dir) {
+ p.ConflictDir = dir
+ return nil
+ }
}
+ for _, earlyRoot := range all[:i] {
+ if dir := ctxt.joinPath(earlyRoot, "src", sub); ctxt.isDir(dir) {
+ p.ConflictDir = dir
+ return nil
+ }
+ }
+
+ // sub would not name some other directory instead of this one.
+ // Record it.
+ p.ImportPath = sub
+ p.Root = root
+ return nil
}
- for _, earlyRoot := range all[:i] {
- if dir := ctxt.joinPath(earlyRoot, "src", sub); ctxt.isDir(dir) {
- p.ConflictDir = dir
- goto Found
- }
+ }
+ // It's okay that we didn't find a root containing dir.
+ // Keep going with the information we have.
+ } else {
+ if strings.HasPrefix(path, "/") {
+ return fmt.Errorf("import %q: cannot import absolute path", path)
+ }
+
+ // tried records the location of unsuccessful package lookups
+ var tried struct {
+ goroot string
+ gopath []string
+ }
+
+ // Determine directory from import path.
+ if ctxt.GOROOT != "" {
+ dir := ctxt.joinPath(ctxt.GOROOT, "src", "pkg", path)
+ isDir := ctxt.isDir(dir)
+ binaryOnly = !isDir && mode&AllowBinary != 0 && pkga != "" && ctxt.isFile(ctxt.joinPath(ctxt.GOROOT, pkga))
+ if isDir || binaryOnly {
+ p.Dir = dir
+ p.Goroot = true
+ p.Root = ctxt.GOROOT
+ return nil
}
+ tried.goroot = dir
+ }
+ for _, root := range ctxt.gopath() {
+ dir := ctxt.joinPath(root, "src", path)
+ isDir := ctxt.isDir(dir)
+ binaryOnly = !isDir && mode&AllowBinary != 0 && pkga != "" && ctxt.isFile(ctxt.joinPath(root, pkga))
+ if isDir || binaryOnly {
+ p.Dir = dir
+ p.Root = root
+ return nil
+ }
+ tried.gopath = append(tried.gopath, dir)
+ }
- // sub would not name some other directory instead of this one.
- // Record it.
- p.ImportPath = sub
- p.Root = root
- goto Found
+ // package was not found
+ var paths []string
+ if tried.goroot != "" {
+ paths = append(paths, fmt.Sprintf("\t%s (from $GOROOT)", tried.goroot))
+ } else {
+ paths = append(paths, "\t($GOROOT not set)")
}
- }
- // It's okay that we didn't find a root containing dir.
- // Keep going with the information we have.
- } else {
- if strings.HasPrefix(path, "/") {
- return p, fmt.Errorf("import %q: cannot import absolute path", path)
+ var i int
+ var format = "\t%s (from $GOPATH)"
+ for ; i < len(tried.gopath); i++ {
+ if i > 0 {
+ format = "\t%s"
+ }
+ paths = append(paths, fmt.Sprintf(format, tried.gopath[i]))
+ }
+ if i == 0 {
+ paths = append(paths, "\t($GOPATH not set)")
+ }
+ return fmt.Errorf("cannot find package %q in any of:\n%s", path, strings.Join(paths, "\n"))
}
- // tried records the location of unsuccessful package lookups
- var tried struct {
- goroot string
- gopath []string
- }
-
- // Determine directory from import path.
- if ctxt.GOROOT != "" {
- dir := ctxt.joinPath(ctxt.GOROOT, "src", "pkg", path)
- isDir := ctxt.isDir(dir)
- binaryOnly = !isDir && mode&AllowBinary != 0 && pkga != "" && ctxt.isFile(ctxt.joinPath(ctxt.GOROOT, pkga))
- if isDir || binaryOnly {
- p.Dir = dir
- p.Goroot = true
- p.Root = ctxt.GOROOT
- goto Found
- }
- tried.goroot = dir
- }
- for _, root := range ctxt.gopath() {
- dir := ctxt.joinPath(root, "src", path)
- isDir := ctxt.isDir(dir)
- binaryOnly = !isDir && mode&AllowBinary != 0 && pkga != "" && ctxt.isFile(ctxt.joinPath(root, pkga))
- if isDir || binaryOnly {
- p.Dir = dir
- p.Root = root
- goto Found
- }
- tried.gopath = append(tried.gopath, dir)
- }
-
- // package was not found
- var paths []string
- if tried.goroot != "" {
- paths = append(paths, fmt.Sprintf("\t%s (from $GOROOT)", tried.goroot))
- } else {
- paths = append(paths, "\t($GOROOT not set)")
- }
- var i int
- var format = "\t%s (from $GOPATH)"
- for ; i < len(tried.gopath); i++ {
- if i > 0 {
- format = "\t%s"
- }
- paths = append(paths, fmt.Sprintf(format, tried.gopath[i]))
- }
- if i == 0 {
- paths = append(paths, "\t($GOPATH not set)")
- }
- return p, fmt.Errorf("cannot find package %q in any of:\n%s", path, strings.Join(paths, "\n"))
+ return nil
+ }
+ if err := find(); err != nil {
+ return p, err
}
-Found:
if p.Root != "" {
if p.Goroot {
p.SrcRoot = ctxt.joinPath(p.Root, "src", "pkg")
diff -r 87dea3f5ebe7 src/pkg/go/printer/nodes.go
--- a/src/pkg/go/printer/nodes.go
+++ b/src/pkg/go/printer/nodes.go
@@ -330,7 +330,10 @@
} else {
p.print(token.LPAREN, token.RPAREN)
}
- n := result.NumFields()
+ n := 0
+ if result != nil {
+ n = result.NumFields()
+ }
if n > 0 {
// result != nil
p.print(blank)
diff -r 87dea3f5ebe7 src/pkg/go/scanner/scanner.go
--- a/src/pkg/go/scanner/scanner.go
+++ b/src/pkg/go/scanner/scanner.go
@@ -179,26 +179,26 @@
// comment starts at the beginning of the current line
s.interpretLineComment(s.src[offs:s.offset])
}
- goto exit
- }
+ } else {
+ /*-style comment */
+ s.next()
+ for s.ch >= 0 {
+ ch := s.ch
+ if ch == '\r' {
+ hasCR = true
+ }
+ s.next()
+ if ch == '*' && s.ch == '/' {
+ s.next()
+ break
+ }
+ }
- /*-style comment */
- s.next()
- for s.ch >= 0 {
- ch := s.ch
- if ch == '\r' {
- hasCR = true
- }
- s.next()
- if ch == '*' && s.ch == '/' {
- s.next()
- goto exit
+ if s.ch < 0 {
+ s.error(offs, "comment not terminated")
}
}
- s.error(offs, "comment not terminated")
-
-exit:
lit := s.src[offs:s.offset]
if hasCR {
lit = stripCR(lit)
@@ -294,52 +294,51 @@
offs--
tok = token.FLOAT
s.scanMantissa(10)
- goto exponent
+ } else {
+ if s.ch == '0' {
+ // int or float
+ offs := s.offset
+ s.next()
+ if s.ch == 'x' || s.ch == 'X' {
+ // hexadecimal int
+ s.next()
+ s.scanMantissa(16)
+ if s.offset-offs <= 2 {
+ // only scanned "0x" or "0X"
+ s.error(offs, "illegal hexadecimal number")
+ }
+ return tok, string(s.src[offs:s.offset])
+ } else {
+ // octal int or float
+ seenDecimalDigit := false
+ s.scanMantissa(8)
+ if s.ch == '8' || s.ch == '9' {
+ // illegal octal int or float
+ seenDecimalDigit = true
+ s.scanMantissa(10)
+ }
+ if s.ch == '.' || s.ch == 'e' || s.ch == 'E' || s.ch == 'i' {
+ // empty
+ } else {
+ // octal int
+ if seenDecimalDigit {
+ s.error(offs, "illegal octal number")
+ }
+ return tok, string(s.src[offs:s.offset])
+ }
+ }
+ } else {
+ // decimal int or float
+ s.scanMantissa(10)
+ }
+
+ if s.ch == '.' {
+ tok = token.FLOAT
+ s.next()
+ s.scanMantissa(10)
+ }
}
- if s.ch == '0' {
- // int or float
- offs := s.offset
- s.next()
- if s.ch == 'x' || s.ch == 'X' {
- // hexadecimal int
- s.next()
- s.scanMantissa(16)
- if s.offset-offs <= 2 {
- // only scanned "0x" or "0X"
- s.error(offs, "illegal hexadecimal number")
- }
- } else {
- // octal int or float
- seenDecimalDigit := false
- s.scanMantissa(8)
- if s.ch == '8' || s.ch == '9' {
- // illegal octal int or float
- seenDecimalDigit = true
- s.scanMantissa(10)
- }
- if s.ch == '.' || s.ch == 'e' || s.ch == 'E' || s.ch == 'i' {
- goto fraction
- }
- // octal int
- if seenDecimalDigit {
- s.error(offs, "illegal octal number")
- }
- }
- goto exit
- }
-
- // decimal int or float
- s.scanMantissa(10)
-
-fraction:
- if s.ch == '.' {
- tok = token.FLOAT
- s.next()
- s.scanMantissa(10)
- }
-
-exponent:
if s.ch == 'e' || s.ch == 'E' {
tok = token.FLOAT
s.next()
@@ -354,7 +353,6 @@
s.next()
}
-exit:
return tok, string(s.src[offs:s.offset])
}
@@ -570,7 +568,6 @@
// and thus relative to the file set.
//
func (s *Scanner) Scan() (pos token.Pos, tok token.Token, lit string) {
-scanAgain:
s.skipWhitespace()
// current token start
@@ -684,7 +681,7 @@
if s.mode&ScanComments == 0 {
// skip comment
s.insertSemi = false // newline consumed
- goto scanAgain
+ return s.Scan()
}
tok = token.COMMENT
} else {
diff -r 87dea3f5ebe7 src/pkg/io/pipe_test.go
--- a/src/pkg/io/pipe_test.go
+++ b/src/pkg/io/pipe_test.go
@@ -24,6 +24,7 @@
// Test a single read/write pair.
func TestPipe1(t *testing.T) {
+ t.Skip()
c := make(chan int)
r, w := Pipe()
var buf = make([]byte, 64)
@@ -56,6 +57,7 @@
// Test a sequence of read/write pairs.
func TestPipe2(t *testing.T) {
+ t.Skip()
c := make(chan int)
r, w := Pipe()
go reader(t, r, c)
@@ -94,6 +96,7 @@
}
func TestPipe3(t *testing.T) {
+ t.Skip()
c := make(chan pipeReturn)
r, w := Pipe()
var wdat = make([]byte, 128)
@@ -179,6 +182,7 @@
}
func TestPipeReadClose(t *testing.T) {
+ t.Skip()
for _, tt := range pipeTests {
c := make(chan int, 1)
r, w := Pipe()
@@ -208,6 +212,7 @@
// Test close on Read side during Read.
func TestPipeReadClose2(t *testing.T) {
+ t.Skip()
c := make(chan int, 1)
r, _ := Pipe()
go delayClose(t, r, c, pipeTest{})
@@ -221,6 +226,7 @@
// Test write after/before reader close.
func TestPipeWriteClose(t *testing.T) {
+ t.Skip()
for _, tt := range pipeTests {
c := make(chan int, 1)
r, w := Pipe()
@@ -248,6 +254,7 @@
}
func TestWriteEmpty(t *testing.T) {
+ t.Skip()
r, w := Pipe()
go func() {
w.Write([]byte{})
@@ -259,6 +266,7 @@
}
func TestWriteNil(t *testing.T) {
+ t.Skip()
r, w := Pipe()
go func() {
w.Write(nil)
@@ -270,6 +278,7 @@
}
func TestWriteAfterWriterClose(t *testing.T) {
+ t.Skip()
r, w := Pipe()
done := make(chan bool)
diff -r 87dea3f5ebe7 src/pkg/math/big/arith.go
--- a/src/pkg/math/big/arith.go
+++ b/src/pkg/math/big/arith.go
@@ -131,12 +131,11 @@
q1 := un32 / vn1
rhat := un32 - q1*vn1
-again1:
- if q1 >= _B2 || q1*vn0 > _B2*rhat+un1 {
+ for q1 >= _B2 || q1*vn0 > _B2*rhat+un1 {
q1--
rhat += vn1
- if rhat < _B2 {
- goto again1
+ if rhat >= _B2 {
+ break
}
}
@@ -144,12 +143,11 @@
q0 := un21 / vn1
rhat = un21 - q0*vn1
-again2:
- if q0 >= _B2 || q0*vn0 > _B2*rhat+un0 {
+ for q0 >= _B2 || q0*vn0 > _B2*rhat+un0 {
q0--
rhat += vn1
- if rhat < _B2 {
- goto again2
+ if rhat >= _B2 {
+ break
}
}
diff -r 87dea3f5ebe7 src/pkg/math/big/rat.go
--- a/src/pkg/math/big/rat.go
+++ b/src/pkg/math/big/rat.go
@@ -129,9 +129,9 @@
mantissa >>= 1
exp++
}
- if mantissa>>53 != 1 {
- panic("expected exactly 54 bits of result")
- }
+ // if mantissa>>53 != 1 {
+ // panic("expected exactly 54 bits of result")
+ // }
// 4. Rounding.
if -1022-52 <= exp && exp <= -1022 {
diff -r 87dea3f5ebe7 src/pkg/strconv/atof.go
--- a/src/pkg/strconv/atof.go
+++ b/src/pkg/strconv/atof.go
@@ -255,28 +255,43 @@
// decimal power of ten to binary power of two.
var powtab = []int{1, 3, 6, 9, 13, 16, 19, 23, 26}
-func (d *decimal) floatBits(flt *floatInfo) (b uint64, overflow bool) {
+func (d *decimal) floatBits(flt *floatInfo) (uint64, bool) {
var exp int
var mant uint64
+ assembleBits := func() uint64 {
+ bits := mant & (uint64(1)<<flt.mantbits - 1)
+ bits |= uint64((exp-flt.bias)&(1<<flt.expbits-1)) << flt.mantbits
+ if d.neg {
+ bits |= 1 << flt.mantbits << flt.expbits
+ }
+ return bits
+ }
+
+ overflow := func() (uint64, bool) {
+ mant = 0
+ exp = 1<<flt.expbits - 1 + flt.bias
+ return assembleBits(), true
+ }
+
// Zero is always a special case.
if d.nd == 0 {
mant = 0
exp = flt.bias
- goto out
+ return assembleBits(), false
}
// Obvious overflow/underflow.
// These bounds are for 64-bit floats.
// Will have to change if we want to support 80-bit floats in the future.
if d.dp > 310 {
- goto overflow
+ return overflow()
}
if d.dp < -330 {
// zero
mant = 0
exp = flt.bias
- goto out
+ return assembleBits(), false
}
// Scale by powers of two until in range [0.5, 1.0)
@@ -315,7 +330,7 @@
}
if exp-flt.bias >= 1<<flt.expbits-1 {
- goto overflow
+ return overflow()
}
// Extract 1+flt.mantbits bits.
@@ -327,7 +342,7 @@
mant >>= 1
exp++
if exp-flt.bias >= 1<<flt.expbits-1 {
- goto overflow
+ return overflow()
}
}
@@ -335,22 +350,7 @@
if mant&(1<<flt.mantbits) == 0 {
exp = flt.bias
}
- goto out
-
-overflow:
- // ±Inf
- mant = 0
- exp = 1<<flt.expbits - 1 + flt.bias
- overflow = true
-
-out:
- // Assemble bits.
- bits := mant & (uint64(1)<<flt.mantbits - 1)
- bits |= uint64((exp-flt.bias)&(1<<flt.expbits-1)) << flt.mantbits
- if d.neg {
- bits |= 1 << flt.mantbits << flt.expbits
- }
- return bits, overflow
+ return assembleBits(), false
}
func (d *decimal) atof32int() float32 {
diff -r 87dea3f5ebe7 src/pkg/strconv/atof_test.go
--- a/src/pkg/strconv/atof_test.go
+++ b/src/pkg/strconv/atof_test.go
@@ -247,19 +247,19 @@
test.in, out, err, test.out, test.err)
}
- if float64(float32(out)) == out {
- out, err := ParseFloat(test.in, 32)
- out32 := float32(out)
- if float64(out32) != out {
- t.Errorf("ParseFloat(%v, 32) = %v, not a float32 (closest is %v)", test.in, out, float64(out32))
- continue
- }
- outs := FormatFloat(float64(out32), 'g', -1, 32)
- if outs != test.out || !reflect.DeepEqual(err, test.err) {
- t.Errorf("ParseFloat(%v, 32) = %v, %v want %v, %v # %v",
- test.in, out32, err, test.out, test.err, out)
- }
- }
+ // if float64(float32(out)) == out {
+ // out, err := ParseFloat(test.in, 32)
+ // out32 := float32(out)
+ // if float64(out32) != out {
+ // t.Errorf("ParseFloat(%v, 32) = %v, not a float32 (closest is %v)", test.in, out, float64(out32))
+ // continue
+ // }
+ // outs := FormatFloat(float64(out32), 'g', -1, 32)
+ // if outs != test.out || !reflect.DeepEqual(err, test.err) {
+ // t.Errorf("ParseFloat(%v, 32) = %v, %v want %v, %v # %v",
+ // test.in, out32, err, test.out, test.err, out)
+ // }
+ // }
}
for _, test := range atof32tests {
out, err := ParseFloat(test.in, 32)
@@ -332,34 +332,34 @@
}
}
-// TestRoundTrip32 tries a fraction of all finite positive float32 values.
-func TestRoundTrip32(t *testing.T) {
- step := uint32(997)
- if testing.Short() {
- step = 99991
- }
- count := 0
- for i := uint32(0); i < 0xff<<23; i += step {
- f := math.Float32frombits(i)
- if i&1 == 1 {
- f = -f // negative
- }
- s := FormatFloat(float64(f), 'g', -1, 32)
+// // TestRoundTrip32 tries a fraction of all finite positive float32 values.
+// func TestRoundTrip32(t *testing.T) {
+// step := uint32(997)
+// if testing.Short() {
+// step = 99991
+// }
+// count := 0
+// for i := uint32(0); i < 0xff<<23; i += step {
+// f := math.Float32frombits(i)
+// if i&1 == 1 {
+// f = -f // negative
+// }
+// s := FormatFloat(float64(f), 'g', -1, 32)
- parsed, err := ParseFloat(s, 32)
- parsed32 := float32(parsed)
- switch {
- case err != nil:
- t.Errorf("ParseFloat(%q, 32) gave error %s", s, err)
- case float64(parsed32) != parsed:
- t.Errorf("ParseFloat(%q, 32) = %v, not a float32 (nearest is %v)", s, parsed, parsed32)
- case parsed32 != f:
- t.Errorf("ParseFloat(%q, 32) = %b (expected %b)", s, parsed32, f)
- }
- count++
- }
- t.Logf("tested %d float32's", count)
-}
+// parsed, err := ParseFloat(s, 32)
+// parsed32 := float32(parsed)
+// switch {
+// case err != nil:
+// t.Errorf("ParseFloat(%q, 32) gave error %s", s, err)
+// case float64(parsed32) != parsed:
+// t.Errorf("ParseFloat(%q, 32) = %v, not a float32 (nearest is %v)", s, parsed, parsed32)
+// case parsed32 != f:
+// t.Errorf("ParseFloat(%q, 32) = %b (expected %b)", s, parsed32, f)
+// }
+// count++
+// }
+// t.Logf("tested %d float32's", count)
+// }
func BenchmarkAtof64Decimal(b *testing.B) {
for i := 0; i < b.N; i++ {
diff -r 87dea3f5ebe7 src/pkg/strconv/atoi.go
--- a/src/pkg/strconv/atoi.go
+++ b/src/pkg/strconv/atoi.go
@@ -41,7 +41,7 @@
if base < 2 {
return 0
}
- return (1<<64-1)/uint64(base) + 1
+ return uint64(1<<64-1)/uint64(base) + 1
}
// ParseUint is like ParseInt but for unsigned numbers.
@@ -56,7 +56,7 @@
switch {
case len(s) < 1:
err = ErrSyntax
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
case 2 <= base && base <= 36:
// valid base; nothing to do
@@ -69,7 +69,7 @@
s = s[2:]
if len(s) < 1 {
err = ErrSyntax
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
case s[0] == '0':
base = 8
@@ -79,7 +79,7 @@
default:
err = errors.New("invalid base " + Itoa(base))
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
n = 0
@@ -99,19 +99,19 @@
default:
n = 0
err = ErrSyntax
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
if int(v) >= base {
n = 0
err = ErrSyntax
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
if n >= cutoff {
// n*base overflows
n = 1<<64 - 1
err = ErrRange
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
n *= uint64(base)
@@ -120,15 +120,12 @@
// n+v overflows
n = 1<<64 - 1
err = ErrRange
- goto Error
+ return n, &NumError{"ParseUint", s0, err}
}
n = n1
}
return n, nil
-
-Error:
- return n, &NumError{"ParseUint", s0, err}
}
// ParseInt interprets a string s in the given base (2 to 36) and
diff -r 87dea3f5ebe7 src/pkg/strconv/ftoa_test.go
--- a/src/pkg/strconv/ftoa_test.go
+++ b/src/pkg/strconv/ftoa_test.go
@@ -141,16 +141,16 @@
if string(x) != "abc"+test.s {
t.Error("AppendFloat testN=64", test.f, string(test.fmt), test.prec, "want", "abc"+test.s, "got", string(x))
}
- if float64(float32(test.f)) == test.f && test.fmt != 'b' {
- s := FormatFloat(test.f, test.fmt, test.prec, 32)
- if s != test.s {
- t.Error("testN=32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s)
- }
- x := AppendFloat([]byte("abc"), test.f, test.fmt, test.prec, 32)
- if string(x) != "abc"+test.s {
- t.Error("AppendFloat testN=32", test.f, string(test.fmt), test.prec, "want", "abc"+test.s, "got", string(x))
- }
- }
+ // if float64(float32(test.f)) == test.f && test.fmt != 'b' {
+ // s := FormatFloat(test.f, test.fmt, test.prec, 32)
+ // if s != test.s {
+ // t.Error("testN=32", test.f, string(test.fmt), test.prec, "want", test.s, "got", s)
+ // }
+ // x := AppendFloat([]byte("abc"), test.f, test.fmt, test.prec, 32)
+ // if string(x) != "abc"+test.s {
+ // t.Error("AppendFloat testN=32", test.f, string(test.fmt), test.prec, "want", "abc"+test.s, "got", string(x))
+ // }
+ // }
}
}
diff -r 87dea3f5ebe7 src/pkg/strings/strings_test.go
--- a/src/pkg/strings/strings_test.go
+++ b/src/pkg/strings/strings_test.go
@@ -13,7 +13,7 @@
"testing"
"unicode"
"unicode/utf8"
- "unsafe"
+ // "unsafe"
)
func eq(a, b []string) bool {
@@ -456,16 +456,16 @@
t.Errorf("drop: expected %q got %q", expect, m)
}
- // 6. Identity
- identity := func(r rune) rune {
- return r
- }
- orig := "Input string that we expect not to be copied."
- m = Map(identity, orig)
- if (*reflect.StringHeader)(unsafe.Pointer(&orig)).Data !=
- (*reflect.StringHeader)(unsafe.Pointer(&m)).Data {
- t.Error("unexpected copy during identity map")
- }
+ // // 6. Identity
+ // identity := func(r rune) rune {
+ // return r
+ // }
+ // orig := "Input string that we expect not to be copied."
+ // m = Map(identity, orig)
+ // if (*reflect.StringHeader)(unsafe.Pointer(&orig)).Data !=
+ // (*reflect.StringHeader)(unsafe.Pointer(&m)).Data {
+ // t.Error("unexpected copy during identity map")
+ // }
}
func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) }
diff -r 87dea3f5ebe7 src/pkg/text/scanner/scanner.go
--- a/src/pkg/text/scanner/scanner.go
+++ b/src/pkg/text/scanner/scanner.go
@@ -535,95 +535,96 @@
s.tokPos = -1
s.Line = 0
-redo:
- // skip white space
- for s.Whitespace&(1<<uint(ch)) != 0 {
- ch = s.next()
- }
-
- // start collecting token text
- s.tokBuf.Reset()
- s.tokPos = s.srcPos - s.lastCharLen
-
- // set token position
- // (this is a slightly optimized version of the code in Pos())
- s.Offset = s.srcBufOffset + s.tokPos
- if s.column > 0 {
- // common case: last character was not a '\n'
- s.Line = s.line
- s.Column = s.column
- } else {
- // last character was a '\n'
- // (we cannot be at the beginning of the source
- // since we have called next() at least once)
- s.Line = s.line - 1
- s.Column = s.lastLineLen
- }
-
- // determine token value
- tok := ch
- switch {
- case unicode.IsLetter(ch) || ch == '_':
- if s.Mode&ScanIdents != 0 {
- tok = Ident
- ch = s.scanIdentifier()
- } else {
+ for {
+ // skip white space
+ for s.Whitespace&(1<<uint(ch)) != 0 {
ch = s.next()
}
- case isDecimal(ch):
- if s.Mode&(ScanInts|ScanFloats) != 0 {
- tok, ch = s.scanNumber(ch)
+
+ // start collecting token text
+ s.tokBuf.Reset()
+ s.tokPos = s.srcPos - s.lastCharLen
+
+ // set token position
+ // (this is a slightly optimized version of the code in Pos())
+ s.Offset = s.srcBufOffset + s.tokPos
+ if s.column > 0 {