From 12eea4a98db166d3489cbf20490809e07c6eea45 Mon Sep 17 00:00:00 2001 From: BWindey <93756910+BWindey@users.noreply.github.com> Date: Thu, 18 Sep 2025 14:06:58 +0200 Subject: [PATCH] [STDLIB] Add macro return types (#2487) * add return types to macros where applicable * std::time::clock::now() -> clock::now() --- lib/std/collections/elastic_array.c3 | 4 +- lib/std/collections/hashmap.c3 | 2 +- lib/std/collections/linked_hashmap.c3 | 44 +++++++++--------- lib/std/collections/linked_hashset.c3 | 64 +++++++++++++-------------- lib/std/collections/list.c3 | 2 +- lib/std/core/array.c3 | 12 ++--- lib/std/core/bitorder.c3 | 4 +- lib/std/core/builtin.c3 | 8 ++-- lib/std/core/builtin_comparison.c3 | 8 ++-- lib/std/core/mem.c3 | 1 + lib/std/core/runtime_benchmark.c3 | 10 ++--- lib/std/core/sanitizer/asan.c3 | 12 ++--- lib/std/hash/a5hash.c3 | 2 +- lib/std/hash/hmac.c3 | 4 +- lib/std/hash/komi.c3 | 2 +- lib/std/hash/md5.c3 | 2 +- lib/std/hash/sha1.c3 | 16 +++---- lib/std/io/formatter_private.c3 | 2 +- lib/std/io/stream/bytebuffer.c3 | 2 +- lib/std/math/math.c3 | 10 ++--- lib/std/math/random.c3 | 4 +- lib/std/math/vector.c3 | 28 ++++++------ lib/std/net/socket_private.c3 | 4 +- lib/std/sort/countingsort.c3 | 12 ++--- lib/std/sort/insertionsort.c3 | 2 +- lib/std/sort/quicksort.c3 | 4 +- 26 files changed, 133 insertions(+), 132 deletions(-) diff --git a/lib/std/collections/elastic_array.c3 b/lib/std/collections/elastic_array.c3 index aabc41e81..176d64eec 100644 --- a/lib/std/collections/elastic_array.c3 +++ b/lib/std/collections/elastic_array.c3 @@ -11,7 +11,7 @@ alias ElementPredicate = fn bool(Type *type); alias ElementTest = fn bool(Type *type, any context); const ELEMENT_IS_EQUATABLE = types::is_equatable_type(Type); const ELEMENT_IS_POINTER = Type.kindof == POINTER; -macro type_is_overaligned() => Type.alignof > mem::DEFAULT_MEM_ALIGNMENT; +macro bool type_is_overaligned() => Type.alignof > mem::DEFAULT_MEM_ALIGNMENT; struct ElasticArray (Printable) { @@ -458,4 +458,4 @@ fn usz ElasticArray.compact_count(&self) @if(ELEMENT_IS_POINTER) fn usz ElasticArray.compact(&self) @if(ELEMENT_IS_POINTER) { return list_common::list_compact(self); -} \ No newline at end of file +} diff --git a/lib/std/collections/hashmap.c3 b/lib/std/collections/hashmap.c3 index cdcf9c895..f5625a34f 100644 --- a/lib/std/collections/hashmap.c3 +++ b/lib/std/collections/hashmap.c3 @@ -605,4 +605,4 @@ macro uint index_for(uint hash, uint capacity) @private return hash & (capacity - 1); } -int dummy @local; \ No newline at end of file +int dummy @local; diff --git a/lib/std/collections/linked_hashmap.c3 b/lib/std/collections/linked_hashmap.c3 index 91e3aabdf..a802ca811 100644 --- a/lib/std/collections/linked_hashmap.c3 +++ b/lib/std/collections/linked_hashmap.c3 @@ -249,7 +249,7 @@ fn void? LinkedHashMap.remove(&map, Key key) @maydiscard fn void LinkedHashMap.clear(&map) { if (!map.count) return; - + LinkedEntry* entry = map.head; while (entry) { @@ -257,12 +257,12 @@ fn void LinkedHashMap.clear(&map) map.free_entry(entry); entry = next; } - + foreach (LinkedEntry** &bucket : map.table) { *bucket = null; } - + map.count = 0; map.head = null; map.tail = null; @@ -284,10 +284,10 @@ fn Key[] LinkedHashMap.tkeys(&self) fn Key[] LinkedHashMap.keys(&self, Allocator allocator) { if (!self.count) return {}; - + Key[] list = allocator::alloc_array(allocator, Key, self.count); usz index = 0; - + LinkedEntry* entry = self.head; while (entry) { @@ -338,7 +338,7 @@ fn Value[] LinkedHashMap.values(&self, Allocator allocator) fn bool LinkedHashMap.has_value(&map, Value v) @if(VALUE_IS_EQUATABLE) { if (!map.count) return false; - + LinkedEntry* entry = map.head; while (entry) { @@ -396,7 +396,7 @@ fn void LinkedHashMap.add_entry(&map, uint hash, Key key, Value value, uint buck $if COPY_KEYS: key = key.copy(map.allocator); $endif - + LinkedEntry* entry = allocator::new(map.allocator, LinkedEntry, { .hash = hash, .key = key, @@ -405,10 +405,10 @@ fn void LinkedHashMap.add_entry(&map, uint hash, Key key, Value value, uint buck .before = map.tail, .after = null }); - + // Update bucket chain map.table[bucket_index] = entry; - + // Update linked list if (map.tail) { @@ -420,7 +420,7 @@ fn void LinkedHashMap.add_entry(&map, uint hash, Key key, Value value, uint buck map.head = entry; } map.tail = entry; - + if (map.count++ >= map.threshold) { map.resize(map.table.len * 2); @@ -431,28 +431,28 @@ fn void LinkedHashMap.resize(&map, uint new_capacity) @private { LinkedEntry*[] old_table = map.table; uint old_capacity = old_table.len; - + if (old_capacity == MAXIMUM_CAPACITY) { map.threshold = uint.max; return; } - + LinkedEntry*[] new_table = allocator::new_array(map.allocator, LinkedEntry*, new_capacity); map.table = new_table; map.threshold = (uint)(new_capacity * map.load_factor); - + // Rehash all entries - linked list order remains unchanged foreach (uint i, LinkedEntry *e : old_table) { if (!e) continue; - + // Split the bucket chain into two chains based on new bit LinkedEntry* lo_head = null; LinkedEntry* lo_tail = null; LinkedEntry* hi_head = null; LinkedEntry* hi_tail = null; - + do { LinkedEntry* next = e.next; @@ -484,7 +484,7 @@ fn void LinkedHashMap.resize(&map, uint new_capacity) @private e = next; } while (e); - + if (lo_tail) { lo_tail.next = null; @@ -496,7 +496,7 @@ fn void LinkedHashMap.resize(&map, uint new_capacity) @private new_table[i + old_capacity] = hi_head; } } - + map.free_internal(old_table.ptr); } @@ -562,12 +562,12 @@ fn void LinkedHashMap.free_internal(&map, void* ptr) @inline @private fn bool LinkedHashMap.remove_entry_for_key(&map, Key key) @private { if (!map.count) return false; - + uint hash = rehash(key.hash()); uint i = index_for(hash, map.table.len); LinkedEntry* prev = null; LinkedEntry* e = map.table[i]; - + while (e) { if (e.hash == hash && equals(key, e.key)) @@ -580,7 +580,7 @@ fn bool LinkedHashMap.remove_entry_for_key(&map, Key key) @private { map.table[i] = e.next; } - + if (e.before) { e.before.after = e.after; @@ -589,7 +589,7 @@ fn bool LinkedHashMap.remove_entry_for_key(&map, Key key) @private { map.head = e.after; } - + if (e.after) { e.after.before = e.before; @@ -598,7 +598,7 @@ fn bool LinkedHashMap.remove_entry_for_key(&map, Key key) @private { map.tail = e.before; } - + map.count--; map.free_entry(e); return true; diff --git a/lib/std/collections/linked_hashset.c3 b/lib/std/collections/linked_hashset.c3 index 635fec1b8..30fbd9716 100644 --- a/lib/std/collections/linked_hashset.c3 +++ b/lib/std/collections/linked_hashset.c3 @@ -43,7 +43,7 @@ fn LinkedHashSet* LinkedHashSet.init(&self, Allocator allocator, usz capacity = self.threshold = (usz)(capacity * load_factor); self.load_factor = load_factor; self.table = allocator::new_array(allocator, LinkedEntry*, capacity); - + self.head = null; self.tail = null; return self; @@ -304,7 +304,7 @@ fn void LinkedHashSet.free(&set) fn void LinkedHashSet.clear(&set) { if (!set.count) return; - + LinkedEntry* entry = set.head; while (entry) { @@ -312,12 +312,12 @@ fn void LinkedHashSet.clear(&set) set.free_entry(entry); entry = next; } - + foreach (LinkedEntry** &bucket : set.table) { *bucket = null; } - + set.count = 0; set.head = null; set.tail = null; @@ -363,16 +363,16 @@ fn LinkedHashSet LinkedHashSet.intersection(&self, Allocator allocator, LinkedHa { LinkedHashSet result; result.init(allocator, math::min(self.table.len, other.table.len), self.load_factor); - + // Iterate through the smaller set for efficiency LinkedHashSet* smaller = self.count <= other.count ? self : other; LinkedHashSet* larger = self.count > other.count ? self : other; - - smaller.@each(;Value value) + + smaller.@each(;Value value) { if (larger.contains(value)) result.add(value); }; - + return result; } @@ -435,7 +435,7 @@ fn bool LinkedHashSet.is_subset(&self, LinkedHashSet* other) { if (self.count == 0) return true; if (self.count > other.count) return false; - + self.@each(; Value value) { if (!other.contains(value)) return false; }; @@ -453,10 +453,10 @@ fn void LinkedHashSet.add_entry(&set, uint hash, Value value, uint bucket_index) .before = set.tail, .after = null }); - + // Update bucket chain set.table[bucket_index] = entry; - + // Update linked list if (set.tail) { @@ -468,7 +468,7 @@ fn void LinkedHashSet.add_entry(&set, uint hash, Value value, uint bucket_index) set.head = entry; } set.tail = entry; - + if (set.count++ >= set.threshold) { set.resize(set.table.len * 2); @@ -479,28 +479,28 @@ fn void LinkedHashSet.resize(&set, usz new_capacity) @private { LinkedEntry*[] old_table = set.table; usz old_capacity = old_table.len; - + if (old_capacity == MAXIMUM_CAPACITY) { set.threshold = uint.max; return; } - + LinkedEntry*[] new_table = allocator::new_array(set.allocator, LinkedEntry*, new_capacity); set.table = new_table; set.threshold = (uint)(new_capacity * set.load_factor); - + // Rehash all entries - linked list order remains unchanged foreach (uint i, LinkedEntry *e : old_table) { if (!e) continue; - + // Split the bucket chain into two chains based on new bit LinkedEntry* lo_head = null; LinkedEntry* lo_tail = null; LinkedEntry* hi_head = null; LinkedEntry* hi_tail = null; - + do { LinkedEntry* next = e.next; @@ -532,7 +532,7 @@ fn void LinkedHashSet.resize(&set, usz new_capacity) @private e = next; } while (e); - + if (lo_tail) { lo_tail.next = null; @@ -544,7 +544,7 @@ fn void LinkedHashSet.resize(&set, usz new_capacity) @private new_table[i + old_capacity] = hi_head; } } - + set.free_internal(old_table.ptr); } @@ -601,16 +601,16 @@ fn void LinkedHashSet.free_internal(&set, void* ptr) @inline @private fn void LinkedHashSet.create_entry(&set, uint hash, Value value, int bucket_index) @private { - LinkedEntry* entry = allocator::new(set.allocator, LinkedEntry, { - .hash = hash, - .value = value, + LinkedEntry* entry = allocator::new(set.allocator, LinkedEntry, { + .hash = hash, + .value = value, .next = set.table[bucket_index], .before = set.tail, .after = null }); - + set.table[bucket_index] = entry; - + // Update linked list if (set.tail) { @@ -622,19 +622,19 @@ fn void LinkedHashSet.create_entry(&set, uint hash, Value value, int bucket_inde set.head = entry; } set.tail = entry; - + set.count++; } fn bool LinkedHashSet.remove_entry_for_value(&set, Value value) @private { if (!set.count) return false; - + uint hash = rehash(value.hash()); uint i = index_for(hash, set.table.len); LinkedEntry* prev = null; LinkedEntry* e = set.table[i]; - + while (e) { if (e.hash == hash && equals(value, e.value)) @@ -647,7 +647,7 @@ fn bool LinkedHashSet.remove_entry_for_value(&set, Value value) @private { set.table[i] = e.next; } - + if (e.before) { e.before.after = e.after; @@ -656,7 +656,7 @@ fn bool LinkedHashSet.remove_entry_for_value(&set, Value value) @private { set.head = e.after; } - + if (e.after) { e.after.before = e.before; @@ -665,7 +665,7 @@ fn bool LinkedHashSet.remove_entry_for_value(&set, Value value) @private { set.tail = e.before; } - + set.count--; set.free_entry(e); return true; @@ -715,9 +715,9 @@ fn bool LinkedHashSetIterator.has_next(&self) return self.current && self.current.after != null; } -fn usz LinkedHashSetIterator.len(&self) @operator(len) +fn usz LinkedHashSetIterator.len(&self) @operator(len) { return self.set.count; } -int dummy @local; \ No newline at end of file +int dummy @local; diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 531bd6850..f4189b219 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -13,7 +13,7 @@ const Allocator LIST_HEAP_ALLOCATOR = (Allocator)&dummy; const List ONHEAP = { .allocator = LIST_HEAP_ALLOCATOR }; -macro type_is_overaligned() => Type.alignof > mem::DEFAULT_MEM_ALIGNMENT; +macro bool type_is_overaligned() => Type.alignof > mem::DEFAULT_MEM_ALIGNMENT; struct List (Printable) { diff --git a/lib/std/core/array.c3 b/lib/std/core/array.c3 index 0177c754d..294d4a470 100644 --- a/lib/std/core/array.c3 +++ b/lib/std/core/array.c3 @@ -3,7 +3,7 @@ import std::collections::pair, std::io; <* Returns true if the array contains at least one element, else false - + @param [in] array @param [in] element @require $kindof(array) == SLICE || $kindof(array) == ARRAY @@ -15,13 +15,13 @@ macro bool contains(array, element) { if (*item == element) return true; } - return false; + return false; } <* Return the first index of element found in the array, searching from the start. - + @param [in] array @param [in] element @require $kindof(array) == SLICE || $kindof(array) == ARRAY @@ -29,7 +29,7 @@ macro bool contains(array, element) @return "the first index of the element" @return? NOT_FOUND *> -macro index_of(array, element) +macro usz? index_of(array, element) { foreach (i, &e : array) { @@ -63,13 +63,13 @@ macro slice2d(array_ptr, x = 0, xlen = 0, y = 0, ylen = 0) <* Return the first index of element found in the array, searching in reverse from the end. - + @param [in] array @param [in] element @return "the last index of the element" @return? NOT_FOUND *> -macro rindex_of(array, element) +macro usz? rindex_of(array, element) { foreach_r (i, &e : array) { diff --git a/lib/std/core/bitorder.c3 b/lib/std/core/bitorder.c3 index f396d52f5..1aa2213db 100644 --- a/lib/std/core/bitorder.c3 +++ b/lib/std/core/bitorder.c3 @@ -119,7 +119,7 @@ macro write(x, bytes, $Type) *($typeof(x)*)s.ptr = bitcast(x, $Type).val; } -macro is_bitorder($Type) +macro bool is_bitorder($Type) { $switch $Type: $case UShortLE: @@ -181,4 +181,4 @@ macro bool @is_arrayptr_or_slice_of_char(#bytes) @const $default: return false; $endswitch -} \ No newline at end of file +} diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index 8c52ea71f..dc0d430c3 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -27,8 +27,8 @@ macro foo(a, #b = EMPTY_MACRO_SLOT) const EmptySlot EMPTY_MACRO_SLOT @builtin = null; typedef EmptySlot = void*; -macro @is_empty_macro_slot(#arg) @const @builtin => $typeof(#arg) == EmptySlot; -macro @is_valid_macro_slot(#arg) @const @builtin => $typeof(#arg) != EmptySlot; +macro bool @is_empty_macro_slot(#arg) @const @builtin => $typeof(#arg) == EmptySlot; +macro bool @is_valid_macro_slot(#arg) @const @builtin => $typeof(#arg) != EmptySlot; <* Returns a random value at compile time. @@ -430,7 +430,7 @@ macro swizzle2(v, v2, ...) @builtin @require types::is_int($typeof($value)) : "Input value must be an integer" @require $sizeof($value) * 8 <= 128 : "Input value must be 128 bits wide or lower" *> -macro @clz($value) @builtin @const +macro uint @clz($value) @builtin @const { $if $value == 0: return $sizeof($value) * 8; // it's all leading zeroes @@ -556,7 +556,7 @@ macro @generic_hash_core(h, value) return h; } -macro @generic_hash(value) +macro uint @generic_hash(value) { uint h = @generic_hash_core((uint)0x3efd4391, value); $for var $cnt = 4; $cnt < $sizeof(value); $cnt += 4: diff --git a/lib/std/core/builtin_comparison.c3 b/lib/std/core/builtin_comparison.c3 index 5dbbb7009..9687d6fdb 100644 --- a/lib/std/core/builtin_comparison.c3 +++ b/lib/std/core/builtin_comparison.c3 @@ -6,7 +6,7 @@ module std::core::builtin; <* @require types::@comparable_value(a) && types::@comparable_value(b) *> -macro less(a, b) @builtin +macro bool less(a, b) @builtin { $switch: $case $defined(a.less): @@ -21,7 +21,7 @@ macro less(a, b) @builtin <* @require types::@comparable_value(a) && types::@comparable_value(b) *> -macro less_eq(a, b) @builtin +macro bool less_eq(a, b) @builtin { $switch: $case $defined(a.less): @@ -36,7 +36,7 @@ macro less_eq(a, b) @builtin <* @require types::@comparable_value(a) && types::@comparable_value(b) *> -macro greater(a, b) @builtin +macro bool greater(a, b) @builtin { $switch: $case $defined(a.less): @@ -65,7 +65,7 @@ macro int compare_to(a, b) @builtin <* @require types::@comparable_value(a) && types::@comparable_value(b) *> -macro greater_eq(a, b) @builtin +macro bool greater_eq(a, b) @builtin { $switch: $case $defined(a.less): diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index b537fdd5c..c6c098aa2 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -72,6 +72,7 @@ macro masked_load(ptr, bool[<*>] mask, passthru) @require @constant_is_power_of_2($alignment) : "The alignment must be a power of two" @return "A vector with the loaded values where the mask is true, passthru where the mask is false" + @ensure $typeof(return) == $typeof(*ptr) *> macro @masked_load_aligned(ptr, bool[<*>] mask, passthru, usz $alignment) { diff --git a/lib/std/core/runtime_benchmark.c3 b/lib/std/core/runtime_benchmark.c3 index 0ca6dcc9b..b8abc1a8b 100644 --- a/lib/std/core/runtime_benchmark.c3 +++ b/lib/std/core/runtime_benchmark.c3 @@ -58,25 +58,25 @@ bool benchmark_warming @local; uint this_iteration @local; bool benchmark_stop @local; -macro @start_benchmark() +macro void @start_benchmark() { - benchmark_clock = std::time::clock::now(); + benchmark_clock = clock::now(); cycle_start = $$sysclock(); } -macro @end_benchmark() +macro void @end_benchmark() { benchmark_nano_seconds = benchmark_clock.mark(); cycle_stop = $$sysclock(); } -macro @kill_benchmark(String format, ...) +macro void @kill_benchmark(String format, ...) { @log_benchmark(format, $vasplat); benchmark_stop = true; } -macro @log_benchmark(msg, args...) => @pool() +macro void @log_benchmark(msg, args...) => @pool() { if (benchmark_warming) return; diff --git a/lib/std/core/sanitizer/asan.c3 b/lib/std/core/sanitizer/asan.c3 index 73c8866e4..20842ffb7 100644 --- a/lib/std/core/sanitizer/asan.c3 +++ b/lib/std/core/sanitizer/asan.c3 @@ -29,11 +29,11 @@ alias ErrorCallback = fn void (ZString); @param addr : "Start of memory region." @param size : "Size of memory region." *> -macro poison_memory_region(void* addr, usz size) +macro void poison_memory_region(void* addr, usz size) { - $if env::ADDRESS_SANITIZER: + $if env::ADDRESS_SANITIZER: __asan_poison_memory_region(addr, size); - $endif + $endif } <* @@ -50,11 +50,11 @@ macro poison_memory_region(void* addr, usz size) @param addr : "Start of memory region." @param size : "Size of memory region." *> -macro unpoison_memory_region(void* addr, usz size) +macro void unpoison_memory_region(void* addr, usz size) { - $if env::ADDRESS_SANITIZER: + $if env::ADDRESS_SANITIZER: __asan_unpoison_memory_region(addr, size); - $endif + $endif } <* diff --git a/lib/std/hash/a5hash.c3 b/lib/std/hash/a5hash.c3 index 6107962c6..c40a8b906 100644 --- a/lib/std/hash/a5hash.c3 +++ b/lib/std/hash/a5hash.c3 @@ -33,7 +33,7 @@ module std::hash::a5hash; -macro @a5mul(#u, #v, #lo, #hi) @local +macro void @a5mul(#u, #v, #lo, #hi) @local { uint128 imd = (uint128)#u * (uint128)#v; #lo = (ulong)imd; diff --git a/lib/std/hash/hmac.c3 b/lib/std/hash/hmac.c3 index dd601f9da..657868eae 100644 --- a/lib/std/hash/hmac.c3 +++ b/lib/std/hash/hmac.c3 @@ -83,7 +83,7 @@ fn char[HASH_BYTES] Hmac.final(&self) const IPAD @private = 0x36; const OPAD @private = 0x5C; -macro @derive(Hmac *hmac_start, char[] salt, uint iterations, usz index, char[] out) +macro void @derive(Hmac *hmac_start, char[] salt, uint iterations, usz index, char[] out) { assert(out.len == HASH_BYTES); char[HASH_BYTES] tmp @noinit; @@ -104,4 +104,4 @@ macro @derive(Hmac *hmac_start, char[] salt, uint iterations, usz index, char[] out[i] ^= v; } } -} \ No newline at end of file +} diff --git a/lib/std/hash/komi.c3 b/lib/std/hash/komi.c3 index d48ea2b27..4ed43185f 100644 --- a/lib/std/hash/komi.c3 +++ b/lib/std/hash/komi.c3 @@ -33,7 +33,7 @@ module std::hash::komi; -macro @komimul(#u, #v, #lo, #hi) @local +macro void @komimul(#u, #v, #lo, #hi) @local { uint128 imd = (uint128)#u * (uint128)#v; #lo = (ulong)imd; diff --git a/lib/std/hash/md5.c3 b/lib/std/hash/md5.c3 index 31823e0f3..47b686686 100644 --- a/lib/std/hash/md5.c3 +++ b/lib/std/hash/md5.c3 @@ -106,7 +106,7 @@ macro @h(x, y, z) => (x ^ y) ^ z; macro @h2(x, y, z) => x ^ (y ^ z); macro @i(x, y, z) => y ^ (x | ~z); -macro @step(#f, a, b, c, d, ptr, n, t, s) +macro void @step(#f, a, b, c, d, ptr, n, t, s) { *a += #f(b, c, d) + @unaligned_load(*(uint *)&ptr[n * 4], 2) + t; *a = (*a << s) | ((*a & 0xffffffff) >> (32 - s)); diff --git a/lib/std/hash/sha1.c3 b/lib/std/hash/sha1.c3 index b4afade06..2bc7cab8f 100644 --- a/lib/std/hash/sha1.c3 +++ b/lib/std/hash/sha1.c3 @@ -103,13 +103,13 @@ union Long16 @local uint[16] l; } -macro blk(Long16* block, i) @local +macro uint blk(Long16* block, i) @local { return (block.l[i & 15] = (block.l[(i + 13) & 15] ^ block.l[(i + 8) & 15] ^ block.l[(i + 2) & 15] ^ block.l[i & 15]).rotl(1)); } -macro blk0(Long16* block, i) @local +macro uint blk0(Long16* block, i) @local { $if env::BIG_ENDIAN: return block.l[i]; @@ -119,35 +119,35 @@ macro blk0(Long16* block, i) @local $endif } -macro r0(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local +macro void r0(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local { var w = *wref; *z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + v.rotl(5); *wref = w.rotl(30); } -macro r1(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local +macro void r1(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local { var w = *wref; *z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + v.rotl(5); *wref = w.rotl(30); } -macro r2(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local +macro void r2(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local { var w = *wref; *z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + v.rotl(5); *wref = w.rotl(30); } -macro r3(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local +macro void r3(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local { var w = *wref; *z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + v.rotl(5); *wref = w.rotl(30); } -macro r4(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local +macro void r4(Long16* block, uint v, uint* wref, uint x, uint y, uint* z, uint i) @local { var w = *wref; *z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + v.rotl(5); @@ -254,4 +254,4 @@ fn void sha1_transform(uint[5]* state, char* buffer) @local (*state)[4] += e; a = b = c = d = e = 0; block = {}; -} \ No newline at end of file +} diff --git a/lib/std/io/formatter_private.c3 b/lib/std/io/formatter_private.c3 index 1080f447c..0c9718a36 100644 --- a/lib/std/io/formatter_private.c3 +++ b/lib/std/io/formatter_private.c3 @@ -22,7 +22,7 @@ fn usz? print_hex_chars(Formatter* f, char[] out, bool uppercase) @inline return len; } -macro Formatter.first_err(&self, fault f) +macro fault Formatter.first_err(&self, fault f) { if (self.first_fault) return self.first_fault; self.first_fault = f; diff --git a/lib/std/io/stream/bytebuffer.c3 b/lib/std/io/stream/bytebuffer.c3 index 8335e9eaa..e550befdf 100644 --- a/lib/std/io/stream/bytebuffer.c3 +++ b/lib/std/io/stream/bytebuffer.c3 @@ -135,7 +135,7 @@ fn void ByteBuffer.grow(&self, usz n) self.bytes = p[:n]; } -macro ByteBuffer.shrink(&self) +macro void ByteBuffer.shrink(&self) { if (self.read_idx >= self.max_read) { diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index a6350cea3..48c551803 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -82,7 +82,7 @@ macro abs(x) => $$abs(x); @require values::@is_int(x) || values::@is_float(x) : "Expected an integer or floating point value" @require values::@is_int(y) || values::@is_float(y) : "Expected an integer or floating point value" *> -macro is_approx(x, y, eps) +macro bool is_approx(x, y, eps) { if (x == y) return true; if (is_nan(x) || is_nan(y)) return false; @@ -93,7 +93,7 @@ macro is_approx(x, y, eps) @require values::@is_int(x) || values::@is_float(x) : "Expected an integer or floating point value" @require values::@is_int(y) || values::@is_float(y) : "Expected an integer or floating point value" *> -macro is_approx_rel(x, y, eps) +macro bool is_approx_rel(x, y, eps) { if (x == y) return true; if (is_nan(x) || is_nan(y)) return false; @@ -132,7 +132,7 @@ macro atan2(x, y) @require @typematch(sinp, cosp) : "Expected sinp and cosp to have the same type" @require $defined(*sinp = x) : "Expected x and *sinp/*cosp to have the same type" *> -macro sincos_ref(x, sinp, cosp) +macro void sincos_ref(x, sinp, cosp) { $if $typeof(sinp) == float*: _sincosf(x, sinp, cosp); @@ -540,7 +540,7 @@ macro bool is_finite(x) <* @require values::@is_promotable_to_float(x) : `The input must be a float` *> -macro is_nan(x) +macro bool is_nan(x) { $switch $typeof(x): $case float: @@ -554,7 +554,7 @@ macro is_nan(x) <* @require values::@is_promotable_to_float(x) : `The input must be a float` *> -macro is_inf(x) +macro bool is_inf(x) { $switch $typeof(x): $case float: diff --git a/lib/std/math/random.c3 b/lib/std/math/random.c3 index 43abacf1b..b61d70a85 100644 --- a/lib/std/math/random.c3 +++ b/lib/std/math/random.c3 @@ -140,7 +140,7 @@ macro ulong @int_to_long(#function) => (ulong)#function << 32 + #function; macro uint @short_to_int(#function) => (uint)#function << 16 + #function; macro ushort @char_to_short(#function) => (ushort)#function << 8 + #function; -macro @random_value_to_bytes(#function, char[] bytes) +macro void @random_value_to_bytes(#function, char[] bytes) { var $byte_size = $sizeof(#function()); usz len = bytes.len; @@ -174,7 +174,7 @@ interface Random } -macro init_default_random() @private +macro void init_default_random() @private { if (!default_random_initialized) { diff --git a/lib/std/math/vector.c3 b/lib/std/math/vector.c3 index 52c964da9..81e162da2 100644 --- a/lib/std/math/vector.c3 +++ b/lib/std/math/vector.c3 @@ -3,25 +3,25 @@ module std::math::vector; import std::math; -macro double[<*>].sq_magnitude(self) => self.dot(self); -macro float[<*>].sq_magnitude(self) => self.dot(self); +macro double double[<*>].sq_magnitude(self) => self.dot(self); +macro float float[<*>].sq_magnitude(self) => self.dot(self); -macro double[<*>].distance_sq(self, double[<*>] v2) => (self - v2).sq_magnitude(); -macro float[<*>].distance_sq(self, float[<*>] v2) => (self - v2).sq_magnitude(); +macro double double[<*>].distance_sq(self, double[<*>] v2) => (self - v2).sq_magnitude(); +macro float float[<*>].distance_sq(self, float[<*>] v2) => (self - v2).sq_magnitude(); -macro float[<2>].transform(self, Matrix4f mat) => transform2(self, mat); -macro float[<2>].rotate(self, float angle) => rotate(self, angle); -macro float[<2>].angle(self, float[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x); +macro float[<2>] float[<2>].transform(self, Matrix4f mat) => transform2(self, mat); +macro float[<2>] float[<2>].rotate(self, float angle) => rotate(self, angle); +macro float[<2>] float[<2>].angle(self, float[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x); -macro double[<2>].transform(self, Matrix4 mat) => transform2(self, mat); -macro double[<2>].rotate(self, double angle) => rotate(self, angle); -macro double[<2>].angle(self, double[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x); +macro double[<2>] double[<2>].transform(self, Matrix4 mat) => transform2(self, mat); +macro double[<2>] double[<2>].rotate(self, double angle) => rotate(self, angle); +macro double[<2>] double[<2>].angle(self, double[<2>] v2) => math::atan2(v2.y, v2.x) - math::atan2(self.y, self.x); -macro float[<*>].clamp_mag(self, float min, float max) => clamp_magnitude(self, min, max); -macro double[<*>].clamp_mag(self, double min, double max) => clamp_magnitude(self, min, max); +macro float[<*>] float[<*>].clamp_mag(self, float min, float max) => clamp_magnitude(self, min, max); +macro double[<*>] double[<*>].clamp_mag(self, double min, double max) => clamp_magnitude(self, min, max); -macro float[<*>].towards(self, float[<*>] target, float max_distance) => towards(self, target, max_distance); -macro double[<*>].towards(self, double[<*>] target, double max_distance) => towards(self, target, max_distance); +macro float[<*>] float[<*>].towards(self, float[<*>] target, float max_distance) => towards(self, target, max_distance); +macro double[<*>] double[<*>].towards(self, double[<*>] target, double max_distance) => towards(self, target, max_distance); fn float[<3>] float[<3>].cross(self, float[<3>] v2) => cross3(self, v2); fn double[<3>] double[<3>].cross(self, double[<3>] v2) => cross3(self, v2); diff --git a/lib/std/net/socket_private.c3 b/lib/std/net/socket_private.c3 index 21e92d696..c663a349a 100644 --- a/lib/std/net/socket_private.c3 +++ b/lib/std/net/socket_private.c3 @@ -1,7 +1,7 @@ module std::net @if(os::SUPPORTS_INET); import std::time, libc, std::os; -macro apply_sockoptions(sockfd, options) @private +macro void? apply_sockoptions(sockfd, options) @private { Socket sock = { .sock = sockfd }; foreach (o : options) sock.set_option(o, true)!; @@ -96,7 +96,7 @@ fn Socket? connect_async_from_addrinfo(AddrInfo* addrinfo, SocketOption[] option return os::socket_error()?; } -macro @network_loop_over_ai(network, host, port; @body(fd, ai)) @private +macro void @network_loop_over_ai(network, host, port; @body(fd, ai)) @private { AddrInfo* ai = network.addrinfo(host, port)!; AddrInfo* first = ai; diff --git a/lib/std/sort/countingsort.c3 b/lib/std/sort/countingsort.c3 index 4b788469c..f21e1d8dd 100644 --- a/lib/std/sort/countingsort.c3 +++ b/lib/std/sort/countingsort.c3 @@ -8,18 +8,18 @@ Sort list using the counting sort algorithm. @require @is_sortable(list) : "The list must be indexable and support .len or .len()" @require @is_cmp_key_fn(key_fn, list) : "Expected a transformation function which returns an unsigned integer." *> -macro countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin +macro void countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin { usz len = lengthof(list); cs::csort{$typeof(list), $typeof(key_fn)}(list, 0, len, key_fn, ~((uint)0)); } -macro insertionsort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin +macro void insertionsort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { is::isort{$typeof(list), $typeof(cmp), $typeof(context)}(list, (usz)start, (usz)end, cmp, context); } -macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin +macro void quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { qs::qsort{$typeof(list), $typeof(cmp), $typeof(context)}(list, (isz)start, (isz)(end-1), cmp, context); } @@ -82,7 +82,7 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) mn = k < mn ? k : mn; mx = k > mx ? k : mx; - keys_ordered = keys_ordered & (char)(key_byte >= last_key); + keys_ordered = keys_ordered & (char)(key_byte >= last_key); last_key = key_byte; } @@ -107,7 +107,7 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) total += count; } ranges[256] = total; - + ushort remaining_indexs = 256 - (fallback0_count + recursion_count); for(ushort i = 0; (i < 256) && remaining_indexs; i++) { indexs[fallback0_count + fallback1_count] = (char)i; @@ -116,7 +116,7 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) fallback1_count += within_fallback1_range; remaining_indexs -= within_fallback1_range; } - + if (!keys_ordered) { usz sorted_count = 0; diff --git a/lib/std/sort/insertionsort.c3 b/lib/std/sort/insertionsort.c3 index 069ca2de1..285b17d0a 100644 --- a/lib/std/sort/insertionsort.c3 +++ b/lib/std/sort/insertionsort.c3 @@ -6,7 +6,7 @@ Sort list using the quick sort algorithm. @require @is_sortable(list) : "The list must be indexable and support .len or .len()" @require @is_valid_cmp_fn(cmp, list, context) : "Expected a comparison function which compares values" *> -macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin @safemacro +macro void insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin @safemacro { $if $kindof(list) == POINTER &&& ($kindof(*list) == ARRAY || $kindof(*list) == VECTOR): $typeof((*list)[0])[] list2 = list; diff --git a/lib/std/sort/quicksort.c3 b/lib/std/sort/quicksort.c3 index 1c683f329..c97d65d81 100644 --- a/lib/std/sort/quicksort.c3 +++ b/lib/std/sort/quicksort.c3 @@ -7,7 +7,7 @@ Sort list using the quick sort algorithm. @require @is_valid_cmp_fn(cmp, list, context) : "Expected a comparison function which compares values" @require @is_valid_context(cmp, context) : "Expected a valid context" *> -macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin +macro void quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin { $if $kindof(list) == POINTER &&& ($kindof(*list) == ARRAY || $kindof(*list) == VECTOR): $typeof((*list)[0])[] list2 = list; @@ -111,7 +111,7 @@ fn ElementType? qselect(Type list, isz low, isz high, isz k, CmpFn cmp, Context return NOT_FOUND?; } -macro @partition(Type list, isz l, isz h, CmpFn cmp, Context context) +macro isz @partition(Type list, isz l, isz h, CmpFn cmp, Context context) { var $has_cmp = @is_valid_macro_slot(cmp); var $has_context = @is_valid_macro_slot(context);