This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
etc.go
2802 lines (2513 loc) · 47.4 KB
/
etc.go
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
// Copyright 2014 The ql 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 ql
import (
"bytes"
"fmt"
"io"
"math"
"math/big"
"time"
)
// QL types.
const (
qBool = 0x62 // 'b'
qComplex64 = 0x63 // 'c'
qComplex128 = 0x64 // 'd'
qFloat32 = 0x66 // 'f'
qFloat64 = 0x67 // 'g', alias float
qInt8 = 0x69 // 'i'
qInt16 = 0x6a // 'j'
qInt32 = 0x6b // 'k'
qInt64 = 0x6c // 'l', alias int
qString = 0x73 // 's'
qUint8 = 0x75 // 'u', alias byte
qUint16 = 0x76 // 'v'
qUint32 = 0x77 // 'w'
qUint64 = 0x78 // 'x', alias uint
qBigInt = 0x49 // 'I'
qBigRat = 0x52 // 'R'
qBlob = 0x42 // 'B'
qDuration = 0x44 // 'D'
qTime = 0x54 // 'T'
)
var (
type2Str = map[int]string{
qBigInt: "bigint",
qBigRat: "bigrat",
qBlob: "blob",
qBool: "bool",
qComplex128: "complex128",
qComplex64: "complex64",
qDuration: "duration",
qFloat32: "float32",
qFloat64: "float64",
qInt16: "int16",
qInt32: "int32",
qInt64: "int64",
qInt8: "int8",
qString: "string",
qTime: "time",
qUint16: "uint16",
qUint32: "uint32",
qUint64: "uint64",
qUint8: "uint8",
}
)
func typeStr(typ int) (r string) {
return type2Str[typ]
}
func noEOF(err error) error {
if err == io.EOF {
err = nil
}
return err
}
func runErr(err error) error { return fmt.Errorf("run time error: %s", err) }
func invXOp(s, x interface{}) error {
return fmt.Errorf("invalid operation: %v[%v] (index of type %T)", s, x, x)
}
func invSOp(s interface{}) error {
return fmt.Errorf("cannot slice %s (type %T)", s, s)
}
func invNegX(x interface{}) error {
return fmt.Errorf("invalid string index %v (index must be non-negative)", x)
}
func invNegLO(x interface{}) error {
return fmt.Errorf("invalid LIMIT or OFFSET value %v (must be non-negative)", x)
}
func invSliceNegX(x interface{}) error {
return fmt.Errorf("invalid slice index %v (index must be non-negative)", x)
}
func invBoundX(s string, x uint64) error {
return fmt.Errorf("invalid string index %d (out of bounds for %d-byte string)", x, len(s))
}
func invSliceBoundX(s string, x uint64) error {
return fmt.Errorf("invalid slice index %d (out of bounds for %d-byte string)", x, len(s))
}
func intExpr(x interface{}) (i int64, err error) {
switch x := x.(type) {
case idealInt:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case idealRune:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case idealUint:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case int8:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case int16:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case int32:
if x < 0 {
return 0, invNegLO(x)
}
return int64(x), nil
case int64:
if x < 0 {
return 0, invNegLO(x)
}
return x, nil
case uint8:
return int64(x), nil
case uint16:
return int64(x), nil
case uint32:
return int64(x), nil
case uint64:
return int64(x), nil
default:
return 0, fmt.Errorf("non-integer expression: %v (value of type %T)", x, x)
}
}
func limOffExpr(x interface{}) (i uint64, err error) {
switch x := x.(type) {
case idealInt:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case idealRune:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case idealUint:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case int8:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case int16:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case int32:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case int64:
if x < 0 {
return 0, invNegLO(x)
}
return uint64(x), nil
case uint8:
return uint64(x), nil
case uint16:
return uint64(x), nil
case uint32:
return uint64(x), nil
case uint64:
return x, nil
default:
return 0, fmt.Errorf("non-integer used in LIMIT or OFFSET: %v (value of type %T)", x, x)
}
}
func indexExpr(s *string, x interface{}) (i uint64, err error) {
switch x := x.(type) {
case idealFloat:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealInt:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int64(x) >= int64(len(*s)) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealRune:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int32(x) >= int32(len(*s)) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealUint:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && uint64(x) >= uint64(len(*s)) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case int8:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case int16:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case int32:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case int64:
if x < 0 {
return 0, invNegX(x)
}
if s != nil && x >= int64(len(*s)) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint8:
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint16:
if s != nil && int(x) >= len(*s) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint32:
if s != nil && x >= uint32(len(*s)) {
return 0, invBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint64:
if s != nil && x >= uint64(len(*s)) {
return 0, invBoundX(*s, x)
}
return x, nil
default:
return 0, fmt.Errorf("non-integer string index %v (value of type %T)", x, x)
}
}
func sliceExpr(s *string, x interface{}, mod int) (i uint64, err error) {
switch x := x.(type) {
case idealFloat:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealInt:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int64(x) >= int64(len(*s)+mod) {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealRune:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int32(x) >= int32(len(*s)+mod) {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case idealUint:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && uint64(x) >= uint64(len(*s)+mod) {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case int8:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case int16:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case int32:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case int64:
if x < 0 {
return 0, invSliceNegX(x)
}
if s != nil && x >= int64(len(*s)+mod) {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint8:
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint16:
if s != nil && int(x) >= len(*s)+mod {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint32:
if s != nil && x >= uint32(len(*s)+mod) {
return 0, invSliceBoundX(*s, uint64(x))
}
return uint64(x), nil
case uint64:
if s != nil && x >= uint64(len(*s)+mod) {
return 0, invSliceBoundX(*s, x)
}
return x, nil
default:
return 0, fmt.Errorf("invalid slice index %s (type %T)", x, x)
}
}
type iop int
func (o iop) String() string {
switch i := int(o); i {
case andand:
return "&&"
case andnot:
return "&^"
case lsh:
return "<<"
case le:
return "<="
case eq:
return "=="
case ge:
return ">="
case neq:
return "!="
case oror:
return "||"
case rsh:
return ">>"
default:
return string(i)
}
}
func ideal(v interface{}) interface{} {
switch x := v.(type) {
case idealComplex:
return complex128(x)
case idealFloat:
return float64(x)
case idealInt:
return int64(x)
case idealRune:
return int64(x)
case idealUint:
return uint64(x)
default:
return v
}
}
func eval(v expression, execCtx *execCtx, ctx map[interface{}]interface{}) (y interface{}) {
y, err := expand1(v.eval(execCtx, ctx))
if err != nil {
panic(err) // panic ok here
}
return
}
func eval2(a, b expression, execCtx *execCtx, ctx map[interface{}]interface{}) (x, y interface{}) {
return eval(a, execCtx, ctx), eval(b, execCtx, ctx)
}
func invOp2(x, y interface{}, o int) (interface{}, error) {
return nil, fmt.Errorf("invalid operation: %v %v %v (mismatched types %T and %T)", x, iop(o), y, ideal(x), ideal(y))
}
func undOp(x interface{}, o int) (interface{}, error) {
return nil, fmt.Errorf("invalid operation: %v%v (operator %v not defined on %T)", iop(o), x, iop(o), x)
}
func undOp2(x, y interface{}, o int) (interface{}, error) {
return nil, fmt.Errorf("invalid operation: %v %v %v (operator %v not defined on %T)", x, iop(o), y, iop(o), x)
}
func invConv(val interface{}, typ int) (interface{}, error) {
return nil, fmt.Errorf("cannot convert %v (type %T) to type %s", val, val, typeStr(typ))
}
func truncConv(val interface{}) (interface{}, error) {
return nil, fmt.Errorf("constant %v truncated to integer", val)
}
func convert(val interface{}, typ int) (v interface{}, err error) { //NTYPE
if val == nil {
return nil, nil
}
switch typ {
case qBool:
switch x := val.(type) {
//case nil:
//case idealComplex:
//case idealFloat:
//case idealInt:
//case idealRune:
//case idealUint:
case bool:
return x, nil
//case complex64:
//case complex128:
//case float32:
//case float64:
//case int8:
//case int16:
//case int32:
//case int64:
//case string:
//case uint8:
//case uint16:
//case uint32:
//case uint64:
default:
return invConv(val, typ)
}
case qComplex64:
switch x := val.(type) {
//case nil:
case idealComplex:
return complex64(x), nil
case idealFloat:
return complex(float32(x), 0), nil
case idealInt:
return complex(float32(x), 0), nil
case idealRune:
return complex(float32(x), 0), nil
case idealUint:
return complex(float32(x), 0), nil
//case bool:
case complex64:
return x, nil
case complex128:
return complex64(x), nil
//case float32:
//case float64:
//case int8:
//case int16:
//case int32:
//case int64:
//case string:
//case uint8:
//case uint16:
//case uint32:
//case uint64:
default:
return invConv(val, typ)
}
case qComplex128:
switch x := val.(type) {
//case nil:
case idealComplex:
return complex128(x), nil
case idealFloat:
return complex(float64(x), 0), nil
case idealInt:
return complex(float64(x), 0), nil
case idealRune:
return complex(float64(x), 0), nil
case idealUint:
return complex(float64(x), 0), nil
//case bool:
case complex64:
return complex128(x), nil
case complex128:
return x, nil
//case float32:
//case float64:
//case int8:
//case int16:
//case int32:
//case int64:
//case string:
//case uint8:
//case uint16:
//case uint32:
//case uint64:
default:
return invConv(val, typ)
}
case qFloat32:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
return float32(x), nil
case idealInt:
return float32(x), nil
case idealRune:
return float32(x), nil
case idealUint:
return float32(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return x, nil
case float64:
return float32(x), nil
case int8:
return float32(x), nil
case int16:
return float32(x), nil
case int32:
return float32(x), nil
case int64:
return float32(x), nil
//case string:
case uint8:
return float32(x), nil
case uint16:
return float32(x), nil
case uint32:
return float32(x), nil
case uint64:
return float32(x), nil
case *big.Int:
v, _ := big.NewRat(1, 1).SetInt(x).Float64()
return float32(v), nil
case *big.Rat:
v, _ := x.Float64()
return float32(v), nil
case time.Duration:
return float32(x), nil
default:
return invConv(val, typ)
}
case qFloat64:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
return float64(x), nil
case idealInt:
return float64(x), nil
case idealRune:
return float64(x), nil
case idealUint:
return float64(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return float64(x), nil
case float64:
return x, nil
case int8:
return float64(x), nil
case int16:
return float64(x), nil
case int32:
return float64(x), nil
case int64:
return float64(x), nil
//case string:
case uint8:
return float64(x), nil
case uint16:
return float64(x), nil
case uint32:
return float64(x), nil
case uint64:
return float64(x), nil
case *big.Int:
v, _ := big.NewRat(1, 1).SetInt(x).Float64()
return v, nil
case *big.Rat:
v, _ := x.Float64()
return v, nil
case time.Duration:
return float64(x), nil
default:
return invConv(val, typ)
}
case qInt8:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return int8(x), nil
case idealInt:
return int8(x), nil
case idealRune:
return int8(x), nil
case idealUint:
return int8(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return int8(x), nil
case float64:
return int8(x), nil
case int8:
return x, nil
case int16:
return int8(x), nil
case int32:
return int8(x), nil
case int64:
return int8(x), nil
//case string:
case uint8:
return int8(x), nil
case uint16:
return int8(x), nil
case uint32:
return int8(x), nil
case uint64:
return int8(x), nil
case *big.Int:
return int8(x.Int64()), nil
case time.Duration:
return int8(x), nil
default:
return invConv(val, typ)
}
case qInt16:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return int16(x), nil
case idealInt:
return int16(x), nil
case idealRune:
return int16(x), nil
case idealUint:
return int16(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return int16(x), nil
case float64:
return int16(x), nil
case int8:
return int16(x), nil
case int16:
return x, nil
case int32:
return int16(x), nil
case int64:
return int16(x), nil
//case string:
case uint8:
return int16(x), nil
case uint16:
return int16(x), nil
case uint32:
return int16(x), nil
case uint64:
return int16(x), nil
case *big.Int:
return int16(x.Int64()), nil
case time.Duration:
return int16(x), nil
default:
return invConv(val, typ)
}
case qInt32:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return int32(x), nil
case idealInt:
return int32(x), nil
case idealRune:
return int32(x), nil
case idealUint:
return int32(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return int32(x), nil
case float64:
return int32(x), nil
case int8:
return int32(x), nil
case int16:
return int32(x), nil
case int32:
return x, nil
case int64:
return int32(x), nil
//case string:
case uint8:
return int32(x), nil
case uint16:
return int32(x), nil
case uint32:
return int32(x), nil
case uint64:
return int32(x), nil
case *big.Int:
return int32(x.Int64()), nil
case time.Duration:
return int32(x), nil
default:
return invConv(val, typ)
}
case qInt64:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return int64(x), nil
case idealInt:
return int64(x), nil
case idealRune:
return int64(x), nil
case idealUint:
return int64(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return int64(x), nil
case float64:
return int64(x), nil
case int8:
return int64(x), nil
case int16:
return int64(x), nil
case int32:
return int64(x), nil
case int64:
return x, nil
//case string:
case uint8:
return int64(x), nil
case uint16:
return int64(x), nil
case uint32:
return int64(x), nil
case uint64:
return int64(x), nil
case *big.Int:
return x.Int64(), nil
case time.Duration:
return int64(x), nil
default:
return invConv(val, typ)
}
case qString:
switch x := val.(type) {
//case nil:
//case idealComplex:
//case idealFloat:
case idealInt:
return string(x), nil
case idealRune:
return string(x), nil
case idealUint:
return string(x), nil
//case bool:
//case complex64:
//case complex128:
//case float32:
//case float64:
case int8:
return string(x), nil
case int16:
return string(x), nil
case int32:
return string(x), nil
case int64:
return string(x), nil
case string:
return x, nil
case uint8:
return string(x), nil
case uint16:
return string(x), nil
case uint32:
return string(x), nil
case uint64:
return string(x), nil
case []byte:
return string(x), nil
case *big.Int:
return x.String(), nil
case time.Time:
return x.String(), nil
case time.Duration:
return x.String(), nil
default:
return invConv(val, typ)
}
case qUint8:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return uint8(x), nil
case idealInt:
return uint8(x), nil
case idealRune:
return uint8(x), nil
case idealUint:
return uint8(x), nil
//case bool:
//case complex64:
//case complex128:
case float32:
return uint8(x), nil
case float64:
return uint8(x), nil
case int8:
return uint8(x), nil
case int16:
return uint8(x), nil
case int32:
return uint8(x), nil
case int64:
return uint8(x), nil
//case string:
case uint8:
return x, nil
case uint16:
return uint8(x), nil
case uint32:
return uint8(x), nil
case uint64:
return uint8(x), nil
case *big.Int:
return uint8(x.Int64()), nil
case time.Duration:
return uint8(x), nil
default:
return invConv(val, typ)
}
case qUint16:
switch x := val.(type) {
//case nil:
//case idealComplex:
case idealFloat:
if _, frac := math.Modf(float64(x)); frac != 0 {
return truncConv(x)
}
return uint16(x), nil
case idealInt:
return uint16(x), nil
case idealRune:
return uint16(x), nil