diff --git a/lib/std/collections/map.c3 b/lib/std/collections/map.c3 index d8d706351..5929e0c16 100644 --- a/lib/std/collections/map.c3 +++ b/lib/std/collections/map.c3 @@ -130,10 +130,10 @@ fn Map new_from_map(Map other_map, Allocator allocator = null) MapImpl* map = (MapImpl*)new(other_map_impl.table.len, other_map_impl.load_factor, allocator ?: allocator::heap()); if (!other_map_impl.count) return (Map)map; foreach (Entry *e : other_map_impl.table) - { - if (!e) continue; - map._put_for_create(e.key, e.value); - } + { + if (!e) continue; + map._put_for_create(e.key, e.value); + } return (Map)map; } @@ -421,9 +421,9 @@ fn void _init(MapImpl* impl, uint capacity, float load_factor, Allocator allocat capacity = math::next_power_of_2(capacity); *impl = { .allocator = allocator, - .load_factor = load_factor, - .threshold = (uint)(capacity * load_factor), - .table = allocator::new_array(allocator, Entry*, capacity) + .load_factor = load_factor, + .threshold = (uint)(capacity * load_factor), + .table = allocator::new_array(allocator, Entry*, capacity) }; } diff --git a/lib/std/compression/qoi.c3 b/lib/std/compression/qoi.c3 index 2418ce329..eb9e2198d 100644 --- a/lib/std/compression/qoi.c3 +++ b/lib/std/compression/qoi.c3 @@ -9,8 +9,8 @@ const uint PIXELS_MAX = 400000000; */ enum QOIColorspace : char (char id) { - SRGB = 0, // sRGB with linear alpha - LINEAR = 1 // all channels linear + SRGB = 0, // sRGB with linear alpha + LINEAR = 1 // all channels linear } /** @@ -22,8 +22,8 @@ enum QOIColorspace : char (char id) enum QOIChannels : char (char id) { AUTO = 0, - RGB = 3, - RGBA = 4 + RGB = 3, + RGBA = 4 } /** diff --git a/lib/std/core/allocators/libc_allocator.c3 b/lib/std/core/allocators/libc_allocator.c3 index 0a18551fa..377e9a223 100644 --- a/lib/std/core/allocators/libc_allocator.c3 +++ b/lib/std/core/allocators/libc_allocator.c3 @@ -28,7 +28,7 @@ fn void*! LibcAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz a mem::clear(data, bytes, mem::DEFAULT_MEM_ALIGNMENT); return data; } - return libc::calloc(1, bytes) ?: AllocationFailure.OUT_OF_MEMORY?; + return libc::calloc(1, bytes) ?: AllocationFailure.OUT_OF_MEMORY?; } else { @@ -41,17 +41,17 @@ fn void*! LibcAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz a { if (!(data = libc::malloc(bytes))) return AllocationFailure.OUT_OF_MEMORY?; } - $if env::TESTING: - for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; - $endif - return data; + $if env::TESTING: + for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; + $endif + return data; } } fn void*! LibcAllocator.resize(&self, void* old_ptr, usz new_bytes, usz alignment) @dynamic { if (alignment <= mem::DEFAULT_MEM_ALIGNMENT) return libc::realloc(old_ptr, new_bytes) ?: AllocationFailure.OUT_OF_MEMORY?; - void* new_ptr; + void* new_ptr; if (posix::posix_memalign(&new_ptr, alignment, new_bytes)) return AllocationFailure.OUT_OF_MEMORY?; $switch @@ -90,10 +90,10 @@ fn void*! LibcAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz a } void* data = alignment > 0 ? win32::_aligned_malloc(bytes, alignment) : libc::malloc(bytes); if (!data) return AllocationFailure.OUT_OF_MEMORY?; - $if env::TESTING: + $if env::TESTING: for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; $endif - return data; + return data; } fn void*! LibcAllocator.resize(&self, void* old_ptr, usz new_bytes, usz alignment) @dynamic @@ -109,8 +109,8 @@ fn void LibcAllocator.release(&self, void* old_ptr, bool aligned) @dynamic { if (aligned) { - win32::_aligned_free(old_ptr); - return; + win32::_aligned_free(old_ptr); + return; } libc::free(old_ptr); } @@ -123,16 +123,16 @@ fn void*! LibcAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz a if (init_type == ZERO) { void* data = alignment ? @aligned_alloc(fn void*(usz bytes) => libc::calloc(bytes, 1), bytes, alignment)!! : libc::calloc(bytes, 1); - return data ?: AllocationFailure.OUT_OF_MEMORY?; + return data ?: AllocationFailure.OUT_OF_MEMORY?; } else { void* data = alignment ? @aligned_alloc(libc::malloc, bytes, alignment)!! : libc::malloc(bytes); - if (!data) return AllocationFailure.OUT_OF_MEMORY?; - $if env::TESTING: - for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; - $endif - return data; + if (!data) return AllocationFailure.OUT_OF_MEMORY?; + $if env::TESTING: + for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; + $endif + return data; } } diff --git a/lib/std/core/allocators/tracking_allocator.c3 b/lib/std/core/allocators/tracking_allocator.c3 index 99ecb5943..6fb86f256 100644 --- a/lib/std/core/allocators/tracking_allocator.c3 +++ b/lib/std/core/allocators/tracking_allocator.c3 @@ -86,7 +86,7 @@ fn void*! TrackingAllocator.acquire(&self, usz size, AllocInitType init_type, us void*[MAX_BACKTRACE] bt; backtrace::capture_current(&bt); self.map.set((uptr)data, { data, size, bt }); - self.mem_total += size; + self.mem_total += size; return data; } @@ -97,7 +97,7 @@ fn void*! TrackingAllocator.resize(&self, void* old_pointer, usz size, usz align void*[MAX_BACKTRACE] bt; backtrace::capture_current(&bt); self.map.set((uptr)data, { data, size, bt }); - self.mem_total += size; + self.mem_total += size; self.allocs_total++; return data; } @@ -105,9 +105,9 @@ fn void*! TrackingAllocator.resize(&self, void* old_pointer, usz size, usz align fn void TrackingAllocator.release(&self, void* old_pointer, bool is_aligned) @dynamic { if (catch self.map.remove((uptr)old_pointer)) - { - unreachable("Attempt to release untracked pointer %p, this is likely a bug.", old_pointer); - } + { + unreachable("Attempt to release untracked pointer %p, this is likely a bug.", old_pointer); + } self.inner_allocator.release(old_pointer, is_aligned); } @@ -132,14 +132,14 @@ fn void! TrackingAllocator.fprint_report(&self, OutStream out) if (!allocs[0].backtrace[0]) { io::fprintn(out, "======== Memory Report ========")!; - io::fprintn(out, "Size in bytes Address")!; - foreach (i, &allocation : allocs) - { - entries++; - total += allocation.size; - io::fprintfn(out, "%13s %p", allocation.size, allocation.ptr)!; - } - io::fprintn(out, "===============================")!; + io::fprintn(out, "Size in bytes Address")!; + foreach (i, &allocation : allocs) + { + entries++; + total += allocation.size; + io::fprintfn(out, "%13s %p", allocation.size, allocation.ptr)!; + } + io::fprintn(out, "===============================")!; } else @@ -169,48 +169,48 @@ fn void! TrackingAllocator.fprint_report(&self, OutStream out) io::fprintn(out, "* NO ALLOCATIONS FOUND *")!; } io::fprintfn(out, "- Total currently allocated memory: %d", total)!; - io::fprintfn(out, "- Total current allocations: %d", entries)!; - io::fprintfn(out, "- Total allocations (freed and retained): %d", self.allocs_total)!; - io::fprintfn(out, "- Total allocated memory (freed and retained): %d", self.mem_total)!; - if (leaks) - { + io::fprintfn(out, "- Total current allocations: %d", entries)!; + io::fprintfn(out, "- Total allocations (freed and retained): %d", self.allocs_total)!; + io::fprintfn(out, "- Total allocated memory (freed and retained): %d", self.mem_total)!; + if (leaks) + { io::fprintn(out)!; io::fprintn(out, "Full leak report:")!; - foreach (i, &allocation : allocs) - { - if (!allocation.backtrace[3]) - { - io::fprintfn(out, "Allocation %d (%d bytes) - no backtrace available.", i + 1, allocation.size)!; - continue; + foreach (i, &allocation : allocs) + { + if (!allocation.backtrace[3]) + { + io::fprintfn(out, "Allocation %d (%d bytes) - no backtrace available.", i + 1, allocation.size)!; + continue; } - BacktraceList backtraces = {}; - usz end = MAX_BACKTRACE; - foreach (j, val : allocation.backtrace) - { - if (!val) - { - end = j; - break; + BacktraceList backtraces = {}; + usz end = MAX_BACKTRACE; + foreach (j, val : allocation.backtrace) + { + if (!val) + { + end = j; + break; } } - BacktraceList list = backtrace::symbolize_backtrace(allocation.backtrace[3..(end - 1)], allocator::temp())!; - io::fprintfn(out, "Allocation %d (%d bytes): ", i + 1, allocation.size)!; - foreach (trace : list) - { - if (trace.has_file()) - { - io::fprintfn(out, " %s (in %s:%d)", trace.function, trace.file, trace.line); - continue; - } - if (trace.is_unknown()) - { - io::fprintfn(out, " ??? (in unknown)"); - continue; - } + BacktraceList list = backtrace::symbolize_backtrace(allocation.backtrace[3..(end - 1)], allocator::temp())!; + io::fprintfn(out, "Allocation %d (%d bytes): ", i + 1, allocation.size)!; + foreach (trace : list) + { + if (trace.has_file()) + { + io::fprintfn(out, " %s (in %s:%d)", trace.function, trace.file, trace.line); + continue; + } + if (trace.is_unknown()) + { + io::fprintfn(out, " ??? (in unknown)"); + continue; + } io::fprintfn(out, " %s (source unavailable)", trace.function); } - } - } + } + } }; } \ No newline at end of file diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index dc6370e6d..066f2fa0c 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -71,23 +71,23 @@ fn bool print_backtrace(String message, int backtraces_to_ignore) @if(env::NATIV if (catch backtrace) return false; if (backtrace.len() <= backtraces_to_ignore) return false; io::eprint("\nERROR: '"); - io::eprint(message); - io::eprintn("'"); + io::eprint(message); + io::eprintn("'"); foreach (i, &trace : backtrace) - { - if (i < backtraces_to_ignore) continue; - String inline_suffix = trace.is_inline ? " [inline]" : ""; - if (trace.is_unknown()) - { + { + if (i < backtraces_to_ignore) continue; + String inline_suffix = trace.is_inline ? " [inline]" : ""; + if (trace.is_unknown()) + { io::eprintfn(" in ???%s", inline_suffix); continue; } if (trace.has_file()) - { - io::eprintfn(" in %s (%s:%d) [%s]%s", trace.function, trace.file, trace.line, trace.object_file, inline_suffix); - continue; - } - io::eprintfn(" in %s (source unavailable) [%s]%s", trace.function, trace.object_file, inline_suffix); + { + io::eprintfn(" in %s (%s:%d) [%s]%s", trace.function, trace.file, trace.line, trace.object_file, inline_suffix); + continue; + } + io::eprintfn(" in %s (source unavailable) [%s]%s", trace.function, trace.object_file, inline_suffix); } return true; }; @@ -243,14 +243,14 @@ macro enum_by_name($Type, String enum_name) @builtin **/ macro bool @likely(bool #value, $probability = 1.0) @builtin { - $switch - $case env::BUILTIN_EXPECT_IS_DISABLED: + $switch + $case env::BUILTIN_EXPECT_IS_DISABLED: return #value; - $case $probability == 1.0: + $case $probability == 1.0: return $$expect(#value, true); - $default: + $default: return $$expect_with_probability(#value, true, $probability); - $endswitch + $endswitch } /** @@ -262,14 +262,14 @@ macro bool @likely(bool #value, $probability = 1.0) @builtin **/ macro bool @unlikely(bool #value, $probability = 1.0) @builtin { - $switch - $case env::BUILTIN_EXPECT_IS_DISABLED: + $switch + $case env::BUILTIN_EXPECT_IS_DISABLED: return #value; - $case $probability == 1.0: + $case $probability == 1.0: return $$expect(#value, false); - $default: + $default: return $$expect_with_probability(#value, false, $probability); - $endswitch + $endswitch } /** @@ -279,14 +279,14 @@ macro bool @unlikely(bool #value, $probability = 1.0) @builtin **/ macro @expect(#value, expected, $probability = 1.0) @builtin { - $switch - $case env::BUILTIN_EXPECT_IS_DISABLED: + $switch + $case env::BUILTIN_EXPECT_IS_DISABLED: return #value == expected; - $case $probability == 1.0: + $case $probability == 1.0: return $$expect(#value, ($typeof(#value))expected); - $default: + $default: return $$expect_with_probability(#value, expected, $probability); - $endswitch + $endswitch } /** diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 4bc53855e..72b7a3dc1 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -77,24 +77,24 @@ fn void DString.replace(&self, String needle, String replacement) foreach (i, c : str) { if (c == needle[match]) - { - match++; - if (match == needle_len) - { - self.append_chars(replacement); - match = 0; - continue; - } - continue; - } - if (match > 0) - { - self.append_chars(str[i - match:match]); - match = 0; - } - self.append_char(c); - } - if (match > 0) self.append_chars(str[^match:match]); + { + match++; + if (match == needle_len) + { + self.append_chars(replacement); + match = 0; + continue; + } + continue; + } + if (match > 0) + { + self.append_chars(str[i - match:match]); + match = 0; + } + self.append_char(c); + } + if (match > 0) self.append_chars(str[^match:match]); }; } diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 3ffbd6d85..5e167bcdd 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -753,7 +753,7 @@ fn void free_aligned(void* ptr) @builtin @inline fn void* trealloc(void* ptr, usz size, usz alignment = mem::DEFAULT_MEM_ALIGNMENT) @builtin @inline @nodiscard { if (!size) return null; - if (!ptr) return tmalloc(size, alignment); + if (!ptr) return tmalloc(size, alignment); return allocator::temp().resize(ptr, size, alignment)!!; } diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 945af2289..00458fb97 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -21,21 +21,21 @@ interface Allocator fn void reset(usz mark) @optional; fn usz mark() @optional; /** - * @require !alignment || math::is_power_of_2(alignment) - * @require alignment <= mem::MAX_MEMORY_ALIGNMENT `alignment too big` - * @require size > 0 - **/ + * @require !alignment || math::is_power_of_2(alignment) + * @require alignment <= mem::MAX_MEMORY_ALIGNMENT `alignment too big` + * @require size > 0 + **/ fn void*! acquire(usz size, AllocInitType init_type, usz alignment = 0); /** - * @require !alignment || math::is_power_of_2(alignment) - * @require alignment <= mem::MAX_MEMORY_ALIGNMENT `alignment too big` - * @require ptr != null - * @require new_size > 0 - **/ + * @require !alignment || math::is_power_of_2(alignment) + * @require alignment <= mem::MAX_MEMORY_ALIGNMENT `alignment too big` + * @require ptr != null + * @require new_size > 0 + **/ fn void*! resize(void* ptr, usz new_size, usz alignment = 0); /** - * @require ptr != null - **/ + * @require ptr != null + **/ fn void release(void* ptr, bool aligned); } diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index ff9597efc..ccb147782 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -260,9 +260,9 @@ macro bool may_load_atomic($Type) @const macro lower_to_atomic_compatible_type($Type) @const { $switch ($Type.kindof) - $case SIGNED_INT: + $case SIGNED_INT: $case UNSIGNED_INT: - return $Type.typeid; + return $Type.typeid; $case DISTINCT: return lower_to_atomic_compatible_type($Type.inner); $case FLOAT: diff --git a/lib/std/hash/md5.c3 b/lib/std/hash/md5.c3 index 5f870629e..1b429131f 100644 --- a/lib/std/hash/md5.c3 +++ b/lib/std/hash/md5.c3 @@ -119,7 +119,7 @@ fn char* body(Md5* ctx, void* data, usz size) char* ptr; uint a, b, c, d; uint saved_a, saved_b, saved_c, saved_d; - ptr = data; + ptr = data; a = ctx.a; b = ctx.b; c = ctx.c; diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index e2e872198..620ca0bf8 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -310,12 +310,12 @@ macro usz! @wrap_bad(Formatter* f, #action) if (catch err = len) { case PrintFault.BUFFER_EXCEEDED: - case PrintFault.INTERNAL_BUFFER_EXCEEDED: - return f.first_err(err)?; - default: - err = f.first_err(PrintFault.INVALID_ARGUMENT); - f.out_substr("")!; - return err?; + case PrintFault.INTERNAL_BUFFER_EXCEEDED: + return f.first_err(err)?; + default: + err = f.first_err(PrintFault.INVALID_ARGUMENT); + f.out_substr("")!; + return err?; } return len; } diff --git a/lib/std/io/formatter_private.c3 b/lib/std/io/formatter_private.c3 index ae3b8b3de..2904834d6 100644 --- a/lib/std/io/formatter_private.c3 +++ b/lib/std/io/formatter_private.c3 @@ -642,7 +642,7 @@ fn usz! Formatter.out_reverse(&self, char[] buf) @private // pad spaces up to given width if (!self.flags.zeropad && !self.flags.left) { - n += self.pad(' ', self.width, len)!; + n += self.pad(' ', self.width, len)!; } // reverse string while (len) n += self.out(buf[--len])!; @@ -661,7 +661,7 @@ fn int! printf_parse_format_field( if (c.is_digit()) return simple_atoi(format_ptr, format_len, index_ptr); if (c != '*') return 0; usz len = ++(*index_ptr); - if (len >= format_len) return FormattingFault.BAD_FORMAT?; + if (len >= format_len) return FormattingFault.BAD_FORMAT?; if (*args_index_ptr >= args_len) return FormattingFault.BAD_FORMAT?; any val = args_ptr[(*args_index_ptr)++]; if (!val.type.kindof.is_int()) return FormattingFault.BAD_FORMAT?; diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index 6666ba56d..9de526516 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -65,29 +65,29 @@ macro String! readline(stream = io::stdin(), Allocator allocator = allocator::he char val = stream.read_byte()!; $endif - if (val == '\n') return ""; - @pool(allocator) - { - DString str = dstring::temp_with_capacity(256); - if (val != '\r') str.append(val); - while (1) - { - $if $is_stream: - char! c = func((void*)stream); - $else - char! c = stream.read_byte(); - $endif - if (catch err = c) - { - if (err == IoError.EOF) break; - return err?; - } - if (c == '\r') continue; - if (c == '\n') break; - str.append_char(c); - } - return str.copy_str(allocator); - }; + if (val == '\n') return ""; + @pool(allocator) + { + DString str = dstring::temp_with_capacity(256); + if (val != '\r') str.append(val); + while (1) + { + $if $is_stream: + char! c = func((void*)stream); + $else + char! c = stream.read_byte(); + $endif + if (catch err = c) + { + if (err == IoError.EOF) break; + return err?; + } + if (c == '\r') continue; + if (c == '\n') break; + str.append_char(c); + } + return str.copy_str(allocator); + }; } /** diff --git a/lib/std/io/stream.c3 b/lib/std/io/stream.c3 index 5b43d7c4e..50f346e22 100644 --- a/lib/std/io/stream.c3 +++ b/lib/std/io/stream.c3 @@ -249,8 +249,8 @@ macro usz! write_varint(stream, x) macro ushort! read_be_ushort(stream) { char hi_byte = stream.read_byte()!; - char lo_byte = stream.read_byte()!; - return (ushort)(hi_byte << 8 | lo_byte); + char lo_byte = stream.read_byte()!; + return (ushort)(hi_byte << 8 | lo_byte); } /** diff --git a/lib/std/libc/os/posix.c3 b/lib/std/libc/os/posix.c3 index cd1c6ac1a..749d2bfa8 100644 --- a/lib/std/libc/os/posix.c3 +++ b/lib/std/libc/os/posix.c3 @@ -28,10 +28,10 @@ def SigActionFunction = fn void(CInt, void*, void*); struct Sigaction { union - { - SignalFunction sa_handler; - SigActionFunction sa_sigaction; - } + { + SignalFunction sa_handler; + SigActionFunction sa_sigaction; + } CInt sa_flags @if(env::BSD_FAMILY); Sigset_t sa_mask; // 128 CInt sa_flags @if(!env::BSD_FAMILY); @@ -181,13 +181,13 @@ extern fn CInt cfsetispeed(Termios* self, Speed speed); const CInt NCCS = 32; struct Termios { - Tcflags c_iflag; - Tcflags c_oflag; - Tcflags c_cflag; - Tcflags c_lflag; - Cc c_line; - Cc[NCCS] c_cc; - Speed c_ispeed; - Speed c_ospeed; + Tcflags c_iflag; + Tcflags c_oflag; + Tcflags c_cflag; + Tcflags c_lflag; + Cc c_line; + Cc[NCCS] c_cc; + Speed c_ispeed; + Speed c_ospeed; } diff --git a/lib/std/math/bigint.c3 b/lib/std/math/bigint.c3 index d67244c26..6399bbbf5 100644 --- a/lib/std/math/bigint.c3 +++ b/lib/std/math/bigint.c3 @@ -109,7 +109,7 @@ fn BigInt*! BigInt.init_string_radix(&self, String value, int radix) switch { case limit && !self.is_negative(): - return NumberConversion.INTEGER_OVERFLOW?; + return NumberConversion.INTEGER_OVERFLOW?; case !limit && self.is_negative(): return NumberConversion.INTEGER_OVERFLOW?; } @@ -503,8 +503,8 @@ fn BigInt BigInt.abs(&self) fn usz! BigInt.to_format(&self, Formatter* format) @dynamic { @stack_mem(4100; Allocator mem) - { - return format.print(self.to_string_with_radix(10, mem)); + { + return format.print(self.to_string_with_radix(10, mem)); }; } @@ -1111,10 +1111,3 @@ fn int shift_right(uint* data, int len, int shift_val) @inline - - - - - - - diff --git a/lib/std/math/math_i128.c3 b/lib/std/math/math_i128.c3 index 8620ce0f4..eeedfeb2b 100644 --- a/lib/std/math/math_i128.c3 +++ b/lib/std/math/math_i128.c3 @@ -62,124 +62,124 @@ macro uint128 @__udivmodti4(uint128 a, uint128 b, bool $return_rem) $else return (uint128)(n.high >> $$ctz(d.high)); $endif - } - sr = (uint)$$clz(d.high) - (uint)$$clz(n.high); - // 0 <= sr <= n_udword_bits - 2 or sr large - if (sr > 64 - 2) - { - $if $return_rem: - return n.all; - $else - return 0; - $endif - } - sr++; - // 1 <= sr <= n_udword_bits - 1 - // q.all = n.all << (n_utword_bits - sr); - q.low = 0; - q.high = n.low << (64 - sr); - r.high = n.high >> sr; - r.low = (n.high << (64 - sr)) | (n.low >> sr); - } - else // d.s.low != 0 - { - if (d.high == 0) - { - if (d.low & (d.low - 1) == 0) // if d is a power of 2 - { - $if $return_rem: - return (uint128)(n.low & (d.low - 1)); - $else - if (d.low == 1) return n.all; - sr = (uint)$$ctz(d.low); - q.high = n.high >> sr; - q.low = (n.high << (64 - sr)) | (n.low >> sr); - return q.all; - $endif - } - sr = 1 + 64 + (uint)$$clz(d.low) - (uint)$$clz(n.high); - // 2 <= sr <= n_utword_bits - 1 - // q.all = n.all << (n_utword_bits - sr); - // r.all = n.all >> sr; - switch - { - case sr == 64: + } + sr = (uint)$$clz(d.high) - (uint)$$clz(n.high); + // 0 <= sr <= n_udword_bits - 2 or sr large + if (sr > 64 - 2) + { + $if $return_rem: + return n.all; + $else + return 0; + $endif + } + sr++; + // 1 <= sr <= n_udword_bits - 1 + // q.all = n.all << (n_utword_bits - sr); + q.low = 0; + q.high = n.low << (64 - sr); + r.high = n.high >> sr; + r.low = (n.high << (64 - sr)) | (n.low >> sr); + } + else // d.s.low != 0 + { + if (d.high == 0) + { + if (d.low & (d.low - 1) == 0) // if d is a power of 2 + { + $if $return_rem: + return (uint128)(n.low & (d.low - 1)); + $else + if (d.low == 1) return n.all; + sr = (uint)$$ctz(d.low); + q.high = n.high >> sr; + q.low = (n.high << (64 - sr)) | (n.low >> sr); + return q.all; + $endif + } + sr = 1 + 64 + (uint)$$clz(d.low) - (uint)$$clz(n.high); + // 2 <= sr <= n_utword_bits - 1 + // q.all = n.all << (n_utword_bits - sr); + // r.all = n.all >> sr; + switch + { + case sr == 64: q.low = 0; q.high = n.low; r.high = 0; r.low = n.high; case sr < 64: - q.low = 0; - q.high = n.low << (64 - sr); - r.high = n.high >> sr; - r.low = (n.high << (64 - sr)) | (n.low >> sr); - default: // n_udword_bits + 1 <= sr <= n_utword_bits - 1 - q.low = n.low << (128 - sr); - q.high = (n.high << (128 - sr)) | (n.low >> (sr - 64)); - r.high = 0; - r.low = n.high >> (sr - 64); - } - } - else - { + q.low = 0; + q.high = n.low << (64 - sr); + r.high = n.high >> sr; + r.low = (n.high << (64 - sr)) | (n.low >> sr); + default: // n_udword_bits + 1 <= sr <= n_utword_bits - 1 + q.low = n.low << (128 - sr); + q.high = (n.high << (128 - sr)) | (n.low >> (sr - 64)); + r.high = 0; + r.low = n.high >> (sr - 64); + } + } + else + { sr = (uint)$$clz(d.high) - (uint)$$clz(n.high); - // 0 <= sr <= n_udword_bits - 1 or sr large - if (sr > 64 - 1) - { - $if $return_rem: - return n.all; - $else - return 0; - $endif - } + // 0 <= sr <= n_udword_bits - 1 or sr large + if (sr > 64 - 1) + { + $if $return_rem: + return n.all; + $else + return 0; + $endif + } - sr++; + sr++; // 1 <= sr <= n_udword_bits // q.all = n.all << (n_utword_bits - sr); // r.all = n.all >> sr; q.low = 0; - if (sr == 64) - { - q.high = n.low; - r.high = 0; - r.low = n.high; + if (sr == 64) + { + q.high = n.low; + r.high = 0; + r.low = n.high; } else { r.high = n.high >> sr; r.low = (n.high << (64 - sr)) | (n.low >> sr); q.high = n.low << (64 - sr); - } - } - } - // Not a special case - // q and r are initialized with: - // q.all = n.all << (128 - sr); - // r.all = n.all >> sr; - // 1 <= sr <= n_utword_bits - 1 - uint carry = 0; - for (; sr > 0; sr--) - { - // r:q = ((r:q) << 1) | carry - r.high = (r.high << 1) | (r.low >> (64 - 1)); - r.low = (r.low << 1) | (q.high >> (64 - 1)); - q.high = (q.high << 1) | (q.low >> (64 - 1)); - q.low = (q.low << 1) | carry; - // carry = 0; - // if (r.all >= d.all) - // { - // r.all -= d.all; - // carry = 1; - // } - int128 s = (int128)(d.all - r.all - 1) >> (128 - 1); - carry = (uint)(s & 1); - r.all -= d.all & s; - } - $if $return_rem: + } + } + } + // Not a special case + // q and r are initialized with: + // q.all = n.all << (128 - sr); + // r.all = n.all >> sr; + // 1 <= sr <= n_utword_bits - 1 + uint carry = 0; + for (; sr > 0; sr--) + { + // r:q = ((r:q) << 1) | carry + r.high = (r.high << 1) | (r.low >> (64 - 1)); + r.low = (r.low << 1) | (q.high >> (64 - 1)); + q.high = (q.high << 1) | (q.low >> (64 - 1)); + q.low = (q.low << 1) | carry; + // carry = 0; + // if (r.all >= d.all) + // { + // r.all -= d.all; + // carry = 1; + // } + int128 s = (int128)(d.all - r.all - 1) >> (128 - 1); + carry = (uint)(s & 1); + r.all -= d.all & s; + } + $if $return_rem: return r.all; - $else + $else return (q.all << 1) | carry; - $endif + $endif } fn uint128 __umodti3(uint128 n, uint128 d) @extern("__umodti3") @weak @nostrip diff --git a/lib/std/math/math_nolibc/atan.c3 b/lib/std/math/math_nolibc/atan.c3 index f5c1002d6..167c77704 100644 --- a/lib/std/math/math_nolibc/atan.c3 +++ b/lib/std/math/math_nolibc/atan.c3 @@ -38,11 +38,11 @@ fn double _atan(double x) @weak @extern("atan") @nostrip { case ix >= 0x44100000: /* if |x| >= 2^66 */ - if (math::is_nan(x)) return x; - double z = ATANHI[3] + 0x1p-120f; - return sign ? -z : z; - case ix < 0x3fdc0000: - /* |x| < 0.4375 */ + if (math::is_nan(x)) return x; + double z = ATANHI[3] + 0x1p-120f; + return sign ? -z : z; + case ix < 0x3fdc0000: + /* |x| < 0.4375 */ if (ix < 0x3e400000) { /* |x| < 2^-27 */ @@ -55,8 +55,8 @@ fn double _atan(double x) @weak @extern("atan") @nostrip } id = -1; case ix < 0x3ff30000: - /* |x| < 1.1875 */ - x = math::abs(x); + /* |x| < 1.1875 */ + x = math::abs(x); if (ix < 0x3fe60000) { /* 7/16 <= |x| < 11/16 */ @@ -128,32 +128,32 @@ fn float _atanf(float x) @weak @extern("atanf") @nostrip { case ix < 0x3ee00000: /* |x| < 0.4375 */ - if (ix < 0x39800000) - { - /* |x| < 2**-12 */ - if (ix < 0x00800000) - { - /* raise underflow for subnormal x */ + if (ix < 0x39800000) + { + /* |x| < 2**-12 */ + if (ix < 0x00800000) + { + /* raise underflow for subnormal x */ float f = @volatile_load(x); - f = f * f; - } - return x; - } - id = -1; - case ix < 0x3f980000: - /* |x| < 1.1875 */ + f = f * f; + } + return x; + } + id = -1; + case ix < 0x3f980000: + /* |x| < 1.1875 */ x = math::abs(x); - if (ix < 0x3f300000) - { - /* 7/16 <= |x| < 11/16 */ - id = 0; - x = (2.0f * x - 1.0f) / (2.0f + x); - break; - } - /* 11/16 <= |x| < 19/16 */ - id = 1; - x = (x - 1.0f) / (x + 1.0f); - case ix < 0x401c0000: + if (ix < 0x3f300000) + { + /* 7/16 <= |x| < 11/16 */ + id = 0; + x = (2.0f * x - 1.0f) / (2.0f + x); + break; + } + /* 11/16 <= |x| < 19/16 */ + id = 1; + x = (x - 1.0f) / (x + 1.0f); + case ix < 0x401c0000: x = math::abs(x); /* |x| < 2.4375 */ id = 2; @@ -161,8 +161,8 @@ fn float _atanf(float x) @weak @extern("atanf") @nostrip default: /* 2.4375 <= |x| < 2**26 */ x = math::abs(x); - id = 3; - x = -1.0f / x; + id = 3; + x = -1.0f / x; } /* end of argument reduction */ float z = x * x; diff --git a/lib/std/math/math_nolibc/cos.c3 b/lib/std/math/math_nolibc/cos.c3 index 7fefa946f..94313d3a9 100644 --- a/lib/std/math/math_nolibc/cos.c3 +++ b/lib/std/math/math_nolibc/cos.c3 @@ -61,14 +61,14 @@ fn double _cos(double x) @weak @nostrip { // |x| ~< pi/4 case ix <= 0x3fe921fb: - if (ix < 0x3e46a09e) - { - // |x| < 2**-27 * sqrt(2) - // raise inexact if x!=0 - force_eval_add(x, 0x1p120f); - return 1.0; - } - return __cos(x, 0); + if (ix < 0x3e46a09e) + { + // |x| < 2**-27 * sqrt(2) + // raise inexact if x!=0 + force_eval_add(x, 0x1p120f); + return 1.0; + } + return __cos(x, 0); case ix >= 0x7ff00000: // cos(Inf or NaN) is NaN return x - x; diff --git a/lib/std/math/math_nolibc/exp2.c3 b/lib/std/math/math_nolibc/exp2.c3 index 2215a663d..a14f3f363 100644 --- a/lib/std/math/math_nolibc/exp2.c3 +++ b/lib/std/math/math_nolibc/exp2.c3 @@ -126,10 +126,10 @@ fn double _exp2(double x) @extern("exp2") @weak @nostrip /* Evaluation is optimized assuming superscalar pipelined execution. */ double r2 = r * r; const C1 = __EXP2_DATA.exp2_poly[0]; - const C2 = __EXP2_DATA.exp2_poly[1]; - const C3 = __EXP2_DATA.exp2_poly[2]; - const C4 = __EXP2_DATA.exp2_poly[3]; - const C5 = __EXP2_DATA.exp2_poly[4]; + const C2 = __EXP2_DATA.exp2_poly[1]; + const C3 = __EXP2_DATA.exp2_poly[2]; + const C4 = __EXP2_DATA.exp2_poly[3]; + const C5 = __EXP2_DATA.exp2_poly[4]; /* Without fma the worst case error is 0.5/N ulp larger. */ /* Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp. */ double tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5); diff --git a/lib/std/math/math_nolibc/math_nolibc.c3 b/lib/std/math/math_nolibc/math_nolibc.c3 index e7c455fbc..d36eed9e2 100644 --- a/lib/std/math/math_nolibc/math_nolibc.c3 +++ b/lib/std/math/math_nolibc/math_nolibc.c3 @@ -31,18 +31,18 @@ const Exp2fData __EXP2F_DATA @private = { 0x3feeace5422aa0db, 0x3feeb737b0cdc5e5, 0x3feec49182a3f090, 0x3feed503b23e255d, 0x3feee89f995ad3ad, 0x3feeff76f2fb5e47, 0x3fef199bdd85529c, 0x3fef3720dcef9069, 0x3fef5818dcfba487, 0x3fef7c97337b9b5f, 0x3fefa4afa2a490da, 0x3fefd0765b6e4540, - }, - .shift_scaled = 0x1.8p+52 / (1 << 5), - .poly = { - 0x1.c6af84b912394p-5, 0x1.ebfce50fac4f3p-3, 0x1.62e42ff0c52d6p-1, - }, - .shift = 0x1.8p+52, - .invln2_scaled = 0x1.71547652b82fep+0 * (1 << 5), - .poly_scaled = { - 0x1.c6af84b912394p-5 / (1 << 5) / (1 << 5) / (1 << 5), - 0x1.ebfce50fac4f3p-3 / (1 << 5) / (1 << 5), - 0x1.62e42ff0c52d6p-1 / (1 << 5), - }, + }, + .shift_scaled = 0x1.8p+52 / (1 << 5), + .poly = { + 0x1.c6af84b912394p-5, 0x1.ebfce50fac4f3p-3, 0x1.62e42ff0c52d6p-1, + }, + .shift = 0x1.8p+52, + .invln2_scaled = 0x1.71547652b82fep+0 * (1 << 5), + .poly_scaled = { + 0x1.c6af84b912394p-5 / (1 << 5) / (1 << 5) / (1 << 5), + 0x1.ebfce50fac4f3p-3 / (1 << 5) / (1 << 5), + 0x1.62e42ff0c52d6p-1 / (1 << 5), + }, }; const EXP_TABLE_BITS = 7; diff --git a/lib/std/math/math_nolibc/rempi.c3 b/lib/std/math/math_nolibc/rempi.c3 index 8e5715779..f802f4380 100644 --- a/lib/std/math/math_nolibc/rempi.c3 +++ b/lib/std/math/math_nolibc/rempi.c3 @@ -181,9 +181,9 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec) iq[jz - 1] -= i << (24 - q0); ih = iq[jz - 1] >> (23 - q0); case q0 == 0: - ih = iq[jz - 1] >> 23; + ih = iq[jz - 1] >> 23; case z >= 0.5: - ih = 2; + ih = 2; } if (ih > 0) { @@ -192,7 +192,7 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec) int carry = 0; for (int i = 0; i < jz; i++) { - /* compute 1-q */ + /* compute 1-q */ j = iq[i]; if (carry == 0) { @@ -369,13 +369,13 @@ fn int __rem_pio2_large(double* x, double* y, int e0, int nx, int prec) fn int __rem_pio2(double x, double *y) { const double PIO4 = 0x1.921fb54442d18p-1; - const double INVPIO2 = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ - const double PIO2_1 = 1.57079632673412561417e+00; /* 0x3FF921FB, 0x54400000 */ - const double PIO2_1T = 6.07710050650619224932e-11; /* 0x3DD0B461, 0x1A626331 */ - const double PIO2_2 = 6.07710050630396597660e-11; /* 0x3DD0B461, 0x1A600000 */ - const double PIO2_2T = 2.02226624879595063154e-21; /* 0x3BA3198A, 0x2E037073 */ - const double PIO2_3 = 2.02226624871116645580e-21; /* 0x3BA3198A, 0x2E000000 */ - const double PIO2_3T = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ + const double INVPIO2 = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ + const double PIO2_1 = 1.57079632673412561417e+00; /* 0x3FF921FB, 0x54400000 */ + const double PIO2_1T = 6.07710050650619224932e-11; /* 0x3DD0B461, 0x1A626331 */ + const double PIO2_2 = 6.07710050630396597660e-11; /* 0x3DD0B461, 0x1A600000 */ + const double PIO2_2T = 2.02226624879595063154e-21; /* 0x3BA3198A, 0x2E037073 */ + const double PIO2_3 = 2.02226624871116645580e-21; /* 0x3BA3198A, 0x2E000000 */ + const double PIO2_3T = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ ulong u = bitcast(x, ulong); int sign = (int)(u >> 63); @@ -452,37 +452,37 @@ fn int __rem_pio2(double x, double *y) case ix < 0x413921fb: break; // medium case ix >= 0x7ff00000: - // x is inf or NaN */ - y[0] = y[1] = x - x; - return 0; + // x is inf or NaN */ + y[0] = y[1] = x - x; + return 0; default: // all other (large) arguments - // set z = scalbn(|x|,-ilogb(x)+23) - u = bitcast(x, ulong); - u &= ((ulong)-1) >> 12; - u |= (ulong)(0x3ff + 23) << 52; - double z = bitcast(u, double); - double[3] tx; - int i; - for (i = 0; i < 2; i++) - { - tx[i] = (double)(int)z; - z = (z - tx[i]) * 0x1p24; - } - tx[i] = z; - // skip zero terms, first term is non-zero - while (tx[i] == 0.0) i--; - double[2] ty; - int n = __rem_pio2_large(&tx, &ty, (int)(ix >> 20) - (0x3ff + 23), i + 1, 1); - if (sign) - { - y[0] = -ty[0]; - y[1] = -ty[1]; - return -n; - } - y[0] = ty[0]; - y[1] = ty[1]; - return n; + // set z = scalbn(|x|,-ilogb(x)+23) + u = bitcast(x, ulong); + u &= ((ulong)-1) >> 12; + u |= (ulong)(0x3ff + 23) << 52; + double z = bitcast(u, double); + double[3] tx; + int i; + for (i = 0; i < 2; i++) + { + tx[i] = (double)(int)z; + z = (z - tx[i]) * 0x1p24; + } + tx[i] = z; + // skip zero terms, first term is non-zero + while (tx[i] == 0.0) i--; + double[2] ty; + int n = __rem_pio2_large(&tx, &ty, (int)(ix >> 20) - (0x3ff + 23), i + 1, 1); + if (sign) + { + y[0] = -ty[0]; + y[1] = -ty[1]; + return -n; + } + y[0] = ty[0]; + y[1] = ty[1]; + return n; } // |x| ~< 2^20*(pi/2), medium size diff --git a/lib/std/math/math_nolibc/sincos.c3 b/lib/std/math/math_nolibc/sincos.c3 index 92b64eeaf..720bdfe46 100644 --- a/lib/std/math/math_nolibc/sincos.c3 +++ b/lib/std/math/math_nolibc/sincos.c3 @@ -64,20 +64,20 @@ fn void sincosf(float x, float *sin, float *cos) @extern("sincosf") @weak @nostr if (ix <= 0x40afeddf) { // |x| ~<= 7*pi/4 - if (sign) - { - *sin = __cosdf(x + S3PI2); - *cos = -__sindf(x + S3PI2); - return; - } - *sin = -__cosdf(x - S3PI2); - *cos = __sindf(x - S3PI2); - return; - } - *sin = __sindf(sign ? x + S4PI2 : x - S4PI2); - *cos = __cosdf(sign ? x + S4PI2 : x - S4PI2); - case ix >= 0x7f800000: - // sin(Inf or NaN) is NaN + if (sign) + { + *sin = __cosdf(x + S3PI2); + *cos = -__sindf(x + S3PI2); + return; + } + *sin = -__cosdf(x - S3PI2); + *cos = __sindf(x - S3PI2); + return; + } + *sin = __sindf(sign ? x + S4PI2 : x - S4PI2); + *cos = __cosdf(sign ? x + S4PI2 : x - S4PI2); + case ix >= 0x7f800000: + // sin(Inf or NaN) is NaN *sin = *cos = x - x; default: // general argument reduction needed @@ -129,8 +129,8 @@ fn void sincos(double x, double *sin, double *cos) @extern("sincos") @weak @nost *cos = __cos(x, 0.0); // sincos(Inf or NaN) is NaN case ix >= 0x7ff00000: - *sin = *cos = x - x; - default: + *sin = *cos = x - x; + default: // argument reduction needed double[2] y; int n = __rem_pio2(x, &y); diff --git a/lib/std/math/math_nolibc/tan.c3 b/lib/std/math/math_nolibc/tan.c3 index 3817462d6..e9f3265f1 100644 --- a/lib/std/math/math_nolibc/tan.c3 +++ b/lib/std/math/math_nolibc/tan.c3 @@ -30,13 +30,13 @@ fn double tan(double x) @extern("tan") @weak @nostrip } return __tan(x, 0.0, 0); // tan(Inf or NaN) is NaN - case ix >= 0x7ff00000: - return x - x; + case ix >= 0x7ff00000: + return x - x; default: // argument reduction double[2] y; uint n = __rem_pio2(x, &y); - return __tan(y[0], y[1], n & 1); + return __tan(y[0], y[1], n & 1); } } diff --git a/lib/std/math/math_random.c3 b/lib/std/math/math_random.c3 index fc6ff98dd..e58929cd3 100644 --- a/lib/std/math/math_random.c3 +++ b/lib/std/math/math_random.c3 @@ -39,8 +39,8 @@ macro int next(random, uint range) if (range == 1) return 0; uint mask = ~0U; range--; - mask >>= range.clz(); - uint x @noinit; + mask >>= range.clz(); + uint x @noinit; do { x = random.next_int() & mask; diff --git a/lib/std/math/random/math.seeder.c3 b/lib/std/math/random/math.seeder.c3 index 0900915bd..af1fc35e4 100644 --- a/lib/std/math/random/math.seeder.c3 +++ b/lib/std/math/random/math.seeder.c3 @@ -88,8 +88,8 @@ fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC) hash(clock::now()), hash(&DString.new_init), hash(allocator::heap()) - }; - return bitcast(entropy_data, char[8 * 4]); + }; + return bitcast(entropy_data, char[8 * 4]); } fn char[8 * 4] entropy() @if(env::WASM_NOLIBC) @@ -105,6 +105,6 @@ fn char[8 * 4] entropy() @if(env::WASM_NOLIBC) random_int, hash($$TIME), hash(&entropy), - }; - return bitcast(entropy_data, char[8 * 4]); + }; + return bitcast(entropy_data, char[8 * 4]); } \ No newline at end of file diff --git a/lib/std/net/os/posix.c3 b/lib/std/net/os/posix.c3 index b3a73e776..499537d62 100644 --- a/lib/std/net/os/posix.c3 +++ b/lib/std/net/os/posix.c3 @@ -44,7 +44,7 @@ fn anyfault convert_error(Errno error) case errno::ENETUNREACH: return NetError.NETWORK_UNREACHABLE; case errno::ENOTSOCK: return NetError.NOT_A_SOCKET; case errno::EINTR: return IoError.INTERRUPTED; - case errno::EWOULDBLOCK: return IoError.WOULD_BLOCK; + case errno::EWOULDBLOCK: return IoError.WOULD_BLOCK; case errno::EOPNOTSUPP: return NetError.OPERATION_NOT_SUPPORTED_ON_SOCKET; case errno::ETIMEDOUT: return NetError.CONNECTION_TIMED_OUT; default: return IoError.GENERAL_ERROR; diff --git a/lib/std/net/os/win32.c3 b/lib/std/net/os/win32.c3 index 4b7db87a6..826c9a8db 100644 --- a/lib/std/net/os/win32.c3 +++ b/lib/std/net/os/win32.c3 @@ -71,17 +71,17 @@ fn anyfault convert_error(WSAError error) case wsa::EACCESS: return IoError.NO_PERMISSION; case wsa::EINPROGRESS: return NetError.STILL_PROCESSING_CALLBACK; case wsa::EADDRINUSE: return NetError.ADDRESS_IN_USE; - case wsa::EALREADY: return NetError.CONNECTION_ALREADY_IN_PROGRESS; - case wsa::EBADF: return NetError.BAD_SOCKET_DESCRIPTOR; - case wsa::EINTR: return IoError.INTERRUPTED; - case wsa::EWOULDBLOCK: return IoError.WOULD_BLOCK; - case wsa::ECONNREFUSED: return NetError.CONNECTION_REFUSED; - case wsa::EISCONN: return NetError.ALREADY_CONNECTED; - case wsa::ENETUNREACH: return NetError.NETWORK_UNREACHABLE; - case wsa::ENOTSOCK: return NetError.NOT_A_SOCKET; - case wsa::EOPNOTSUPP: return NetError.OPERATION_NOT_SUPPORTED_ON_SOCKET; - case wsa::ETIMEDOUT: return NetError.CONNECTION_TIMED_OUT; - case wsa::ECONNRESET: return NetError.CONNECTION_RESET; + case wsa::EALREADY: return NetError.CONNECTION_ALREADY_IN_PROGRESS; + case wsa::EBADF: return NetError.BAD_SOCKET_DESCRIPTOR; + case wsa::EINTR: return IoError.INTERRUPTED; + case wsa::EWOULDBLOCK: return IoError.WOULD_BLOCK; + case wsa::ECONNREFUSED: return NetError.CONNECTION_REFUSED; + case wsa::EISCONN: return NetError.ALREADY_CONNECTED; + case wsa::ENETUNREACH: return NetError.NETWORK_UNREACHABLE; + case wsa::ENOTSOCK: return NetError.NOT_A_SOCKET; + case wsa::EOPNOTSUPP: return NetError.OPERATION_NOT_SUPPORTED_ON_SOCKET; + case wsa::ETIMEDOUT: return NetError.CONNECTION_TIMED_OUT; + case wsa::ECONNRESET: return NetError.CONNECTION_RESET; default: return IoError.GENERAL_ERROR; } } diff --git a/lib/std/net/socket_private.c3 b/lib/std/net/socket_private.c3 index 4301a3c49..77f4b2d81 100644 --- a/lib/std/net/socket_private.c3 +++ b/lib/std/net/socket_private.c3 @@ -29,9 +29,9 @@ fn bool last_error_is_delayed_connect() case wsa::EINPROGRESS: return true; default: return false; } - $default: - Errno err = libc::errno(); - return err == errno::EINPROGRESS || err == errno::EAGAIN || err == errno::EWOULDBLOCK; + $default: + Errno err = libc::errno(); + return err == errno::EINPROGRESS || err == errno::EAGAIN || err == errno::EWOULDBLOCK; $endswitch } diff --git a/lib/std/os/macos/darwin.c3 b/lib/std/os/macos/darwin.c3 index d81b59acd..6c8fe9203 100644 --- a/lib/std/os/macos/darwin.c3 +++ b/lib/std/os/macos/darwin.c3 @@ -81,7 +81,7 @@ fn uptr! load_address() @local Darwin_segment_command_64* cmd = darwin::getsegbyname("__TEXT"); if (!cmd) return BacktraceFault.SEGMENT_NOT_FOUND?; String path = env::new_executable_path(allocator::temp()) ?? BacktraceFault.EXECUTABLE_PATH_NOT_FOUND?!; - uint dyld_count = darwin::_dyld_image_count(); + uint dyld_count = darwin::_dyld_image_count(); for (uint i = 0; i < dyld_count; i++) { ZString image_name = darwin::_dyld_get_image_name(i); @@ -111,11 +111,11 @@ fn Backtrace! backtrace_load_element(String execpath, void* buffer, void* load_a String[] path_parts = parts[3].tsplit(":"); return { .offset = (uptr)buffer, - .function = parts[0].copy(allocator), - .object_file = parts[2][..^2].copy(allocator), - .file = path_parts[0][1..].copy(allocator), - .line = path_parts[1][..^2].to_uint()!, - .allocator = allocator + .function = parts[0].copy(allocator), + .object_file = parts[2][..^2].copy(allocator), + .file = path_parts[0][1..].copy(allocator), + .line = path_parts[1][..^2].to_uint()!, + .allocator = allocator }; } } diff --git a/lib/std/os/posix/process.c3 b/lib/std/os/posix/process.c3 index 564a3beca..b2dd4f9b8 100644 --- a/lib/std/os/posix/process.c3 +++ b/lib/std/os/posix/process.c3 @@ -77,16 +77,16 @@ fn CInt backtrace(void** buffer, CInt size) libc::longjmp(&backtrace_jmpbuf, 1); }; SignalFunction sig_bus = libc::signal(libc::SIGBUS, restore_backtrace); - SignalFunction sig_segv = libc::signal(libc::SIGSEGV, restore_backtrace); - SignalFunction sig_ill = libc::signal(libc::SIGILL, restore_backtrace); + SignalFunction sig_segv = libc::signal(libc::SIGSEGV, restore_backtrace); + SignalFunction sig_ill = libc::signal(libc::SIGILL, restore_backtrace); void*[128] buffer_first; int i = 0; - for (i = 0; i < size; i++) - { + for (i = 0; i < size; i++) + { if (libc::setjmp(&backtrace_jmpbuf) == 1) break; - buffer[i] = builtin::get_returnaddress(i); - if (!buffer[i]) break; + buffer[i] = builtin::get_returnaddress(i); + if (!buffer[i]) break; } libc::signal(libc::SIGBUS, sig_bus); libc::signal(libc::SIGSEGV, sig_segv); diff --git a/lib/std/os/win32/types.c3 b/lib/std/os/win32/types.c3 index 20bf52540..443c428bb 100644 --- a/lib/std/os/win32/types.c3 +++ b/lib/std/os/win32/types.c3 @@ -323,38 +323,38 @@ enum Win32_SYM_TYPE struct Win32_GUID { CULong data1; - CUShort data2; - CUShort data3; - char[8] data4; + CUShort data2; + CUShort data3; + char[8] data4; } struct Win32_IMAGEHLP_MODULE64 { - Win32_DWORD sizeOfStruct; - Win32_DWORD64 baseOfImage; - Win32_DWORD imageSize; - Win32_DWORD timeDateStamp; - Win32_DWORD checkSum; - Win32_DWORD numSyms; - Win32_SYM_TYPE symType; - Win32_CHAR[32] moduleName; - Win32_CHAR[256] imageName; - Win32_CHAR[256] loadedImageName; - Win32_CHAR[256] loadedPdbName; - Win32_DWORD cVSig; - Win32_CHAR** cVData; - Win32_DWORD pdbSig; - Win32_GUID pdbSig70; - Win32_DWORD pdbAge; - Win32_BOOL pdbUnmatched; - Win32_BOOL dbgUnmatched; - Win32_BOOL lineNumbers; - Win32_BOOL globalSymbols; - Win32_BOOL typeInfo; - Win32_BOOL sourceIndexed; - Win32_BOOL publics; - Win32_DWORD machineType; - Win32_DWORD reserved; + Win32_DWORD sizeOfStruct; + Win32_DWORD64 baseOfImage; + Win32_DWORD imageSize; + Win32_DWORD timeDateStamp; + Win32_DWORD checkSum; + Win32_DWORD numSyms; + Win32_SYM_TYPE symType; + Win32_CHAR[32] moduleName; + Win32_CHAR[256] imageName; + Win32_CHAR[256] loadedImageName; + Win32_CHAR[256] loadedPdbName; + Win32_DWORD cVSig; + Win32_CHAR** cVData; + Win32_DWORD pdbSig; + Win32_GUID pdbSig70; + Win32_DWORD pdbAge; + Win32_BOOL pdbUnmatched; + Win32_BOOL dbgUnmatched; + Win32_BOOL lineNumbers; + Win32_BOOL globalSymbols; + Win32_BOOL typeInfo; + Win32_BOOL sourceIndexed; + Win32_BOOL publics; + Win32_DWORD machineType; + Win32_DWORD reserved; } def Win32_PIMAGEHLP_MODULE64 = Win32_IMAGEHLP_MODULE64*; @@ -363,44 +363,44 @@ struct Win32_ARM64_NT_CONTEXT @align(16) { Win32_DWORD contextFlags; Win32_DWORD cpsr; - union - { + union + { struct { - Win32_DWORD64 x0; - Win32_DWORD64 x1; - Win32_DWORD64 x2; - Win32_DWORD64 x3; - Win32_DWORD64 x4; - Win32_DWORD64 x5; - Win32_DWORD64 x6; - Win32_DWORD64 x7; - Win32_DWORD64 x8; - Win32_DWORD64 x9; - Win32_DWORD64 x10; - Win32_DWORD64 x11; - Win32_DWORD64 x12; - Win32_DWORD64 x13; - Win32_DWORD64 x14; - Win32_DWORD64 x15; - Win32_DWORD64 x16; - Win32_DWORD64 x17; - Win32_DWORD64 x18; - Win32_DWORD64 x19; - Win32_DWORD64 x20; - Win32_DWORD64 x21; - Win32_DWORD64 x22; - Win32_DWORD64 x23; - Win32_DWORD64 x24; - Win32_DWORD64 x25; - Win32_DWORD64 x26; - Win32_DWORD64 x27; - Win32_DWORD64 x28; - Win32_DWORD64 fp; - Win32_DWORD64 lr; - } - Win32_DWORD64[31] x; - } + Win32_DWORD64 x0; + Win32_DWORD64 x1; + Win32_DWORD64 x2; + Win32_DWORD64 x3; + Win32_DWORD64 x4; + Win32_DWORD64 x5; + Win32_DWORD64 x6; + Win32_DWORD64 x7; + Win32_DWORD64 x8; + Win32_DWORD64 x9; + Win32_DWORD64 x10; + Win32_DWORD64 x11; + Win32_DWORD64 x12; + Win32_DWORD64 x13; + Win32_DWORD64 x14; + Win32_DWORD64 x15; + Win32_DWORD64 x16; + Win32_DWORD64 x17; + Win32_DWORD64 x18; + Win32_DWORD64 x19; + Win32_DWORD64 x20; + Win32_DWORD64 x21; + Win32_DWORD64 x22; + Win32_DWORD64 x23; + Win32_DWORD64 x24; + Win32_DWORD64 x25; + Win32_DWORD64 x26; + Win32_DWORD64 x27; + Win32_DWORD64 x28; + Win32_DWORD64 fp; + Win32_DWORD64 lr; + } + Win32_DWORD64[31] x; + } Win32_DWORD64 sp; Win32_DWORD64 pc; Win32_ARM64_NT_NEON128[32] v; @@ -416,8 +416,8 @@ const ARM64_MAX_WATCHPOINTS = 2; struct Win32_ARM64_NT_NEON128 { - Win32_ULONGLONG low; - Win32_LONGLONG high; + Win32_ULONGLONG low; + Win32_LONGLONG high; } struct Win32_XMM_SAVE_AREA32 @@ -480,34 +480,34 @@ struct Win32_AMD64_CONTEXT @align(16) Win32_DWORD64 r14; Win32_DWORD64 r15; Win32_DWORD64 rip; - union - { - Win32_XMM_SAVE_AREA32 fltSave; - //Win32_NEON128[16] q; - Win32_ULONGLONG[32] d; - struct - { - Win32_M128A[2] header; - Win32_M128A[8] legacy; - Win32_M128A xmm0; - Win32_M128A xmm1; - Win32_M128A xmm2; - Win32_M128A xmm3; - Win32_M128A xmm4; - Win32_M128A xmm5; - Win32_M128A xmm6; - Win32_M128A xmm7; - Win32_M128A xmm8; - Win32_M128A xmm9; - Win32_M128A xmm10; - Win32_M128A xmm11; - Win32_M128A xmm12; - Win32_M128A xmm13; - Win32_M128A xmm14; - Win32_M128A xmm15; - } - Win32_DWORD[32] s; - } + union + { + Win32_XMM_SAVE_AREA32 fltSave; + //Win32_NEON128[16] q; + Win32_ULONGLONG[32] d; + struct + { + Win32_M128A[2] header; + Win32_M128A[8] legacy; + Win32_M128A xmm0; + Win32_M128A xmm1; + Win32_M128A xmm2; + Win32_M128A xmm3; + Win32_M128A xmm4; + Win32_M128A xmm5; + Win32_M128A xmm6; + Win32_M128A xmm7; + Win32_M128A xmm8; + Win32_M128A xmm9; + Win32_M128A xmm10; + Win32_M128A xmm11; + Win32_M128A xmm12; + Win32_M128A xmm13; + Win32_M128A xmm14; + Win32_M128A xmm15; + } + Win32_DWORD[32] s; + } Win32_M128A[26] vectorRegister; Win32_DWORD64 vectorControl; Win32_DWORD64 debugControl; @@ -535,14 +535,14 @@ def Win32_PCONTEXT = Win32_CONTEXT*; struct Win32_M128A @align(16) { - Win32_ULONGLONG low; - Win32_LONGLONG high; + Win32_ULONGLONG low; + Win32_LONGLONG high; } struct Win32_IMAGE_DATA_DIRECTORY { - Win32_ULONG virtualAddress; - Win32_ULONG size; + Win32_ULONG virtualAddress; + Win32_ULONG size; } struct Win32_IMAGE_OPTIONAL_HEADER64 @@ -582,22 +582,22 @@ struct Win32_IMAGE_OPTIONAL_HEADER64 def Win32_PIMAGE_OPTIONAL_HEADER64 = Win32_IMAGE_OPTIONAL_HEADER64*; struct Win32_IMAGE_FILE_HEADER { - Win32_WORD machine; - Win32_WORD numberOfSections; - Win32_DWORD timeDateStamp; - Win32_DWORD pointerToSymbolTable; - Win32_DWORD numberOfSymbols; - Win32_WORD sizeOfOptionalHeader; - Win32_WORD characteristics; + Win32_WORD machine; + Win32_WORD numberOfSections; + Win32_DWORD timeDateStamp; + Win32_DWORD pointerToSymbolTable; + Win32_DWORD numberOfSymbols; + Win32_WORD sizeOfOptionalHeader; + Win32_WORD characteristics; } def Win32_PIMAGE_FILE_HEADER = Win32_IMAGE_FILE_HEADER*; struct Win32_IMAGE_NT_HEADERS { - Win32_DWORD signature; - Win32_IMAGE_FILE_HEADER fileHeader; - Win32_IMAGE_OPTIONAL_HEADER64 optionalHeader; + Win32_DWORD signature; + Win32_IMAGE_FILE_HEADER fileHeader; + Win32_IMAGE_OPTIONAL_HEADER64 optionalHeader; } def Win32_PIMAGE_NT_HEADERS = Win32_IMAGE_NT_HEADERS*; @@ -635,9 +635,9 @@ struct Win32_MODLOAD_DATA enum Win32_ADDRESS_MODE { ADDR_MODE_1616, - ADDR_MODE_1632, - ADDR_MODE_REAL, - ADDR_MODE_FLAT, + ADDR_MODE_1632, + ADDR_MODE_REAL, + ADDR_MODE_FLAT, } struct Win32_ADDRESS64 @@ -649,23 +649,23 @@ struct Win32_ADDRESS64 struct Win32_KDHELP64 { - Win32_DWORD64 thread; - Win32_DWORD thCallbackStack; - Win32_DWORD thCallbackBStore; - Win32_DWORD nextCallback; - Win32_DWORD framePointer; - Win32_DWORD64 kiCallUserMode; - Win32_DWORD64 keUserCallbackDispatcher; - Win32_DWORD64 systemRangeStart; - Win32_DWORD64 kiUserExceptionDispatcher; - Win32_DWORD64 stackBase; - Win32_DWORD64 stackLimit; - Win32_DWORD buildVersion; - Win32_DWORD retpolineStubFunctionTableSize; - Win32_DWORD64 retpolineStubFunctionTable; - Win32_DWORD retpolineStubOffset; - Win32_DWORD retpolineStubSize; - Win32_DWORD64[2] reserved0; + Win32_DWORD64 thread; + Win32_DWORD thCallbackStack; + Win32_DWORD thCallbackBStore; + Win32_DWORD nextCallback; + Win32_DWORD framePointer; + Win32_DWORD64 kiCallUserMode; + Win32_DWORD64 keUserCallbackDispatcher; + Win32_DWORD64 systemRangeStart; + Win32_DWORD64 kiUserExceptionDispatcher; + Win32_DWORD64 stackBase; + Win32_DWORD64 stackLimit; + Win32_DWORD buildVersion; + Win32_DWORD retpolineStubFunctionTableSize; + Win32_DWORD64 retpolineStubFunctionTable; + Win32_DWORD retpolineStubOffset; + Win32_DWORD retpolineStubSize; + Win32_DWORD64[2] reserved0; } struct Win32_STACKFRAME64 diff --git a/lib/std/sort/quicksort.c3 b/lib/std/sort/quicksort.c3 index ec78dca65..3ce5722f0 100644 --- a/lib/std/sort/quicksort.c3 +++ b/lib/std/sort/quicksort.c3 @@ -43,34 +43,34 @@ fn void qsort(Type list, isz low, isz high, CmpFn cmp, Context context) isz h; while (i >= 0) { - l = stack[i].low; - h = stack[i].high; + l = stack[i].low; + h = stack[i].high; - if (l < h) - { + if (l < h) + { ElementType pivot = list[l]; while (l < h) { $switch $case $cmp_by_value && $has_context: while (cmp(list[h], pivot, context) >= 0 && l < h) h--; - if (l < h) list[l++] = list[h]; + if (l < h) list[l++] = list[h]; while (cmp(list[l], pivot, context) <= 0 && l < h) l++; $case $cmp_by_value: while (cmp(list[h], pivot) >= 0 && l < h) h--; - if (l < h) list[l++] = list[h]; + if (l < h) list[l++] = list[h]; while (cmp(list[l], pivot) <= 0 && l < h) l++; $case $has_cmp && $has_context: while (cmp(&list[h], &pivot, context) >= 0 && l < h) h--; - if (l < h) list[l++] = list[h]; + if (l < h) list[l++] = list[h]; while (cmp(&list[l], &pivot, context) <= 0 && l < h) l++; $case $has_cmp: while (cmp(&list[h], &pivot) >= 0 && l < h) h--; - if (l < h) list[l++] = list[h]; + if (l < h) list[l++] = list[h]; while (cmp(&list[l], &pivot) <= 0 && l < h) l++; $default: while (greater_eq(list[h], pivot) && l < h) h--; - if (l < h) list[l++] = list[h]; + if (l < h) list[l++] = list[h]; while (less_eq(list[l], pivot) && l < h) l++; $endswitch if (l < h) list[h--] = list[l]; @@ -83,11 +83,11 @@ fn void qsort(Type list, isz low, isz high, CmpFn cmp, Context context) { @swap(stack[i], stack[i - 1]); } - } - else - { + } + else + { i--; - } + } } } } diff --git a/lib/std/sort/sort.c3 b/lib/std/sort/sort.c3 index 24208ff73..44eda87dd 100644 --- a/lib/std/sort/sort.c3 +++ b/lib/std/sort/sort.c3 @@ -34,7 +34,7 @@ macro bool @is_valid_cmp_fn(#cmp, #list, #context) var $no_context = @is_empty_macro_slot(#context); $switch $case @is_empty_macro_slot(#cmp): return true; - $case $Type.kindof != FUNC ||| $Type.returns.kindof != SIGNED_INT: return false; + $case $Type.kindof != FUNC ||| $Type.returns.kindof != SIGNED_INT: return false; $case $defined(#cmp(#list[0], #list[0], #context)): return true; $case $defined(#cmp(#list[0], #list[0])): return $no_context; $case $defined(#cmp(&#list[0], &#list[0], #context)): return true; @@ -47,8 +47,8 @@ macro bool @is_cmp_key_fn(#key_fn, #list) { $switch $case @is_empty_macro_slot(#key_fn): return true; - $case $typeof(#key_fn).kindof != FUNC: return false; - $case $typeof(#key_fn).returns.kindof != UNSIGNED_INT: return false; + $case $typeof(#key_fn).kindof != FUNC: return false; + $case $typeof(#key_fn).returns.kindof != UNSIGNED_INT: return false; $case $defined(#key_fn(#list[0])): return true; $case $defined(#key_fn(&&(#list[0]))): return true; $default: return false;