1 package frost.core
6
7 uses frost.unsafe.Pointer
8
9
12 class Int8 : Value, HashKey<Int8>, Comparable<Int8>, Formattable {
13 @private
14 class Bits : ListView<Bit> {
15 def value:Int8
16 init(value:Int8) {
17 self.value := value
18 }
19
20
21 @override
22 function [](index:Int):Bit {
23 return value && (1 << index) != 0
24 }
25
26
29 @override
30 function get_count():Int {
31 return 8
32 }
33
34 @override
35 function get_iterator():Iterator<Bit> {
36 return org.frostlang.frost.IntBitIterator(value.toUInt64, 1 << (8->builtin_uint64 - 1))
37 }
38 }
39
42 constant MIN:Int8 := -128
43
44
47 constant MAX:Int8 := 127
48
49 @package
50 def value:builtin_int8
51
52
53 @implicit
54 init(value:builtin_int8) {
55 self.value := value
56 }
57
58
59 @priority(20)
60 function +(other:Int8):Int32 {
61 return value->builtin_int32 + other.value->builtin_int32
62 }
63
64 @priority(-1)
65 function +(other:Int8):Int8 {
66 return value + other.value
67 }
68
69
70 @priority(4)
71 function +(other:Int16):Int32 {
72 return value->builtin_int32 + other.value->builtin_int32
73 }
74
75
76 @priority(6)
77 function +(other:Int32):Int32 {
78 return value->builtin_int32 + other.value
79 }
80
81
82 @priority(8)
83 function +(other:Int64):Int64 {
84 return value->builtin_int64 + other.value
85 }
86
87
88 @priority(10)
89 function +(other:Int):Int {
90 return value->builtin_int + other.value
91 }
92
93
94 @priority(1)
95 function +(other:UInt8):Int32 {
96 return value->builtin_int32 + other.value->builtin_int32
97 }
98
99
100 @priority(3)
101 function +(other:UInt16):Int32 {
102 return value->builtin_int32 + other.value->builtin_int32
103 }
104
105
106 @priority(5)
107 function +(other:UInt32):Int64 {
108 return value->builtin_int64 + other.value->builtin_int64
109 }
110
111
112 @priority(9)
113 function +(other:UInt):Int64 {
114 return value->builtin_int64 + other.value->builtin_int64
115 }
116
117
118 @priority(20)
119 function +&(other:Int8):Int32 {
120 return value->builtin_int32 +& other.value->builtin_int32
121 }
122
123 @priority(-1)
124 function +&(other:Int8):Int8 {
125 return value +& other.value
126 }
127
128
129 @priority(4)
130 function +&(other:Int16):Int32 {
131 return value->builtin_int32 +& other.value->builtin_int32
132 }
133
134
135 @priority(6)
136 function +&(other:Int32):Int32 {
137 return value->builtin_int32 +& other.value
138 }
139
140
141 @priority(8)
142 function +&(other:Int64):Int64 {
143 return value->builtin_int64 +& other.value
144 }
145
146
147 @priority(10)
148 function +&(other:Int):Int {
149 return value->builtin_int +& other.value
150 }
151
152
153 @priority(1)
154 function +&(other:UInt8):Int32 {
155 return value->builtin_int32 +& other.value->builtin_int32
156 }
157
158
159 @priority(3)
160 function +&(other:UInt16):Int32 {
161 return value->builtin_int32 +& other.value->builtin_int32
162 }
163
164
165 @priority(5)
166 function +&(other:UInt32):Int64 {
167 return value->builtin_int64 +& other.value->builtin_int64
168 }
169
170
171 @priority(9)
172 function +&(other:UInt):Int64 {
173 return value->builtin_int64 +& other.value->builtin_int64
174 }
175
176
177 @priority(20)
178 function -(other:Int8):Int32 {
179 return value->builtin_int32 - other.value->builtin_int32
180 }
181
182 @priority(-1)
183 function -(other:Int8):Int8 {
184 return value - other.value
185 }
186
187
188 @priority(4)
189 function -(other:Int16):Int32 {
190 return value->builtin_int32 - other.value->builtin_int32
191 }
192
193
194 @priority(6)
195 function -(other:Int32):Int32 {
196 return value->builtin_int32 - other.value
197 }
198
199
200 @priority(8)
201 function -(other:Int64):Int64 {
202 return value->builtin_int64 - other.value
203 }
204
205
206 @priority(10)
207 function -(other:Int):Int {
208 return value->builtin_int - other.value
209 }
210
211
212 @priority(1)
213 function -(other:UInt8):Int32 {
214 return value->builtin_int32 - other.value->builtin_int32
215 }
216
217
218 @priority(3)
219 function -(other:UInt16):Int32 {
220 return value->builtin_int32 - other.value->builtin_int32
221 }
222
223
224 @priority(5)
225 function -(other:UInt32):Int64 {
226 return value->builtin_int64 - other.value->builtin_int64
227 }
228
229
230 @priority(9)
231 function -(other:UInt):Int64 {
232 return value->builtin_int64 - other.value->builtin_int64
233 }
234
235
236 @priority(20)
237 function -&(other:Int8):Int32 {
238 return value->builtin_int32 -& other.value->builtin_int32
239 }
240
241 @priority(-1)
242 function -&(other:Int8):Int8 {
243 return value -& other.value
244 }
245
246
247 @priority(4)
248 function -&(other:Int16):Int32 {
249 return value->builtin_int32 -& other.value->builtin_int32
250 }
251
252
253 @priority(6)
254 function -&(other:Int32):Int32 {
255 return value->builtin_int32 -& other.value
256 }
257
258
259 @priority(8)
260 function -&(other:Int64):Int64 {
261 return value->builtin_int64 -& other.value
262 }
263
264
265 @priority(10)
266 function -&(other:Int):Int {
267 return value->builtin_int -& other.value
268 }
269
270
271 @priority(1)
272 function -&(other:UInt8):Int32 {
273 return value->builtin_int32 -& other.value->builtin_int32
274 }
275
276
277 @priority(3)
278 function -&(other:UInt16):Int32 {
279 return value->builtin_int32 -& other.value->builtin_int32
280 }
281
282
283 @priority(5)
284 function -&(other:UInt32):Int64 {
285 return value->builtin_int64 -& other.value->builtin_int64
286 }
287
288
289 @priority(9)
290 function -&(other:UInt):Int64 {
291 return value->builtin_int64 -& other.value->builtin_int64
292 }
293
294
295 function -():Int8 {
296 return Int8(-value)
297 }
298
299
300 @priority(20)
301 function *(other:Int8):Int32 {
302 return value->builtin_int32 * other.value->builtin_int32
303 }
304
305 @priority(-1)
306 function *(other:Int8):Int8 {
307 return value * other.value
308 }
309
310
311 @priority(4)
312 function *(other:Int16):Int32 {
313 return value->builtin_int32 * other.value->builtin_int32
314 }
315
316
317 @priority(6)
318 function *(other:Int32):Int32 {
319 return value->builtin_int32 * other.value
320 }
321
322
323 @priority(8)
324 function *(other:Int64):Int64 {
325 return value->builtin_int64 * other.value
326 }
327
328
329 @priority(10)
330 function *(other:Int):Int {
331 return value->builtin_int * other.value
332 }
333
334
335 @priority(1)
336 function *(other:UInt8):Int32 {
337 return value->builtin_int32 * other.value->builtin_int32
338 }
339
340
341 @priority(3)
342 function *(other:UInt16):Int32 {
343 return value->builtin_int32 * other.value->builtin_int32
344 }
345
346
347 @priority(5)
348 function *(other:UInt32):Int64 {
349 return value->builtin_int64 * other.value->builtin_int64
350 }
351
352
353 @priority(9)
354 function *(other:UInt):Int64 {
355 return value->builtin_int64 * other.value->builtin_int64
356 }
357
358
359 @priority(20)
360 function *&(other:Int8):Int32 {
361 return value->builtin_int32 *& other.value->builtin_int32
362 }
363
364 @priority(-1)
365 function *&(other:Int8):Int8 {
366 return value *& other.value
367 }
368
369
370 @priority(4)
371 function *&(other:Int16):Int32 {
372 return value->builtin_int32 *& other.value->builtin_int32
373 }
374
375
376 @priority(6)
377 function *&(other:Int32):Int32 {
378 return value->builtin_int32 *& other.value
379 }
380
381
382 @priority(8)
383 function *&(other:Int64):Int64 {
384 return value->builtin_int64 *& other.value
385 }
386
387
388 @priority(10)
389 function *&(other:Int):Int {
390 return value->builtin_int *& other.value
391 }
392
393
394 @priority(1)
395 function *&(other:UInt8):Int32 {
396 return value->builtin_int32 *& other.value->builtin_int32
397 }
398
399
400 @priority(3)
401 function *&(other:UInt16):Int32 {
402 return value->builtin_int32 *& other.value->builtin_int32
403 }
404
405
406 @priority(5)
407 function *&(other:UInt32):Int64 {
408 return value->builtin_int64 *& other.value->builtin_int64
409 }
410
411
412 @priority(9)
413 function *&(other:UInt):Int64 {
414 return value->builtin_int64 *& other.value->builtin_int64
415 }
416
417
418 @priority(20)
419 function //(other:Int8):Int32 {
420 return value->builtin_int32 // other.value->builtin_int32
421 }
422
423 @priority(-1)
424 function //(other:Int8):Int8 {
425 return value // other.value
426 }
427
428
429 @priority(4)
430 function //(other:Int16):Int32 {
431 return value->builtin_int32 // other.value->builtin_int32
432 }
433
434
435 @priority(6)
436 function //(other:Int32):Int32 {
437 return value->builtin_int32 // other.value
438 }
439
440
441 @priority(8)
442 function //(other:Int64):Int64 {
443 return value->builtin_int64 // other.value
444 }
445
446
447 @priority(10)
448 function //(other:Int):Int {
449 return value->builtin_int // other.value
450 }
451
452
453 @priority(1)
454 function //(other:UInt8):Int32 {
455 return value->builtin_int32 // other.value->builtin_int32
456 }
457
458
459 @priority(3)
460 function //(other:UInt16):Int32 {
461 return value->builtin_int32 // other.value->builtin_int32
462 }
463
464
465 @priority(5)
466 function //(other:UInt32):Int64 {
467 return value->builtin_int64 // other.value->builtin_int64
468 }
469
470
471 @priority(9)
472 function //(other:UInt):Int64 {
473 return value->builtin_int64 // other.value->builtin_int64
474 }
475
476
477 @priority(20)
478 function //&(other:Int8):Int32 {
479 return value->builtin_int32 //& other.value->builtin_int32
480 }
481
482 @priority(-1)
483 function //&(other:Int8):Int8 {
484 return value //& other.value
485 }
486
487
488 @priority(4)
489 function //&(other:Int16):Int32 {
490 return value->builtin_int32 //& other.value->builtin_int32
491 }
492
493
494 @priority(6)
495 function //&(other:Int32):Int32 {
496 return value->builtin_int32 //& other.value
497 }
498
499
500 @priority(8)
501 function //&(other:Int64):Int64 {
502 return value->builtin_int64 //& other.value
503 }
504
505
506 @priority(10)
507 function //&(other:Int):Int {
508 return value->builtin_int //& other.value
509 }
510
511
512 @priority(1)
513 function //&(other:UInt8):Int32 {
514 return value->builtin_int32 //& other.value->builtin_int32
515 }
516
517
518 @priority(3)
519 function //&(other:UInt16):Int32 {
520 return value->builtin_int32 //& other.value->builtin_int32
521 }
522
523
524 @priority(5)
525 function //&(other:UInt32):Int64 {
526 return value->builtin_int64 //& other.value->builtin_int64
527 }
528
529
530 @priority(9)
531 function //&(other:UInt):Int64 {
532 return value->builtin_int64 //& other.value->builtin_int64
533 }
534
535
536 @priority(20)
537 function %(other:Int8):Int32 {
538 return value->builtin_int32 % other.value->builtin_int32
539 }
540
541 @priority(-1)
542 function %(other:Int8):Int8 {
543 return value % other.value
544 }
545
546
547 @priority(4)
548 function %(other:Int16):Int32 {
549 return value->builtin_int32 % other.value->builtin_int32
550 }
551
552
553 @priority(6)
554 function %(other:Int32):Int32 {
555 return value->builtin_int32 % other.value
556 }
557
558
559 @priority(8)
560 function %(other:Int64):Int64 {
561 return value->builtin_int64 % other.value
562 }
563
564
565 @priority(10)
566 function %(other:Int):Int {
567 return value->builtin_int % other.value
568 }
569
570
571 @priority(1)
572 function %(other:UInt8):Int32 {
573 return value->builtin_int32 % other.value->builtin_int32
574 }
575
576
577 @priority(3)
578 function %(other:UInt16):Int32 {
579 return value->builtin_int32 % other.value->builtin_int32
580 }
581
582
583 @priority(5)
584 function %(other:UInt32):Int64 {
585 return value->builtin_int64 % other.value->builtin_int64
586 }
587
588
589 @priority(9)
590 function %(other:UInt):Int64 {
591 return value->builtin_int64 % other.value->builtin_int64
592 }
593
594
595 @priority(20)
596 function /(other:Int8):Real32 {
597 return value->builtin_float32 / other.value->builtin_float32
598 }
599
600
601 @priority(4)
602 function /(other:Int16):Real32 {
603 return value->builtin_float32 / other.value->builtin_float32
604 }
605
606
607 @priority(6)
608 function /(other:Int32):Real32 {
609 return value->builtin_float32 / other.value->builtin_float32
610 }
611
612
613 @priority(8)
614 function /(other:Int64):Real64 {
615 return value->builtin_float64 / other.value->builtin_float64
616 }
617
618
619 @priority(1)
620 function /(other:UInt8):Real32 {
621 return value->builtin_float32 / other.value->builtin_float32
622 }
623
624
625 @priority(3)
626 function /(other:UInt16):Real32 {
627 return value->builtin_float32 / other.value->builtin_float32
628 }
629
630
631 @priority(5)
632 function /(other:UInt32):Real32 {
633 return value->builtin_float32 / other.value->builtin_float32
634 }
635
636
637 @priority(7)
638 function /(other:UInt64):Real64 {
639 return value->builtin_float64 / other.value->builtin_float64
640 }
641
642
643 @priority(11)
644 function /(other:Real32):Real32 {
645 return value->builtin_float32 / other.value
646 }
647
648
649 @priority(12)
650 function /(other:Real64):Real64 {
651 return value->builtin_float64 / other.value
652 }
653
654
655 function !!():Int8 {
656 return Int8(!!value)
657 }
658
659
660 @priority(20)
661 function &&(other:Int8):Int32 {
662 return value->builtin_int32 && other.value->builtin_int32
663 }
664
665 @priority(-1)
666 function &&(other:Int8):Int8 {
667 return value && other.value
668 }
669
670
671 @priority(4)
672 function &&(other:Int16):Int32 {
673 return value->builtin_int32 && other.value->builtin_int32
674 }
675
676
677 @priority(6)
678 function &&(other:Int32):Int32 {
679 return value->builtin_int32 && other.value
680 }
681
682
683 @priority(8)
684 function &&(other:Int64):Int64 {
685 return value->builtin_int64 && other.value
686 }
687
688
689 @priority(10)
690 function &&(other:Int):Int {
691 return value->builtin_int && other.value
692 }
693
694
695 @priority(1)
696 function &&(other:UInt8):UInt32 {
697 return value->builtin_uint32 && other.value->builtin_uint32
698 }
699
700
701 @priority(3)
702 function &&(other:UInt16):UInt32 {
703 return value->builtin_uint32 && other.value->builtin_uint32
704 }
705
706
707 @priority(5)
708 function &&(other:UInt32):UInt32 {
709 return value->builtin_uint32 && other.value
710 }
711
712
713 @priority(7)
714 function &&(other:UInt64):UInt64 {
715 return value->builtin_uint64 && other.value
716 }
717
718
719 @priority(9)
720 function &&(other:UInt):UInt {
721 return value->builtin_uint && other.value
722 }
723
724
725 @priority(20)
726 function ||(other:Int8):Int32 {
727 return value->builtin_int32 || other.value->builtin_int32
728 }
729
730 @priority(-1)
731 function ||(other:Int8):Int8 {
732 return value || other.value
733 }
734
735
736 @priority(4)
737 function ||(other:Int16):Int32 {
738 return value->builtin_int32 || other.value->builtin_int32
739 }
740
741
742 @priority(6)
743 function ||(other:Int32):Int32 {
744 return value->builtin_int32 || other.value
745 }
746
747
748 @priority(8)
749 function ||(other:Int64):Int64 {
750 return value->builtin_int64 || other.value
751 }
752
753
754 @priority(10)
755 function ||(other:Int):Int {
756 return value->builtin_int || other.value
757 }
758
759
760 @priority(1)
761 function ||(other:UInt8):UInt32 {
762 return value->builtin_uint32 || other.value->builtin_uint32
763 }
764
765
766 @priority(3)
767 function ||(other:UInt16):UInt32 {
768 return value->builtin_uint32 || other.value->builtin_uint32
769 }
770
771
772 @priority(5)
773 function ||(other:UInt32):UInt32 {
774 return value->builtin_uint32 || other.value
775 }
776
777
778 @priority(7)
779 function ||(other:UInt64):UInt64 {
780 return value->builtin_uint64 || other.value
781 }
782
783
784 @priority(9)
785 function ||(other:UInt):UInt {
786 return value->builtin_uint || other.value
787 }
788
789
790 @priority(20)
791 function ~~(other:Int8):Int32 {
792 return value->builtin_int32 ~~ other.value->builtin_int32
793 }
794
795 @priority(-1)
796 function ~~(other:Int8):Int8 {
797 return value ~~ other.value
798 }
799
800
801 @priority(4)
802 function ~~(other:Int16):Int32 {
803 return value->builtin_int32 ~~ other.value->builtin_int32
804 }
805
806
807 @priority(6)
808 function ~~(other:Int32):Int32 {
809 return value->builtin_int32 ~~ other.value
810 }
811
812
813 @priority(8)
814 function ~~(other:Int64):Int64 {
815 return value->builtin_int64 ~~ other.value
816 }
817
818
819 @priority(10)
820 function ~~(other:Int):Int {
821 return value->builtin_int ~~ other.value
822 }
823
824
825 @priority(1)
826 function ~~(other:UInt8):UInt32 {
827 return value->builtin_uint32 ~~ other.value->builtin_uint32
828 }
829
830
831 @priority(3)
832 function ~~(other:UInt16):UInt32 {
833 return value->builtin_uint32 ~~ other.value->builtin_uint32
834 }
835
836
837 @priority(5)
838 function ~~(other:UInt32):UInt32 {
839 return value->builtin_uint32 ~~ other.value
840 }
841
842
843 @priority(7)
844 function ~~(other:UInt64):UInt64 {
845 return value->builtin_uint64 ~~ other.value
846 }
847
848
849 @priority(9)
850 function ~~(other:UInt):UInt {
851 return value->builtin_uint ~~ other.value
852 }
853
854
855 @priority(20)
856 function <<(other:Int8):Int32 {
857 return value->builtin_int32 << other.value->builtin_int32
858 }
859
860 @priority(-1)
861 function <<(other:Int8):Int8 {
862 return value << other.value
863 }
864
865
866 @priority(20)
867 function <<&(other:Int8):Int32 {
868 return value->builtin_int32 <<& other.value->builtin_int32
869 }
870
871 @priority(-1)
872 function <<&(other:Int8):Int8 {
873 return value <<& other.value
874 }
875
876
877 @priority(20)
878 function >>(other:Int8):Int32 {
879 return value->builtin_int32 >> other.value->builtin_int32
880 }
881
882 @priority(-1)
883 function >>(other:Int8):Int8 {
884 return value >> other.value
885 }
886
887
888 @override
889 @priority(20)
890 function =(other:Int8):Bit {
891 return value = other.value
892 }
893
894
895 @priority(4)
896 function =(other:Int16):Bit {
897 return value->builtin_int16 = other.value
898 }
899
900
901 @priority(6)
902 function =(other:Int32):Bit {
903 return value->builtin_int32 = other.value
904 }
905
906
907 @priority(8)
908 function =(other:Int64):Bit {
909 return value->builtin_int64 = other.value
910 }
911
912
913 @priority(10)
914 function =(other:Int):Bit {
915 return value->builtin_int = other.value
916 }
917
918
919 @priority(1)
920 function =(other:UInt8):Bit {
921 return value->builtin_int16 = other.value->builtin_int16
922 }
923
924
925 @priority(3)
926 function =(other:UInt16):Bit {
927 return value->builtin_int32 = other.value->builtin_int32
928 }
929
930
931 @priority(5)
932 function =(other:UInt32):Bit {
933 return value->builtin_int64 = other.value->builtin_int64
934 }
935
936
937 @priority(9)
938 function =(other:UInt):Bit {
939 return value->builtin_int64 = other.value->builtin_int64
940 }
941
942
943 @override
944 @priority(20)
945 function !=(other:Int8):Bit {
946 return value != other.value
947 }
948
949
950 @priority(4)
951 function !=(other:Int16):Bit {
952 return value->builtin_int16 != other.value
953 }
954
955
956 @priority(6)
957 function !=(other:Int32):Bit {
958 return value->builtin_int32 != other.value
959 }
960
961
962 @priority(8)
963 function !=(other:Int64):Bit {
964 return value->builtin_int64 != other.value
965 }
966
967
968 @priority(10)
969 function !=(other:Int):Bit {
970 return value->builtin_int != other.value
971 }
972
973
974 @priority(1)
975 function !=(other:UInt8):Bit {
976 return value->builtin_int16 != other.value->builtin_int16
977 }
978
979
980 @priority(3)
981 function !=(other:UInt16):Bit {
982 return value->builtin_int32 != other.value->builtin_int32
983 }
984
985
986 @priority(5)
987 function !=(other:UInt32):Bit {
988 return value->builtin_int64 != other.value->builtin_int64
989 }
990
991
992 @priority(9)
993 function !=(other:UInt):Bit {
994 return value->builtin_int64 != other.value->builtin_int64
995 }
996
997
998 @override
999 @priority(20)
1000 function <(other:Int8):Bit {
1001 return value < other.value
1002 }< other.value
1003 }
1004
1005
1006 @priority(4)
1007 function <(other:Int16):Bit {
1008 return value->builtin_int16 < other.value
1009 }< other.value
1010 }
1011
1012
1013 @priority(6)
1014 function <(other:Int32):Bit {
1015 return value->builtin_int32 < other.value
1016 }< other.value
1017 }
1018
1019
1020 @priority(8)
1021 function <(other:Int64):Bit {
1022 return value->builtin_int64 < other.value
1023 }< other.value
1024 }
1025
1026
1027 @priority(10)
1028 function <(other:Int):Bit {
1029 return value->builtin_int < other.value
1030 }< other.value
1031 }
1032
1033
1034 @priority(1)
1035 function <(other:UInt8):Bit {
1036 return value->builtin_int16 < other.value->< other.value->builtin_int16
1037 }
1038
1039
1040 @priority(3)
1041 function <(other:UInt16):Bit {
1042 return value->builtin_int32 < other.value->< other.value->builtin_int32
1043 }
1044
1045
1046 @priority(5)
1047 function <(other:UInt32):Bit {
1048 return value->builtin_int64 < other.value->< other.value->builtin_int64
1049 }
1050
1051
1052 @priority(9)
1053 function <(other:UInt):Bit {
1054 return value->builtin_int64 < other.value->< other.value->builtin_int64
1055 }
1056
1057
1058 @override
1059 @priority(20)
1060 function >(other:Int8):Bit {
1061 return value > other.value
1062 }
1063
1064
1065 @priority(4)
1066 function >(other:Int16):Bit {
1067 return value->builtin_int16 > other.value
1068 }
1069
1070
1071 @priority(6)
1072 function >(other:Int32):Bit {
1073 return value->builtin_int32 > other.value
1074 }
1075
1076
1077 @priority(8)
1078 function >(other:Int64):Bit {
1079 return value->builtin_int64 > other.value
1080 }
1081
1082
1083 @priority(10)
1084 function >(other:Int):Bit {
1085 return value->builtin_int > other.value
1086 }
1087
1088
1089 @priority(1)
1090 function >(other:UInt8):Bit {
1091 return value->builtin_int16 > other.value->builtin_int16
1092 }
1093
1094
1095 @priority(3)
1096 function >(other:UInt16):Bit {
1097 return value->builtin_int32 > other.value->builtin_int32
1098 }
1099
1100
1101 @priority(5)
1102 function >(other:UInt32):Bit {
1103 return value->builtin_int64 > other.value->builtin_int64
1104 }
1105
1106
1107 @priority(9)
1108 function >(other:UInt):Bit {
1109 return value->builtin_int64 > other.value->builtin_int64
1110 }
1111
1112
1113 @override
1114 @priority(20)
1115 function >=(other:Int8):Bit {
1116 return value >= other.value
1117 }
1118
1119
1120 @priority(4)
1121 function >=(other:Int16):Bit {
1122 return value->builtin_int16 >= other.value
1123 }
1124
1125
1126 @priority(6)
1127 function >=(other:Int32):Bit {
1128 return value->builtin_int32 >= other.value
1129 }
1130
1131
1132 @priority(8)
1133 function >=(other:Int64):Bit {
1134 return value->builtin_int64 >= other.value
1135 }
1136
1137
1138 @priority(10)
1139 function >=(other:Int):Bit {
1140 return value->builtin_int >= other.value
1141 }
1142
1143
1144 @priority(1)
1145 function >=(other:UInt8):Bit {
1146 return value->builtin_int16 >= other.value->builtin_int16
1147 }
1148
1149
1150 @priority(3)
1151 function >=(other:UInt16):Bit {
1152 return value->builtin_int32 >= other.value->builtin_int32
1153 }
1154
1155
1156 @priority(5)
1157 function >=(other:UInt32):Bit {
1158 return value->builtin_int64 >= other.value->builtin_int64
1159 }
1160
1161
1162 @priority(9)
1163 function >=(other:UInt):Bit {
1164 return value->builtin_int64 >= other.value->builtin_int64
1165 }
1166
1167
1168 @override
1169 @priority(20)
1170 function <=(other:Int8):Bit {
1171 return value <= other.value
1172 }
1173
1174
1175 @priority(4)
1176 function <=(other:Int16):Bit {
1177 return value->builtin_int16 <= other.value
1178 }
1179
1180
1181 @priority(6)
1182 function <=(other:Int32):Bit {
1183 return value->builtin_int32 <= other.value
1184 }
1185
1186
1187 @priority(8)
1188 function <=(other:Int64):Bit {
1189 return value->builtin_int64 <= other.value
1190 }
1191
1192
1193 @priority(10)
1194 function <=(other:Int):Bit {
1195 return value->builtin_int <= other.value
1196 }
1197
1198
1199 @priority(1)
1200 function <=(other:UInt8):Bit {
1201 return value->builtin_int16 <= other.value->builtin_int16
1202 }
1203
1204
1205 @priority(3)
1206 function <=(other:UInt16):Bit {
1207 return value->builtin_int32 <= other.value->builtin_int32
1208 }
1209
1210
1211 @priority(5)
1212 function <=(other:UInt32):Bit {
1213 return value->builtin_int64 <= other.value->builtin_int64
1214 }
1215
1216
1217 @priority(9)
1218 function <=(other:UInt):Bit {
1219 return value->builtin_int64 <= other.value->builtin_int64
1220 }
1221
1222 @class
1223 function [](range:Range<Int8>):ListView<Int8> {
1224 return org.frostlang.frost.Int8List(SteppedRange<Int8, Int8>(range.min, range.max, 1, range.inclusive))
1225 }
1226
1227 @class
1228 function [](range:SteppedRange<Int8, Int8>):ListView<Int8> {
1229 return org.frostlang.frost.Int8List(range)
1230 }
1231
1232
1233 property abs:Int8
1234 function get_abs():Int8 {
1235 if self < 0 {
1236 return -self
1237 }
1238 return self
1239 }
1240
1243 property bits:ListView<Bit>
1244 function get_bits():ListView<Bit> { return Bits(self) }
1245
1246
1247 property sqrt:Real32
1248 function get_sqrt():Real32 {
1249 return toReal32.sqrt
1250 }
1251
1252
1253 @priority(20)
1254 function min(other:Int8):Int8 {
1255 if value < other.value {< other.value {
1256 return value
1257 }
1258 return other.value
1259 }
1260
1261
1262 @priority(4)
1263 function min(other:Int16):Int16 {
1264 if value->builtin_int16 < other.value {< other.value {
1265 return value->builtin_int16
1266 }
1267 return other.value
1268 }
1269
1270
1271 @priority(6)
1272 function min(other:Int32):Int32 {
1273 if value->builtin_int32 < other.value {< other.value {
1274 return value->builtin_int32
1275 }
1276 return other.value
1277 }
1278
1279
1280 @priority(8)
1281 function min(other:Int64):Int64 {
1282 if value->builtin_int64 < other.value {< other.value {
1283 return value->builtin_int64
1284 }
1285 return other.value
1286 }
1287
1288
1289 @priority(10)
1290 function min(other:Int):Int {
1291 if value->builtin_int < other.value {< other.value {
1292 return value->builtin_int
1293 }
1294 return other.value
1295 }
1296
1297
1298 @priority(1)
1299 function min(other:UInt8):Int16 {
1300 if value->builtin_int16 < other.value->< other.value->builtin_int16 {
1301 return value->builtin_int16
1302 }
1303 return other.value->builtin_int16
1304 }
1305
1306
1307 @priority(3)
1308 function min(other:UInt16):Int32 {
1309 if value->builtin_int32 < other.value->< other.value->builtin_int32 {
1310 return value->builtin_int32
1311 }
1312 return other.value->builtin_int32
1313 }
1314
1315
1316 @priority(5)
1317 function min(other:UInt32):Int64 {
1318 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
1319 return value->builtin_int64
1320 }
1321 return other.value->builtin_int64
1322 }
1323
1324
1325
1326 @priority(9)
1327 function min(other:UInt):Int64 {
1328 if value->builtin_int64 < other.value->< other.value->builtin_int64 {
1329 return value->builtin_int64
1330 }
1331 return other.value->builtin_int64
1332 }
1333
1334
1335 @priority(20)
1336 function max(other:Int8):Int8 {
1337 if value > other.value {
1338 return value
1339 }
1340 return other.value
1341 }
1342
1343
1344 @priority(4)
1345 function max(other:Int16):Int16 {
1346 if value->builtin_int16 > other.value {
1347 return value->builtin_int16
1348 }
1349 return other.value
1350 }
1351
1352
1353 @priority(6)
1354 function max(other:Int32):Int32 {
1355 if value->builtin_int32 > other.value {
1356 return value->builtin_int32
1357 }
1358 return other.value
1359 }
1360
1361
1362 @priority(8)
1363 function max(other:Int64):Int64 {
1364 if value->builtin_int64 > other.value {
1365 return value->builtin_int64
1366 }
1367 return other.value
1368 }
1369
1370
1371 @priority(10)
1372 function max(other:Int):Int {
1373 if value->builtin_int > other.value {
1374 return value->builtin_int
1375 }
1376 return other.value
1377 }
1378
1379
1380 @priority(1)
1381 function max(other:UInt8):Int16 {
1382 if value->builtin_int16 > other.value->builtin_int16 {
1383 return value->builtin_int16
1384 }
1385 return other.value->builtin_int16
1386 }
1387
1388
1389 @priority(3)
1390 function max(other:UInt16):Int32 {
1391 if value->builtin_int32 > other.value->builtin_int32 {
1392 return value->builtin_int32
1393 }
1394 return other.value->builtin_int32
1395 }
1396
1397
1398 @priority(5)
1399 function max(other:UInt32):Int64 {
1400 if value->builtin_int64 > other.value->builtin_int64 {
1401 return value->builtin_int64
1402 }
1403 return other.value->builtin_int64
1404 }
1405
1406
1407
1408 @priority(9)
1409 function max(other:UInt):Int64 {
1410 if value->builtin_int64 > other.value->builtin_int64 {
1411 return value->builtin_int64
1412 }
1413 return other.value->builtin_int64
1414 }
1415
1416 @override
1417 function get_hash():Int {
1418 return Int(value->builtin_int)
1419 }
1420
1421
1422 property bitCount:Int8
1423 @external(frostInt8_get_bitCount)
1424 function get_bitCount():Int8
1425
1426
1427 @class
1428 @pre(radix >= 2 & radix <= 36)
1429 function parse(str:String, radix:Int):Int8? {
1430 if str.startsWith("-") {
1431 def abs := Frost.parse(str[1..], radix)
1432 if abs == null {
1433 return null
1434 }
1435 return -(abs.asInt8)
1436 }
1437 else {
1438 def result := Frost.parse(str, radix)
1439 if result == null {
1440 return null
1441 }
1442 return result.asInt8
1443 }
1444 }
1445
1446
1449 property asInt:Int
1450 function get_asInt():Int {
1451 return Int(value->builtin_int)
1452 }
1453
1454
1457 property toInt:Int
1458 function get_toInt():Int {
1459 return Int(value->builtin_int)
1460 }
1461
1462
1465 property asInt16:Int16
1466 function get_asInt16():Int16 {
1467 return Int16(value->builtin_int16)
1468 }
1469
1470
1473 property toInt16:Int16
1474 function get_toInt16():Int16 {
1475 return Int16(value->builtin_int16)
1476 }
1477
1478
1481 property asInt32:Int32
1482 function get_asInt32():Int32 {
1483 return Int32(value->builtin_int32)
1484 }
1485
1486
1489 property toInt32:Int32
1490 function get_toInt32():Int32 {
1491 return Int32(value->builtin_int32)
1492 }
1493
1494
1497 property asInt64:Int64
1498 function get_asInt64():Int64 {
1499 return Int64(value->builtin_int64)
1500 }
1501
1502
1505 property toInt64:Int64
1506 function get_toInt64():Int64 {
1507 return Int64(value->builtin_int64)
1508 }
1509
1510
1514 property asUInt:UInt
1515 function get_asUInt():UInt {
1516 assert self >= UInt.MIN.toInt8, "Int8(\{self}) cannot be safely converted to UInt"
1517 return UInt(value->builtin_uint)
1518 }
1519
1520
1524 property toUInt:UInt
1525 function get_toUInt():UInt {
1526 return UInt(value->builtin_uint)
1527 }
1528
1529
1533 property asUInt8:UInt8
1534 function get_asUInt8():UInt8 {
1535 assert self >= UInt8.MIN.toInt8, "Int8(\{self}) cannot be safely converted to UInt8"
1536 return UInt8(value->builtin_uint8)
1537 }
1538
1539
1543 property toUInt8:UInt8
1544 function get_toUInt8():UInt8 {
1545 return UInt8(value->builtin_uint8)
1546 }
1547
1548
1552 property asUInt16:UInt16
1553 function get_asUInt16():UInt16 {
1554 assert self >= UInt16.MIN.toInt8, "Int8(\{self}) cannot be safely converted to UInt16"
1555 return UInt16(value->builtin_uint16)
1556 }
1557
1558
1562 property toUInt16:UInt16
1563 function get_toUInt16():UInt16 {
1564 return UInt16(value->builtin_uint16)
1565 }
1566
1567
1571 property asUInt32:UInt32
1572 function get_asUInt32():UInt32 {
1573 assert self >= UInt32.MIN.toInt8, "Int8(\{self}) cannot be safely converted to UInt32"
1574 return UInt32(value->builtin_uint32)
1575 }
1576
1577
1581 property toUInt32:UInt32
1582 function get_toUInt32():UInt32 {
1583 return UInt32(value->builtin_uint32)
1584 }
1585
1586
1590 property asUInt64:UInt64
1591 function get_asUInt64():UInt64 {
1592 assert self >= UInt64.MIN.toInt8, "Int8(\{self}) cannot be safely converted to UInt64"
1593 return UInt64(value->builtin_uint64)
1594 }
1595
1596
1600 property toUInt64:UInt64
1601 function get_toUInt64():UInt64 {
1602 return UInt64(value->builtin_uint64)
1603 }
1604
1605
1608 property asReal32:Real32
1609 function get_asReal32():Real32 {
1610 return Real32(value->builtin_float32)
1611 }
1612
1613
1616 property toReal32:Real32
1617 function get_toReal32():Real32 {
1618 return Real32(value->builtin_float32)
1619 }
1620
1621
1624 property asReal64:Real64
1625 function get_asReal64():Real64 {
1626 return Real64(value->builtin_float64)
1627 }
1628
1629
1632 property toReal64:Real64
1633 function get_toReal64():Real64 {
1634 return Real64(value->builtin_float64)
1635 }
1636
1637
1638 @override
1639 function get_toString():String {
1640 constant max := 4
1641 def chars := Pointer<Char8>.alloc(max)
1642 var index := max - 1
1643 var value := self
1644 if value >= 0 {
1645 do {
1646 chars[index] := Char8((value % 10 + 48).asUInt8)
1647 value := (value // 10).asInt8
1648 index -= 1
1649 }
1650 while value > 0
1651 index += 1
1652 }
1653 else {
1654 do {
1655 chars[index] := Char8((48 - value % 10).asUInt8)
1656 value := (value // 10).asInt8
1657 index -= 1
1658 }
1659 while value < 0< 0
1660 chars[index] := "-"
1661 }
1662 def size := max - index
1663 for i in 0 .. size {
1664 chars[i] := chars[i + index]
1665 }
1666 return String(chars, size)
1667 }
1668
1669
1670 @override
1671 function format(fmt:String):String {
1672 return Frost.format(value < 0< 0, abs.toUInt64, 0xFF, fmt)
1673 }
1674 }
1675