@@ -41,7 +41,7 @@ to_bytes :: proc "contextless" (s: []$T) -> []byte {
4141 Turns a byte slice into a type.
4242*/
4343@(require_results)
44- to_type :: proc (buf: []u8 , $T : typeid ) -> (T, bool ) #optional_ok {
44+ to_type :: proc " contextless " (buf: []u8 , $T : typeid ) -> (T, bool ) #optional_ok {
4545 if len (buf) < size_of (T) {
4646 return {}, false
4747 }
@@ -97,23 +97,23 @@ reinterpret :: proc "contextless" ($T: typeid/[]$U, s: []$V) -> []U {
9797}
9898
9999
100- swap :: proc (array: $T /[]$E , a, b: int ) {
100+ swap :: proc " contextless " (array: $T /[]$E , a, b: int ) {
101101 when size_of (E) > 8 {
102102 ptr_swap_non_overlapping (&array[a], &array[b], size_of (E))
103103 } else {
104104 array[a], array[b] = array[b], array[a]
105105 }
106106}
107107
108- swap_between :: proc (a, b: $T /[]$E ) {
108+ swap_between :: proc " contextless " (a, b: $T /[]$E ) {
109109 n := builtin.min (len (a), len (b))
110110 if n >= 0 {
111111 ptr_swap_overlapping (&a[0 ], &b[0 ], size_of (E)*n)
112112 }
113113}
114114
115115
116- reverse :: proc (array: $T /[]$E ) {
116+ reverse :: proc " contextless " (array: $T /[]$E ) {
117117 n := len (array)/2
118118 for i in 0 ..<n {
119119 swap (array, i, len (array)-i-1 )
@@ -122,7 +122,7 @@ reverse :: proc(array: $T/[]$E) {
122122
123123
124124@(require_results)
125- contains :: proc (array: $T /[]$E , value: E) -> bool where intrinsics.type_is_comparable (E) {
125+ contains :: proc " contextless " (array: $T /[]$E , value: E) -> bool where intrinsics.type_is_comparable (E) {
126126 _, found := linear_search (array, value)
127127 return found
128128}
@@ -156,7 +156,7 @@ Example:
156156 assert(index == 1 && found == true)
157157*/
158158@(require_results)
159- linear_search :: proc (array: $A /[]$T , key: T) -> (index: int , found: bool )
159+ linear_search :: proc " contextless " (array: $A /[]$T , key: T) -> (index: int , found: bool )
160160 where intrinsics.type_is_comparable (T) {
161161 for x, i in array {
162162 if x == key {
@@ -219,7 +219,7 @@ Example:
219219 assert(index == 1 && found == true)
220220*/
221221@(require_results)
222- linear_search_reverse :: proc (array: $A /[]$T , key: T) -> (index: int , found: bool )
222+ linear_search_reverse :: proc " contextless " (array: $A /[]$T , key: T) -> (index: int , found: bool )
223223 where intrinsics.type_is_comparable (T) {
224224 #reverse for x, i in array {
225225 if x == key {
@@ -327,7 +327,7 @@ binary_search_by :: proc(array: $A/[]$T, key: $K, f: proc(T, K) -> Ordering) ->
327327}
328328
329329@(require_results)
330- equal :: proc (a, b: $T /[]$E ) -> bool where intrinsics.type_is_comparable (E) #no_bounds_check {
330+ equal :: proc " contextless " (a, b: $T /[]$E ) -> bool where intrinsics.type_is_comparable (E) #no_bounds_check {
331331 if len (a) != len (b) {
332332 return false
333333 }
@@ -355,7 +355,7 @@ equal :: proc(a, b: $T/[]$E) -> bool where intrinsics.type_is_comparable(E) #no_
355355}
356356
357357@(require_results)
358- simple_equal :: proc (a, b: $T /[]$E ) -> bool where intrinsics.type_is_simple_compare (E) {
358+ simple_equal :: proc " contextless " (a, b: $T /[]$E ) -> bool where intrinsics.type_is_simple_compare (E) {
359359 if len (a) != len (b) {
360360 return false
361361 }
@@ -370,7 +370,7 @@ simple_equal :: proc(a, b: $T/[]$E) -> bool where intrinsics.type_is_simple_comp
370370 slice.prefix_length([]u8{1, 2, 3, 4}, []u8{2, 3, 4}) -> 0
371371*/
372372@(require_results)
373- prefix_length :: proc (a, b: $T /[]$E ) -> (n: int ) where intrinsics.type_is_comparable (E) {
373+ prefix_length :: proc " contextless " (a, b: $T /[]$E ) -> (n: int ) where intrinsics.type_is_comparable (E) {
374374 _len := builtin.min (len (a), len (b))
375375
376376 #no_bounds_check for n < _len && a[n] == b[n] {
@@ -380,7 +380,7 @@ prefix_length :: proc(a, b: $T/[]$E) -> (n: int) where intrinsics.type_is_compar
380380}
381381
382382@(require_results)
383- has_prefix :: proc (array: $T /[]$E , needle: T) -> bool where intrinsics.type_is_comparable (E) {
383+ has_prefix :: proc " contextless " (array: $T /[]$E , needle: T) -> bool where intrinsics.type_is_comparable (E) {
384384 n := len (needle)
385385 if len (array) >= n {
386386 return equal (array[:n], needle)
@@ -398,7 +398,7 @@ has_prefix :: proc(array: $T/[]$E, needle: T) -> bool where intrinsics.type_is_c
398398 slice.suffix_length([]u8{3, 4, 5}, []u8{3, 5}) -> 1
399399*/
400400@(require_results)
401- suffix_length :: proc (a, b: $T /[]$E ) -> (n: int ) where intrinsics.type_is_comparable (E) {
401+ suffix_length :: proc " contextless " (a, b: $T /[]$E ) -> (n: int ) where intrinsics.type_is_comparable (E) {
402402 len_a, len_b := len (a), len (b)
403403 _len := builtin.min (len_a, len_b)
404404
@@ -409,7 +409,7 @@ suffix_length :: proc(a, b: $T/[]$E) -> (n: int) where intrinsics.type_is_compar
409409}
410410
411411@(require_results)
412- has_suffix :: proc (array: $T /[]$E , needle: T) -> bool where intrinsics.type_is_comparable (E) {
412+ has_suffix :: proc " contextless " (array: $T /[]$E , needle: T) -> bool where intrinsics.type_is_comparable (E) {
413413 array := array
414414 m, n := len (array), len (needle)
415415 if m >= n {
@@ -418,13 +418,13 @@ has_suffix :: proc(array: $T/[]$E, needle: T) -> bool where intrinsics.type_is_c
418418 return false
419419}
420420
421- zero :: proc (array: $T /[]$E ) #no_bounds_check {
421+ zero :: proc " contextless " (array: $T /[]$E ) #no_bounds_check {
422422 if len (array) > 0 {
423423 intrinsics.mem_zero (raw_data (array), size_of (E)*len (array))
424424 }
425425}
426426
427- fill :: proc (array: $T /[]$E , value: E) #no_bounds_check {
427+ fill :: proc " contextless " (array: $T /[]$E , value: E) #no_bounds_check {
428428 if len (array) <= 0 {
429429 return
430430 }
@@ -434,7 +434,7 @@ fill :: proc(array: $T/[]$E, value: E) #no_bounds_check {
434434 }
435435}
436436
437- rotate_left :: proc (array: $T /[]$E , mid: int ) {
437+ rotate_left :: proc " contextless " (array: $T /[]$E , mid: int ) {
438438 n := len (array)
439439 m := mid %% n
440440 k := n - m
@@ -443,7 +443,7 @@ rotate_left :: proc(array: $T/[]$E, mid: int) {
443443 p := cast (^E)raw_data (array)
444444 ptr_rotate (m, ptr_add (p, m), k)
445445}
446- rotate_right :: proc (array: $T /[]$E , k: int ) {
446+ rotate_right :: proc " contextless " (array: $T /[]$E , k: int ) {
447447 rotate_left (array, -k)
448448}
449449
@@ -502,11 +502,11 @@ into_dynamic :: proc(a: $T/[]$E) -> [dynamic]E {
502502
503503
504504@(require_results)
505- length :: proc (a: $T /[]$E ) -> int {
505+ length :: proc " contextless " (a: $T /[]$E ) -> int {
506506 return len (a)
507507}
508508@(require_results)
509- is_empty :: proc (a: $T /[]$E ) -> bool {
509+ is_empty :: proc " contextless " (a: $T /[]$E ) -> bool {
510510 return len (a) == 0
511511}
512512
@@ -519,56 +519,56 @@ size :: proc "contextless" (a: $T/[]$E) -> int {
519519
520520
521521@(require_results)
522- split_at :: proc (array: $T /[]$E , index: int ) -> (a, b: T) {
522+ split_at :: proc " contextless " (array: $T /[]$E , index: int ) -> (a, b: T) {
523523 return array[:index], array[index:]
524524}
525525
526526
527527@(require_results)
528- split_first :: proc (array: $T /[]$E ) -> (first: E, rest: T) {
528+ split_first :: proc " contextless " (array: $T /[]$E ) -> (first: E, rest: T) {
529529 return array[0 ], array[1 :]
530530}
531531@(require_results)
532- split_last :: proc (array: $T /[]$E ) -> (rest: T, last: E) {
532+ split_last :: proc " contextless " (array: $T /[]$E ) -> (rest: T, last: E) {
533533 n := len (array)-1
534534 return array[:n], array[n]
535535}
536536
537537@(require_results)
538- first :: proc (array: $T /[]$E ) -> E {
538+ first :: proc " contextless " (array: $T /[]$E ) -> E {
539539 return array[0 ]
540540}
541541@(require_results)
542- last :: proc (array: $T /[]$E ) -> E {
542+ last :: proc " contextless " (array: $T /[]$E ) -> E {
543543 return array[len (array)-1 ]
544544}
545545
546546
547547@(require_results)
548- first_ptr :: proc (array: $T /[]$E ) -> ^E {
548+ first_ptr :: proc " contextless " (array: $T /[]$E ) -> ^E {
549549 if len (array) != 0 {
550550 return &array[0 ]
551551 }
552552 return nil
553553}
554554@(require_results)
555- last_ptr :: proc (array: $T /[]$E ) -> ^E {
555+ last_ptr :: proc " contextless " (array: $T /[]$E ) -> ^E {
556556 if len (array) != 0 {
557557 return &array[len (array)-1 ]
558558 }
559559 return nil
560560}
561561
562562@(require_results)
563- get :: proc (array: $T /[]$E , index: int ) -> (value: E, ok: bool ) {
563+ get :: proc " contextless " (array: $T /[]$E , index: int ) -> (value: E, ok: bool ) {
564564 if uint (index) < len (array) {
565565 value = array[index]
566566 ok = true
567567 }
568568 return
569569}
570570@(require_results)
571- get_ptr :: proc (array: $T /[]$E , index: int ) -> (value: ^E, ok: bool ) {
571+ get_ptr :: proc " contextless " (array: $T /[]$E , index: int ) -> (value: ^E, ok: bool ) {
572572 if uint (index) < len (array) {
573573 value = &array[index]
574574 ok = true
@@ -577,7 +577,7 @@ get_ptr :: proc(array: $T/[]$E, index: int) -> (value: ^E, ok: bool) {
577577}
578578
579579@(require_results)
580- as_ptr :: proc (array: $T /[]$E ) -> [^]E {
580+ as_ptr :: proc " contextless " (array: $T /[]$E ) -> [^]E {
581581 return raw_data (array)
582582}
583583
@@ -672,7 +672,7 @@ repeat :: proc(s: $S/[]$U, count: int, allocator := context.allocator) -> (b: S,
672672// 'unique' replaces consecutive runs of equal elements with a single copy.
673673// The procedures modifies the slice in-place and returns the modified slice.
674674@(require_results)
675- unique :: proc (s: $S /[]$T ) -> S where intrinsics.type_is_comparable (T) #no_bounds_check {
675+ unique :: proc " contextless " (s: $S /[]$T ) -> S where intrinsics.type_is_comparable (T) #no_bounds_check {
676676 if len (s) < 2 {
677677 return s
678678 }
@@ -711,7 +711,7 @@ unique_proc :: proc(s: $S/[]$T, eq: proc(T, T) -> bool) -> S #no_bounds_check {
711711
712712
713713@(require_results)
714- min :: proc (s: $S /[]$T ) -> (res: T, ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
714+ min :: proc " contextless " (s: $S /[]$T ) -> (res: T, ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
715715 if len (s) != 0 {
716716 res = s[0 ]
717717 ok = true
@@ -722,7 +722,7 @@ min :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T
722722 return
723723}
724724@(require_results)
725- max :: proc (s: $S /[]$T ) -> (res: T, ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
725+ max :: proc " contextless " (s: $S /[]$T ) -> (res: T, ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
726726 if len (s) != 0 {
727727 res = s[0 ]
728728 ok = true
@@ -734,7 +734,7 @@ max :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T
734734}
735735
736736@(require_results)
737- min_max :: proc (s: $S /[]$T ) -> (min, max: T, ok: bool ) where intrinsics.type_is_ordered (T) {
737+ min_max :: proc " contextless " (s: $S /[]$T ) -> (min, max: T, ok: bool ) where intrinsics.type_is_ordered (T) {
738738 if len (s) != 0 {
739739 min, max = s[0 ], s[0 ]
740740 ok = true
@@ -748,7 +748,7 @@ min_max :: proc(s: $S/[]$T) -> (min, max: T, ok: bool) where intrinsics.type_is_
748748
749749// Find the index of the (first) minimum element in a slice.
750750@(require_results)
751- min_index :: proc (s: $S /[]$T ) -> (min_index: int , ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
751+ min_index :: proc " contextless " (s: $S /[]$T ) -> (min_index: int , ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
752752 if len (s) == 0 {
753753 return -1 , false
754754 }
@@ -765,7 +765,7 @@ min_index :: proc(s: $S/[]$T) -> (min_index: int, ok: bool) where intrinsics.typ
765765
766766// Find the index of the (first) maximum element in a slice.
767767@(require_results)
768- max_index :: proc (s: $S /[]$T ) -> (max_index: int , ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
768+ max_index :: proc " contextless " (s: $S /[]$T ) -> (max_index: int , ok: bool ) where intrinsics.type_is_ordered (T) #optional_ok {
769769 if len (s) == 0 {
770770 return -1 , false
771771 }
@@ -781,7 +781,7 @@ max_index :: proc(s: $S/[]$T) -> (max_index: int, ok: bool) where intrinsics.typ
781781}
782782
783783@(require_results)
784- any_of :: proc (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
784+ any_of :: proc " contextless " (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
785785 for v in s {
786786 if v == value {
787787 return true
@@ -791,7 +791,7 @@ any_of :: proc(s: $S/[]$T, value: T) -> bool where intrinsics.type_is_comparable
791791}
792792
793793@(require_results)
794- none_of :: proc (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
794+ none_of :: proc " contextless " (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
795795 for v in s {
796796 if v == value {
797797 return false
@@ -801,7 +801,7 @@ none_of :: proc(s: $S/[]$T, value: T) -> bool where intrinsics.type_is_comparabl
801801}
802802
803803@(require_results)
804- all_of :: proc (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
804+ all_of :: proc " contextless " (s: $S /[]$T , value: T) -> bool where intrinsics.type_is_comparable (T) {
805805 if len (s) == 0 {
806806 return false
807807 }
@@ -849,7 +849,7 @@ all_of_proc :: proc(s: $S/[]$T, f: proc(T) -> bool) -> bool {
849849
850850
851851@(require_results)
852- count :: proc (s: $S /[]$T , value: T) -> (n: int ) where intrinsics.type_is_comparable (T) {
852+ count :: proc " contextless " (s: $S /[]$T , value: T) -> (n: int ) where intrinsics.type_is_comparable (T) {
853853 for v in s {
854854 if v == value {
855855 n += 1
@@ -870,7 +870,7 @@ count_proc :: proc(s: $S/[]$T, f: proc(T) -> bool) -> (n: int) {
870870
871871
872872@(require_results)
873- dot_product :: proc (a, b: $S /[]$T ) -> (r: T, ok: bool )
873+ dot_product :: proc " contextless " (a, b: $S /[]$T ) -> (r: T, ok: bool )
874874 where intrinsics.type_is_numeric (T) {
875875 if len (a) != len (b) {
876876 return
@@ -884,7 +884,7 @@ dot_product :: proc(a, b: $S/[]$T) -> (r: T, ok: bool)
884884
885885// Convert a pointer to an enumerated array to a slice of the element type
886886@(require_results)
887- enumerated_array :: proc (ptr: ^$T ) -> []intrinsics.type_elem_type (T)
887+ enumerated_array :: proc " contextless " (ptr: ^$T ) -> []intrinsics.type_elem_type (T)
888888 where intrinsics.type_is_enumerated_array (T) {
889889 return ([^]intrinsics.type_elem_type (T))(ptr)[:len (T)]
890890}
@@ -893,7 +893,7 @@ enumerated_array :: proc(ptr: ^$T) -> []intrinsics.type_elem_type(T)
893893// e.g.:
894894// bs := slice.enum_slice_to_bitset(my_flag_slice, rl.ConfigFlags)
895895@(require_results)
896- enum_slice_to_bitset :: proc (enums: []$E , $T : typeid /bit_set [E]) -> (bits: T) where intrinsics.type_is_enum (E), intrinsics.type_bit_set_elem_type (T) == E {
896+ enum_slice_to_bitset :: proc " contextless " (enums: []$E , $T : typeid /bit_set [E]) -> (bits: T) where intrinsics.type_is_enum (E), intrinsics.type_bit_set_elem_type (T) == E {
897897 for v in enums {
898898 bits += {v}
899899 }
@@ -904,7 +904,7 @@ enum_slice_to_bitset :: proc(enums: []$E, $T: typeid/bit_set[E]) -> (bits: T) wh
904904// e.g.:
905905// sl := slice.bitset_to_enum_slice(flag_buf[:], bs)
906906@(require_results)
907- bitset_to_enum_slice_with_buffer :: proc (buf: []$E , bs: $T ) -> (slice: []E) where intrinsics.type_is_enum (E), intrinsics.type_bit_set_elem_type (T) == E {
907+ bitset_to_enum_slice_with_buffer :: proc " contextless " (buf: []$E , bs: $T ) -> (slice: []E) where intrinsics.type_is_enum (E), intrinsics.type_bit_set_elem_type (T) == E {
908908 count := 0
909909 for v in bs {
910910 buf[count] = v
0 commit comments