From 2439405e70e5bcc6cc64905f92d2e3c4e5911c38 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 4 Mar 2025 16:13:06 +0100 Subject: [PATCH] - `$foreach` "()" replaced by trailing ":" `$foreach ($x, $y : $foo)` -> `$foreach $x, $y : $foo:` - `$for` "()" replaced by trailing ":" `$for (var $x = 0; $x < FOO; $x++)` -> `$for var $x = 0; $x < FOO; $x++:` - `$switch` "()" replaced by trailing ":" `$switch ($Type)` -> `$switch $Type:` - Empty `$switch` requires trailing ":" `$switch` -> `$switch:` --- lib/std/collections/enumset.c3 | 2 +- lib/std/collections/hashmap.c3 | 2 +- lib/std/collections/object.c3 | 2 +- lib/std/core/allocators/libc_allocator.c3 | 2 +- lib/std/core/bitorder.c3 | 10 ++++----- lib/std/core/builtin.c3 | 8 +++---- lib/std/core/builtin_comparison.c3 | 16 +++++++------- lib/std/core/cinterop.c3 | 4 ++-- lib/std/core/dstring.c3 | 8 +++---- lib/std/core/env.c3 | 4 ++-- lib/std/core/mem.c3 | 2 +- lib/std/core/mem_allocator.c3 | 2 +- lib/std/core/string_to_real.c3 | 2 +- lib/std/core/types.c3 | 22 +++++++++---------- lib/std/core/values.c3 | 2 +- lib/std/io/formatter.c3 | 2 +- lib/std/io/io.c3 | 4 ++-- lib/std/io/os/chdir.c3 | 2 +- lib/std/io/os/fileinfo.c3 | 4 ++-- lib/std/io/os/getcwd.c3 | 2 +- lib/std/io/os/mkdir.c3 | 2 +- lib/std/io/os/rmdir.c3 | 2 +- lib/std/io/stream.c3 | 2 +- lib/std/math/math.c3 | 20 ++++++++--------- lib/std/math/math_i128.c3 | 8 +++---- lib/std/net/socket_private.c3 | 2 +- lib/std/os/backtrace.c3 | 2 +- lib/std/os/env.c3 | 6 ++--- lib/std/sort/binarysearch.c3 | 2 +- lib/std/sort/countingsort.c3 | 4 ++-- lib/std/sort/insertionsort.c3 | 4 ++-- lib/std/sort/quicksort.c3 | 2 +- lib/std/sort/sort.c3 | 6 ++--- lib/std/sort/sorted.c3 | 2 +- releasenotes.md | 4 ++++ src/compiler/parse_stmt.c | 22 ++++++++----------- test/test_suite/assert/assert_with_void.c3 | 6 ++--- .../compile_time/compile_time_array_bug.c3t | 2 +- .../compile_time/compile_time_utf32.c3 | 12 +++++----- test/test_suite/compile_time/concat_const.c3 | 2 +- .../compile_time/concat_slice_array.c3 | 2 +- test/test_suite/compile_time/ct_assert_bug.c3 | 2 +- .../compile_time/ct_enum_values.c3t | 2 +- test/test_suite/compile_time/ct_for.c3t | 4 ++-- .../compile_time/ct_forach_with_defer.c3t | 4 ++-- test/test_suite/compile_time/ct_foreach.c3t | 8 +++---- test/test_suite/compile_time/ct_memberof.c3t | 4 ++-- test/test_suite/compile_time/ct_switch.c3t | 2 +- .../compile_time/ct_switch_errors.c3 | 6 ++--- .../compile_time/ct_switch_more_checks.c3 | 8 +++---- .../compile_time/ct_switch_top_level.c3t | 2 +- .../compile_time/ct_switch_type_check.c3t | 2 +- .../compile_time/ct_switch_type_errors.c3 | 8 +++---- .../compile_time_introspection/paramsof.c3t | 2 +- .../compile_time_introspection/tag_1343.c3t | 2 +- test/test_suite/debug_symbols/ct_foreach.c3t | 2 +- .../enumerations/enum_reflect_associated.c3t | 2 +- test/test_suite/expressions/type_support.c3t | 2 +- test/test_suite/functions/raw_splat.c3t | 2 +- .../generic/generic_lambda_complex.c3t | 4 ++-- test/test_suite/lambda/ct_lambda2.c3t | 2 +- .../macros/macro_untyped_varargs_2.c3t | 6 ++--- test/test_suite/macros/userland_bitcast.c3t | 2 +- test/unit/regression/subtype.c3 | 2 +- test/unit/stdlib/math/math_is_even_odd.c3 | 2 +- 65 files changed, 149 insertions(+), 149 deletions(-) diff --git a/lib/std/collections/enumset.c3 b/lib/std/collections/enumset.c3 index 68cf9d807..572dff60d 100644 --- a/lib/std/collections/enumset.c3 +++ b/lib/std/collections/enumset.c3 @@ -143,7 +143,7 @@ fn usz! EnumSet.to_format(&set, Formatter* formatter) @dynamic macro typeid type_for_enum_elements(usz $elements) @local { - $switch + $switch: $case ($elements > 128): return char[($elements + 7) / 8].typeid; $case ($elements > 64): diff --git a/lib/std/collections/hashmap.c3 b/lib/std/collections/hashmap.c3 index 6bfc2fdd9..b0b9d67b8 100644 --- a/lib/std/collections/hashmap.c3 +++ b/lib/std/collections/hashmap.c3 @@ -75,7 +75,7 @@ fn HashMap* HashMap.tinit(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float macro HashMap* HashMap.init_with_key_values(&self, Allocator allocator, ..., uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) { self.init(allocator, capacity, load_factor); - $for (var $i = 0; $i < $vacount; $i += 2) + $for var $i = 0; $i < $vacount; $i += 2: self.set($vaarg[$i], $vaarg[$i + 1]); $endfor return self; diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index b2ce81704..8fbbbf66d 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -189,7 +189,7 @@ fn void Object.set_object(&self, String key, Object* new_object) @private macro Object* Object.object_from_value(&self, value) @private { var $Type = $typeof(value); - $switch + $switch: $case types::is_int($Type): return new_int(value, self.allocator); $case types::is_float($Type): diff --git a/lib/std/core/allocators/libc_allocator.c3 b/lib/std/core/allocators/libc_allocator.c3 index 377e9a223..87e2de68e 100644 --- a/lib/std/core/allocators/libc_allocator.c3 +++ b/lib/std/core/allocators/libc_allocator.c3 @@ -54,7 +54,7 @@ fn void*! LibcAllocator.resize(&self, void* old_ptr, usz new_bytes, usz alignmen void* new_ptr; if (posix::posix_memalign(&new_ptr, alignment, new_bytes)) return AllocationFailure.OUT_OF_MEMORY?; - $switch + $switch: $case env::DARWIN: usz old_usable_size = darwin::malloc_size(old_ptr); $case env::LINUX: diff --git a/lib/std/core/bitorder.c3 b/lib/std/core/bitorder.c3 index 0b49cee2d..945a72324 100644 --- a/lib/std/core/bitorder.c3 +++ b/lib/std/core/bitorder.c3 @@ -94,7 +94,7 @@ bitstruct UInt128LE : uint128 @littleendian macro read(bytes, $Type) { char[] s; - $switch (@typekind(bytes)) + $switch @typekind(bytes): $case POINTER: s = (*bytes)[:$Type.sizeof]; $default: @@ -110,7 +110,7 @@ macro read(bytes, $Type) macro write(x, bytes, $Type) { char[] s; - $switch (@typekind(bytes)) + $switch @typekind(bytes): $case POINTER: s = (*bytes)[:$Type.sizeof]; $default: @@ -121,7 +121,7 @@ macro write(x, bytes, $Type) macro is_bitorder($Type) { - $switch ($Type) + $switch $Type: $case UShortLE: $case ShortLE: $case UIntLE: @@ -146,7 +146,7 @@ macro is_bitorder($Type) macro bool is_array_or_slice_of_char(bytes) { - $switch (@typekind(bytes)) + $switch @typekind(bytes): $case POINTER: var $Inner = $typefrom($typeof(bytes).inner); $if $Inner.kindof == ARRAY: @@ -164,7 +164,7 @@ macro bool is_array_or_slice_of_char(bytes) macro bool is_arrayptr_or_slice_of_char(bytes) { - $switch (@typekind(bytes)) + $switch @typekind(bytes): $case POINTER: var $Inner = $typefrom($typeof(bytes).inner); $if $Inner.kindof == ARRAY: diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index d5ef1de49..0ada5cfc2 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -286,7 +286,7 @@ macro @enum_from_value($Type, #value, value) @builtin *> macro bool @likely(bool #value, $probability = 1.0) @builtin { - $switch + $switch: $case env::BUILTIN_EXPECT_IS_DISABLED: return #value; $case $probability == 1.0: @@ -305,7 +305,7 @@ macro bool @likely(bool #value, $probability = 1.0) @builtin *> macro bool @unlikely(bool #value, $probability = 1.0) @builtin { - $switch + $switch: $case env::BUILTIN_EXPECT_IS_DISABLED: return #value; $case $probability == 1.0: @@ -322,7 +322,7 @@ macro bool @unlikely(bool #value, $probability = 1.0) @builtin *> macro @expect(#value, expected, $probability = 1.0) @builtin { - $switch + $switch: $case env::BUILTIN_EXPECT_IS_DISABLED: return #value == expected; $case $probability == 1.0: @@ -415,7 +415,7 @@ macro @generic_hash_core(h, value) macro @generic_hash(value) { uint h = @generic_hash_core((uint)0x3efd4391, value); - $for (var $cnt = 4; $cnt < $sizeof(value); $cnt += 4) + $for var $cnt = 4; $cnt < $sizeof(value); $cnt += 4: value >>= 32; // reduce value h = @generic_hash_core(h, value); $endfor diff --git a/lib/std/core/builtin_comparison.c3 b/lib/std/core/builtin_comparison.c3 index b511fb70e..c55195407 100644 --- a/lib/std/core/builtin_comparison.c3 +++ b/lib/std/core/builtin_comparison.c3 @@ -8,7 +8,7 @@ module std::core::builtin; *> macro less(a, b) @builtin { - $switch + $switch: $case $defined(a.less): return a.less(b); $case $defined(a.compare_to): @@ -23,7 +23,7 @@ macro less(a, b) @builtin *> macro less_eq(a, b) @builtin { - $switch + $switch: $case $defined(a.less): return !b.less(a); $case $defined(a.compare_to): @@ -38,7 +38,7 @@ macro less_eq(a, b) @builtin *> macro greater(a, b) @builtin { - $switch + $switch: $case $defined(a.less): return b.less(a); $case $defined(a.compare_to): @@ -53,7 +53,7 @@ macro greater(a, b) @builtin *> macro int compare_to(a, b) @builtin { - $switch + $switch: $case $defined(a.compare_to): return a.compare_to(b); $case $defined(a.less): @@ -67,7 +67,7 @@ macro int compare_to(a, b) @builtin *> macro greater_eq(a, b) @builtin { - $switch + $switch: $case $defined(a.less): return !a.less(b); $case $defined(a.compare_to): @@ -82,7 +82,7 @@ macro greater_eq(a, b) @builtin *> macro bool equals(a, b) @builtin { - $switch + $switch: $case $defined(a.equals, a.equals(b)): return a.equals(b); $case $defined(a.compare_to, a.compare_to(b)): @@ -100,7 +100,7 @@ macro min(x, ...) @builtin return less(x, $vaarg[0]) ? x : $vaarg[0]; $else var result = x; - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: if (less($vaarg[$i], result)) { result = $vaarg[$i]; @@ -116,7 +116,7 @@ macro max(x, ...) @builtin return greater(x, $vaarg[0]) ? x : $vaarg[0]; $else var result = x; - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: if (greater($vaarg[$i], result)) { result = $vaarg[$i]; diff --git a/lib/std/core/cinterop.c3 b/lib/std/core/cinterop.c3 index 5cb9e6ca9..e4f38b47d 100644 --- a/lib/std/core/cinterop.c3 +++ b/lib/std/core/cinterop.c3 @@ -38,7 +38,7 @@ enum CBool : char // Helper macros macro typeid signed_int_from_bitsize(usz $bitsize) @private { - $switch ($bitsize) + $switch $bitsize: $case 128: return int128.typeid; $case 64: return long.typeid; $case 32: return int.typeid; @@ -50,7 +50,7 @@ macro typeid signed_int_from_bitsize(usz $bitsize) @private macro typeid unsigned_int_from_bitsize(usz $bitsize) @private { - $switch ($bitsize) + $switch $bitsize: $case 128: return uint128.typeid; $case 64: return ulong.typeid; $case 32: return uint.typeid; diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 2d382028c..c168a107f 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -381,7 +381,7 @@ fn void DString.delete(&self, usz start, usz len = 1) macro void DString.append(&self, value) { var $Type = $typeof(value); - $switch ($Type) + $switch $Type: $case char: $case ichar: self.append_char(value); @@ -392,7 +392,7 @@ macro void DString.append(&self, value) $case Char32: self.append_char32(value); $default: - $switch + $switch: $case $defined((Char32)value): self.append_char32((Char32)value); $case $defined((String)value): @@ -513,7 +513,7 @@ fn usz DString.insert_utf32_at(&self, usz index, Char32[] chars) macro void DString.insert_at(&self, usz index, value) { var $Type = $typeof(value); - $switch ($Type) + $switch $Type: $case char: $case ichar: self.insert_char_at(index, value); @@ -524,7 +524,7 @@ macro void DString.insert_at(&self, usz index, value) $case Char32: self.insert_char32_at(index, value); $default: - $switch + $switch: $case $defined((Char32)value): self.insert_char32_at(index, (Char32)value); $case $defined((String)value): diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index d6af97c00..09b0b61b5 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -158,7 +158,7 @@ const bool ANY_SANITIZER = ADDRESS_SANITIZER || MEMORY_SANITIZER || THREAD_SANIT macro bool os_is_darwin() @const { - $switch (OS_TYPE) + $switch OS_TYPE: $case IOS: $case MACOS: $case TVOS: @@ -171,7 +171,7 @@ macro bool os_is_darwin() @const macro bool os_is_posix() @const { - $switch (OS_TYPE) + $switch OS_TYPE: $case IOS: $case MACOS: $case NETBSD: diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index abc730579..b2b3970d1 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -421,7 +421,7 @@ macro bool equals(a, b, isz len = -1, usz $align = 0) if (!len) return true; var $Type; - $switch ($align) + $switch $align: $case 1: $Type = char; $case 2: diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 9f832fad4..2760934ca 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -378,7 +378,7 @@ macro Allocator base_allocator() @private macro TempAllocator* create_default_sized_temp_allocator(Allocator allocator) @local { - $switch (env::MEMORY_ENV) + $switch env::MEMORY_ENV: $case NORMAL: return new_temp_allocator(1024 * 256, allocator)!!; $case SMALL: diff --git a/lib/std/core/string_to_real.c3 b/lib/std/core/string_to_real.c3 index 952b82432..361e02ab9 100644 --- a/lib/std/core/string_to_real.c3 +++ b/lib/std/core/string_to_real.c3 @@ -449,7 +449,7 @@ macro double! hexfloat(char[] chars, int $bits, int $emin, int sign) macro String.to_real(chars, $Type) @private { int sign = 1; - $switch ($Type) + $switch $Type: $case float: const int BITS = math::FLOAT_MANT_DIG; const int EMIN = math::FLOAT_MIN_EXP - BITS; diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index 41c76dedc..69e606b21 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -93,7 +93,7 @@ fn bool typeid.is_subtype_of(self, typeid other) macro bool is_subtype_of($Type, $OtherType) { var $typeid = $Type.typeid; - $switch ($Type) + $switch $Type: $case $OtherType: return true; $default: return false; $endswitch @@ -116,7 +116,7 @@ fn bool TypeKind.is_int(kind) @inline macro bool is_slice_convertable($Type) { - $switch ($Type.kindof) + $switch $Type.kindof: $case SLICE: return true; $case POINTER: @@ -134,7 +134,7 @@ macro bool is_int($Type) @const => $Type.kindof == TypeKind.SIGNED_INT || $Type *> macro bool is_signed($Type) @const { - $switch (inner_kind($Type)) + $switch inner_kind($Type): $case SIGNED_INT: $case FLOAT: return true; @@ -150,7 +150,7 @@ macro bool is_signed($Type) @const *> macro bool is_unsigned($Type) @const { - $switch (inner_kind($Type)) + $switch inner_kind($Type): $case UNSIGNED_INT: return true; $case VECTOR: @@ -190,7 +190,7 @@ macro bool is_ref_indexable($Type) @const macro bool is_intlike($Type) @const { - $switch ($Type.kindof) + $switch $Type.kindof: $case SIGNED_INT: $case UNSIGNED_INT: return true; @@ -203,7 +203,7 @@ macro bool is_intlike($Type) @const macro bool is_underlying_int($Type) @const { - $switch ($Type.kindof) + $switch $Type.kindof: $case SIGNED_INT: $case UNSIGNED_INT: return true; @@ -218,7 +218,7 @@ macro bool is_float($Type) @const => $Type.kindof == TypeKind.FLOAT; macro bool is_floatlike($Type) @const { - $switch ($Type.kindof) + $switch $Type.kindof: $case FLOAT: return true; $case VECTOR: @@ -258,7 +258,7 @@ macro bool @has_same(#a, #b, ...) @const $if $type_a != @typeid(#b): return false; $endif - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: $if @typeid($vaexpr[$i]) != $type_a: return false; $endif @@ -268,7 +268,7 @@ macro bool @has_same(#a, #b, ...) @const macro bool may_load_atomic($Type) @const { - $switch ($Type.kindof) + $switch $Type.kindof: $case BOOL: $case SIGNED_INT: $case UNSIGNED_INT: @@ -284,7 +284,7 @@ macro bool may_load_atomic($Type) @const macro lower_to_atomic_compatible_type($Type) @const { - $switch ($Type.kindof) + $switch $Type.kindof: $case BOOL: $case SIGNED_INT: $case UNSIGNED_INT: @@ -292,7 +292,7 @@ macro lower_to_atomic_compatible_type($Type) @const $case DISTINCT: return lower_to_atomic_compatible_type($Type.inner); $case FLOAT: - $switch ($Type) + $switch $Type: $case float16: return ushort.typeid; $case float: diff --git a/lib/std/core/values.c3 b/lib/std/core/values.c3 index e053e459c..2e7e6e817 100644 --- a/lib/std/core/values.c3 +++ b/lib/std/core/values.c3 @@ -49,7 +49,7 @@ macro @select(bool $bool, #value_1, #value_2) @builtin macro promote_int_same(x, y) { $if @is_int(x): - $switch + $switch: $case @is_vector(y) &&& $typeof(y).inner == float.typeid: return (float)x; $case $typeof(y).typeid == float.typeid: diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index 86b4dc35a..d1802eec9 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -39,7 +39,7 @@ macro usz! struct_to_format(value, Formatter* f, bool $force_dump) { var $Type = $typeof(value); usz total = f.print("{ ")!; - $foreach ($i, $member : $Type.membersof) + $foreach $i, $member : $Type.membersof: $if $i > 0: total += f.print(", ")!; $endif diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index 40cde0846..03cc7fd1d 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -114,7 +114,7 @@ macro String! treadline(stream = io::stdin()) macro usz! fprint(out, x) { var $Type = $typeof(x); - $switch ($Type) + $switch $Type: $case String: return out.write(x); $case ZString: return out.write(x.str_view()); $case DString: return out.write(x.str_view()); @@ -173,7 +173,7 @@ macro usz! fprintn(out, x = "") { usz len = fprint(out, x)!; out.write_byte('\n')!; - $switch + $switch: $case @typeid(out) == OutStream.typeid: if (&out.flush) out.flush()!; $case $defined(out.flush): diff --git a/lib/std/io/os/chdir.c3 b/lib/std/io/os/chdir.c3 index 1356edcb2..77c82fc0a 100644 --- a/lib/std/io/os/chdir.c3 +++ b/lib/std/io/os/chdir.c3 @@ -3,7 +3,7 @@ import std::io::path, libc, std::os; macro void! native_chdir(Path path) { - $switch + $switch: $case env::POSIX: if (posix::chdir(path.as_zstr())) { diff --git a/lib/std/io/os/fileinfo.c3 b/lib/std/io/os/fileinfo.c3 index f24fafb4c..e546b0b45 100644 --- a/lib/std/io/os/fileinfo.c3 +++ b/lib/std/io/os/fileinfo.c3 @@ -63,7 +63,7 @@ fn usz! native_file_size(String path) @if(env::DARWIN) fn bool native_file_or_dir_exists(String path) { - $switch + $switch: $case env::DARWIN: $case env::FREEBSD: $case env::NETBSD: @@ -88,7 +88,7 @@ fn bool native_file_or_dir_exists(String path) fn bool native_is_file(String path) { - $switch + $switch: $case env::DARWIN: $case env::FREEBSD: $case env::NETBSD: diff --git a/lib/std/io/os/getcwd.c3 b/lib/std/io/os/getcwd.c3 index f2f84efd5..dbc66ea1d 100644 --- a/lib/std/io/os/getcwd.c3 +++ b/lib/std/io/os/getcwd.c3 @@ -3,7 +3,7 @@ import libc, std::os; macro String! getcwd(Allocator allocator = allocator::heap()) { - $switch + $switch: $case env::WIN32: const DEFAULT_BUFFER = 256; Char16[DEFAULT_BUFFER] buffer; diff --git a/lib/std/io/os/mkdir.c3 b/lib/std/io/os/mkdir.c3 index 1a2b4b5f4..e329f4593 100644 --- a/lib/std/io/os/mkdir.c3 +++ b/lib/std/io/os/mkdir.c3 @@ -7,7 +7,7 @@ import std::os::posix; macro bool! native_mkdir(Path path, MkdirPermissions permissions) { - $switch + $switch: $case env::POSIX: if (!posix::mkdir(path.as_zstr(), permissions == NORMAL ? 0o777 : 0o700)) return true; switch (libc::errno()) diff --git a/lib/std/io/os/rmdir.c3 b/lib/std/io/os/rmdir.c3 index 80f8f5dc6..a4645e39f 100644 --- a/lib/std/io/os/rmdir.c3 +++ b/lib/std/io/os/rmdir.c3 @@ -6,7 +6,7 @@ import std::os::posix; macro bool! native_rmdir(Path path) { - $switch + $switch: $case env::POSIX: if (!posix::rmdir(path.as_zstr())) return true; switch (libc::errno()) diff --git a/lib/std/io/stream.c3 b/lib/std/io/stream.c3 index 1af0574b0..c28af2bf8 100644 --- a/lib/std/io/stream.c3 +++ b/lib/std/io/stream.c3 @@ -154,7 +154,7 @@ fn usz! copy_to(InStream in, OutStream dst, char[] buffer = {}) if (buffer.len) return copy_through_buffer(in, dst, buffer); if (&in.write_to) return in.write_to(dst); if (&dst.read_to) return dst.read_to(in); - $switch (env::MEMORY_ENV) + $switch env::MEMORY_ENV: $case NORMAL: return copy_through_buffer(in, dst, &&(char[4096]){}); $case SMALL: diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index a07a04854..13f1915bb 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -405,7 +405,7 @@ macro max(x, y, ...) return $$max(x, y); $else var m = $$max(x, y); - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: m = $$max(m, $vaarg[$i]); $endfor return m; @@ -422,7 +422,7 @@ macro min(x, y, ...) return $$min(x, y); $else var m = $$min(x, y); - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: m = $$min(m, $vaarg[$i]); $endfor return m; @@ -458,7 +458,7 @@ macro pow(x, exp) *> macro frexp(x, int* e) { - $switch ($typeof(x)) + $switch $typeof(x): $case float: $case float16: return _frexpf((float)x, e); @@ -472,7 +472,7 @@ macro frexp(x, int* e) *> macro int signbit(x) { - $switch ($typeof(x)) + $switch $typeof(x): $case float: $case float16: return bitcast((float)x, uint) >> 31; @@ -542,7 +542,7 @@ macro sqrt(x) => $$sqrt(values::promote_int(x)); macro tan(x) { var $Type = $typeof(x); - $switch + $switch: $case types::is_vector($Type): return $$sin(x) / $$cos(x); $case $Type.typeid == float.typeid: @@ -557,7 +557,7 @@ macro tan(x) *> macro bool is_finite(x) { - $switch ($typeof(x)) + $switch $typeof(x): $case float: $case float16: return bitcast((float)x, uint) & 0x7fffffff < 0x7f800000; @@ -571,7 +571,7 @@ macro bool is_finite(x) *> macro is_nan(x) { - $switch ($typeof(x)) + $switch $typeof(x): $case float: $case float16: return bitcast((float)x, uint) & 0x7fffffff > 0x7f800000; @@ -585,7 +585,7 @@ macro is_nan(x) *> macro is_inf(x) { - $switch ($typeof(x)) + $switch $typeof(x): $case float: $case float16: return bitcast((float)x, uint) & 0x7fffffff == 0x7f800000; @@ -1252,7 +1252,7 @@ Calculate the least common multiple for the provided arguments. macro lcm(...) { $typeof($vaarg[0]) result = $vaarg[0]; - $for (var $i = 1; $i < $vacount; $i++) + $for var $i = 1; $i < $vacount; $i++: $if $defined(result.lcm): result = result.lcm($vaarg[$i]); $else @@ -1270,7 +1270,7 @@ Calculate the greatest common divisor for the provided arguments. macro gcd(...) { $typeof($vaarg[0]) result = $vaarg[0]; - $for (var $i = 1; $i < $vacount; $i++) + $for var $i = 1; $i < $vacount; $i++: $if $defined(result.gcd): result = result.gcd($vaarg[$i]); $else diff --git a/lib/std/math/math_i128.c3 b/lib/std/math/math_i128.c3 index eeedfeb2b..5b510ae41 100644 --- a/lib/std/math/math_i128.c3 +++ b/lib/std/math/math_i128.c3 @@ -309,7 +309,7 @@ fn int128 __fixsfti(float a) @weak @extern("__fixsfti") @nostrip => fixint(a); macro float_from_i128($Type, a) @private { var $Rep; - $switch ($Type) + $switch $Type: $case double: $Rep = ulong; const MANT_DIG = DOUBLE_MANT_DIG; @@ -368,7 +368,7 @@ macro float_from_i128($Type, a) @private macro float_from_u128($Type, a) @private { var $Rep; - $switch ($Type) + $switch $Type: $case double: $Rep = ulong; const MANT_DIG = DOUBLE_MANT_DIG; @@ -423,7 +423,7 @@ macro float_from_u128($Type, a) @private macro fixuint(a) @private { var $Rep; - $switch ($typeof(a)) + $switch $typeof(a): $case double: $Rep = ulong; const EXPONENT_BITS = 11; @@ -467,7 +467,7 @@ macro fixuint(a) @private macro fixint(a) @private { var $Rep; - $switch ($typeof(a)) + $switch $typeof(a): $case double: $Rep = ulong; const EXPONENT_BITS = 11; diff --git a/lib/std/net/socket_private.c3 b/lib/std/net/socket_private.c3 index 77f4b2d81..1833b1d2d 100644 --- a/lib/std/net/socket_private.c3 +++ b/lib/std/net/socket_private.c3 @@ -21,7 +21,7 @@ fn Socket! connect_from_addrinfo(AddrInfo* addrinfo, SocketOption[] options) @pr fn bool last_error_is_delayed_connect() { - $switch + $switch: $case env::WIN32: switch (win32_WSAGetLastError()) { diff --git a/lib/std/os/backtrace.c3 b/lib/std/os/backtrace.c3 index 39ddce575..dc99dec12 100644 --- a/lib/std/os/backtrace.c3 +++ b/lib/std/os/backtrace.c3 @@ -79,7 +79,7 @@ fn Backtrace* Backtrace.init(&self, Allocator allocator, uptr offset, String fun fn void*[] capture_current(void*[] buffer) { if (!buffer.len) return buffer[:0]; - $switch + $switch: $case env::POSIX: CInt len = posix::backtrace(buffer.ptr, buffer.len); return buffer[:len]; diff --git a/lib/std/os/env.c3 b/lib/std/os/env.c3 index d4e69ffb5..7d8b15a03 100644 --- a/lib/std/os/env.c3 +++ b/lib/std/os/env.c3 @@ -12,7 +12,7 @@ import std::io::path, libc, std::os; fn String! get_var(Allocator allocator, String name) => @pool(allocator) { - $switch + $switch: $case env::LIBC && !env::WIN32: ZString val = libc::getenv(name.zstr_tcopy()); return val ? val.copy(allocator) : SearchResult.MISSING?; @@ -46,7 +46,7 @@ fn String! tget_var(String name) *> fn bool set_var(String name, String value, bool overwrite = true) => @pool() { - $switch + $switch: $case env::WIN32: WString wname = name.to_temp_wstring()!!; if (!overwrite) @@ -104,7 +104,7 @@ fn Path! get_config_dir(Allocator allocator) => @pool(allocator) *> fn bool clear_var(String name) => @pool() { - $switch + $switch: $case env::WIN32: WString wname = name.to_temp_wstring()!!; return win32::setEnvironmentVariableW(wname, null) == 0; diff --git a/lib/std/sort/binarysearch.c3 b/lib/std/sort/binarysearch.c3 index 931a3afe8..82aad7ac0 100644 --- a/lib/std/sort/binarysearch.c3 +++ b/lib/std/sort/binarysearch.c3 @@ -25,7 +25,7 @@ macro usz binarysearch(list, x, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SL } $else - $switch + $switch: $case $defined(cmp(list[0], list[0], context)): int res = cmp(list[half], x, context); $case $defined(cmp(list[0], list[0])): diff --git a/lib/std/sort/countingsort.c3 b/lib/std/sort/countingsort.c3 index 09ab21a32..673fc456b 100644 --- a/lib/std/sort/countingsort.c3 +++ b/lib/std/sort/countingsort.c3 @@ -65,7 +65,7 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) for (usz i = low; i < high; i++) { - $switch + $switch: $case NO_KEY_FN: KeyFnReturnType k = list[i]; $case KEY_BY_VALUE: @@ -129,7 +129,7 @@ fn void csort(Type list, usz low, usz high, KeyFn key_fn, uint byte_idx) sorted_count += (e - s); for (; s < e; s++) { - $switch + $switch: $case NO_KEY_FN: KeyFnReturnType k = list[low + s]; $case KEY_BY_VALUE: diff --git a/lib/std/sort/insertionsort.c3 b/lib/std/sort/insertionsort.c3 index f3106067c..d448a47fa 100644 --- a/lib/std/sort/insertionsort.c3 +++ b/lib/std/sort/insertionsort.c3 @@ -35,7 +35,7 @@ fn void isort(Type list, usz low, usz high, CmpFn comp, Context context) $if $has_get_ref: ElementType *rhs = &list[j]; ElementType *lhs = &list[--j]; - $switch + $switch: $case $cmp_by_value && $has_context: if (comp(*rhs, *lhs, context) >= 0) break; $case $cmp_by_value: @@ -51,7 +51,7 @@ fn void isort(Type list, usz low, usz high, CmpFn comp, Context context) $else usz r = j; --j; - $switch + $switch: $case $cmp_by_value && $has_context: if (comp(list[r], list[j], context) >= 0) break; $case $cmp_by_value: diff --git a/lib/std/sort/quicksort.c3 b/lib/std/sort/quicksort.c3 index ca7e77eb2..98d71bef2 100644 --- a/lib/std/sort/quicksort.c3 +++ b/lib/std/sort/quicksort.c3 @@ -120,7 +120,7 @@ macro @partition(Type list, isz l, isz h, CmpFn cmp, Context context) ElementType pivot = list[l]; while (l < h) { - $switch + $switch: $case $cmp_by_value && $has_context: while (cmp(list[h], pivot, context) >= 0 && l < h) h--; if (l < h) list[l++] = list[h]; diff --git a/lib/std/sort/sort.c3 b/lib/std/sort/sort.c3 index 938a1a3e5..fdbac6cf2 100644 --- a/lib/std/sort/sort.c3 +++ b/lib/std/sort/sort.c3 @@ -11,7 +11,7 @@ macro usz len_from_list(list) macro bool @is_sortable(#list) { - $switch + $switch: $case !$defined(#list[0]): return false; $case !$defined(#list.len): @@ -34,7 +34,7 @@ macro bool @is_valid_cmp_fn(#cmp, #list, #context) { var $Type = $typeof(#cmp); var $no_context = @is_empty_macro_slot(#context); - $switch + $switch: $case @is_empty_macro_slot(#cmp): return true; $case $Type.kindof != FUNC ||| $Type.returns.kindof != SIGNED_INT: return false; $case $defined(#cmp(#list[0], #list[0], #context)): return true; @@ -47,7 +47,7 @@ macro bool @is_valid_cmp_fn(#cmp, #list, #context) macro bool @is_cmp_key_fn(#key_fn, #list) { - $switch + $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; diff --git a/lib/std/sort/sorted.c3 b/lib/std/sort/sorted.c3 index 40bc1f801..f280aa0ee 100644 --- a/lib/std/sort/sorted.c3 +++ b/lib/std/sort/sorted.c3 @@ -44,7 +44,7 @@ macro int @sort_cmp(list, pos, cmp, ctx) @local var a = list[pos]; var b = list[pos+1]; - $switch + $switch: $case $cmp_by_value && $has_context: return cmp(a, b); $case $cmp_by_value: diff --git a/releasenotes.md b/releasenotes.md index 9e7a10831..4e48ed6a5 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -18,6 +18,10 @@ - Removal of "any-switch". - Allow swizzling assign, eg. `abc.xz += { 5, 10 };` - Added `$$wstr16` and `$$wstr32` builtins. +- `$foreach` "()" replaced by trailing ":" `$foreach ($x, $y : $foo)` -> `$foreach $x, $y : $foo:` +- `$for` "()" replaced by trailing ":" `$for (var $x = 0; $x < FOO; $x++)` -> `$for var $x = 0; $x < FOO; $x++:` +- `$switch` "()" replaced by trailing ":" `$switch ($Type)` -> `$switch $Type:` +- Empty `$switch` requires trailing ":" `$switch` -> `$switch:` ### Fixes - Fix address sanitizer to work on MachO targets (e.g. MacOS). diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index f9f5e67c2..dbc733e1b 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1073,13 +1073,12 @@ static inline Ast *parse_return_stmt(ParseContext *c) } /** - * ct_foreach_stmt ::= CT_FOREACH '(' CT_IDENT (',' CT_IDENT)? ':' expr ')' statement* CT_ENDFOREACH + * ct_foreach_stmt ::= CT_FOREACH CT_IDENT (',' CT_IDENT)? ':' expr ':' statement* CT_ENDFOREACH */ static inline Ast* parse_ct_foreach_stmt(ParseContext *c) { Ast *ast = ast_new_curr(c, AST_CT_FOREACH_STMT); advance_and_verify(c, TOKEN_CT_FOREACH); - CONSUME_OR_RET(TOKEN_LPAREN, poisoned_ast); if (peek(c) == TOKEN_COMMA) { Decl *index = decl_new_var(symstr(c), c->span, NULL, VARDECL_LOCAL_CT); @@ -1091,7 +1090,7 @@ static inline Ast* parse_ct_foreach_stmt(ParseContext *c) TRY_CONSUME_OR_RET(TOKEN_CT_IDENT, "Expected a compile time variable", poisoned_ast); TRY_CONSUME_OR_RET(TOKEN_COLON, "Expected ':'.", poisoned_ast); ASSIGN_EXPRID_OR_RET(ast->ct_foreach_stmt.expr, parse_expr(c), poisoned_ast); - CONSUME_OR_RET(TOKEN_RPAREN, poisoned_ast); + TRY_CONSUME_OR_RET(TOKEN_COLON, "Expected ':'.", poisoned_ast); Ast *body = new_ast(AST_CT_COMPOUND_STMT, ast->span); ast->ct_foreach_stmt.body = astid(body); AstId *current = &body->ct_compound_stmt; @@ -1106,14 +1105,13 @@ static inline Ast* parse_ct_foreach_stmt(ParseContext *c) /** * ct_for_stmt - * | CT_FOR '(' decl_expr_list? ';' expression_list? ';' expression_list? ')' statement* CT_ENDFOR + * | CT_FOR decl_expr_list? ';' expression_list? ';' expression_list? ':' statement* CT_ENDFOR * ; */ static inline Ast* parse_ct_for_stmt(ParseContext *c) { Ast *ast = ast_new_curr(c, AST_CT_FOR_STMT); advance_and_verify(c, TOKEN_CT_FOR); - CONSUME_OR_RET(TOKEN_LPAREN, poisoned_ast); if (!tok_is(c, TOKEN_EOS)) { @@ -1125,12 +1123,12 @@ static inline Ast* parse_ct_for_stmt(ParseContext *c) ASSIGN_EXPRID_OR_RET(ast->for_stmt.cond, parse_expr(c), poisoned_ast); CONSUME_EOS_OR_RET(poisoned_ast); - if (!tok_is(c, TOKEN_RPAREN)) + if (!tok_is(c, TOKEN_COLON)) { ASSIGN_EXPRID_OR_RET(ast->for_stmt.incr, parse_ct_expression_list(c, false), poisoned_ast); } - CONSUME_OR_RET(TOKEN_RPAREN, poisoned_ast); + CONSUME_OR_RET(TOKEN_COLON, poisoned_ast); Ast *body = new_ast(AST_CT_COMPOUND_STMT, ast->span); ast->for_stmt.body = astid(body); @@ -1145,7 +1143,7 @@ static inline Ast* parse_ct_for_stmt(ParseContext *c) } /** - * ct_switch_stmt ::= CT_SWITCH const_paren_expr? ct_case_statement* CT_ENDSWITCH + * ct_switch_stmt ::= CT_SWITCH const_expr? ':' ct_case_statement* CT_ENDSWITCH * * ct_case_statement ::= (CT_CASE constant_expr | CT_DEFAULT) ':' opt_stmt_list */ @@ -1153,13 +1151,11 @@ static inline Ast* parse_ct_switch_stmt(ParseContext *c) { Ast *ast = ast_new_curr(c, AST_CT_SWITCH_STMT); advance_and_verify(c, TOKEN_CT_SWITCH); - - // Is it a paren expr? - if (tok_is(c, TOKEN_LPAREN)) + if (!tok_is(c, TOKEN_COLON)) { - ASSIGN_EXPRID_OR_RET(ast->ct_switch_stmt.cond, parse_const_paren_expr(c), poisoned_ast); + ASSIGN_EXPRID_OR_RET(ast->ct_switch_stmt.cond, parse_constant_expr(c), poisoned_ast); } - + CONSUME_OR_RET(TOKEN_COLON, poisoned_ast); Ast **cases = NULL; while (!try_consume(c, TOKEN_CT_ENDSWITCH)) { diff --git a/test/test_suite/assert/assert_with_void.c3 b/test/test_suite/assert/assert_with_void.c3 index 1725e0bd2..51e1ac557 100644 --- a/test/test_suite/assert/assert_with_void.c3 +++ b/test/test_suite/assert/assert_with_void.c3 @@ -11,7 +11,7 @@ fn void main() macro deep_print(a) { var $Type = $typeof(a); - $switch ($Type.kindof) + $switch $Type.kindof: $case ARRAY: $case SLICE: io::print("["); @@ -23,13 +23,13 @@ macro deep_print(a) io::print("]"); $case STRUCT: io::print("{"); - $foreach ($i, $m : $typeof(a).membersof) + $foreach $i, $m : $typeof(a).membersof: if ($i > 0) io::print(", "); deep_print($m.get(a)); $endforeach io::print("}"); $default: - $switch ($Type.nameof) + $switch $Type.nameof: $case "String": $case "DString": $case "WString": diff --git a/test/test_suite/compile_time/compile_time_array_bug.c3t b/test/test_suite/compile_time/compile_time_array_bug.c3t index c27082d04..135ae00c2 100644 --- a/test/test_suite/compile_time/compile_time_array_bug.c3t +++ b/test/test_suite/compile_time/compile_time_array_bug.c3t @@ -10,7 +10,7 @@ enum TokenType: char (char token) { macro populate_token_table() { TokenType[256] $tmp = {}; - $foreach ($tokenType: TokenType.values) + $foreach $tokenType: TokenType.values: $tmp[$tokenType.token] = $tokenType; $endforeach diff --git a/test/test_suite/compile_time/compile_time_utf32.c3 b/test/test_suite/compile_time/compile_time_utf32.c3 index 0d5ea9501..fa558b926 100644 --- a/test/test_suite/compile_time/compile_time_utf32.c3 +++ b/test/test_suite/compile_time/compile_time_utf32.c3 @@ -1,7 +1,7 @@ macro int get_utf32_codepoint_length(char $c) @const { int $len; - $switch + $switch: $case !($c & 0x80): $len = 1; $case ($c & 0xE0) == 0xC0: $len = 2; $case ($c & 0xF0) == 0xE0: $len = 3; @@ -14,7 +14,7 @@ macro int get_utf32_codepoint_length(char $c) @const macro usz get_utf32_len_from_utf8(String $source) @const { usz $len = 0; - $for (var $i=0; $i < $source.len;) + $for var $i=0; $i < $source.len;: var $curlen = get_utf32_codepoint_length ($source[$i]); $i += $curlen; $len++; @@ -31,10 +31,10 @@ macro Char32[] conv_utf8_to_char32($source) @const Char32[] $chars = {}; var $char_index = 0; - $for (var $inx = 0; $inx < $max; ) + $for var $inx = 0; $inx < $max; : var $c = $source[$inx]; var $len = get_utf32_codepoint_length($c); - $switch ($len) + $switch $len: $case 1: $codepoint = $c; $case 2: $codepoint = $c & 0x1F; $case 3: $codepoint = $c & 0x0F; @@ -44,7 +44,7 @@ macro Char32[] conv_utf8_to_char32($source) @const return; $endswitch - $for (var $x = 1; $x < $len; ++$x) + $for var $x = 1; $x < $len; ++$x: $c = $source[$inx + $x]; $if ( ($c & 0xC0) != 0x80): $error("Error, invalid utf8 character in string"); @@ -62,7 +62,7 @@ import std; fn void main(String[] args) { Char32[] $chars = conv_utf8_to_char32("🐉 eats 🌎"); - $foreach($v : $chars) + $foreach $v : $chars: io::printn($v); $endforeach Char32[] chars = conv_utf8_to_char32 ("🐉 eats 🌎"); diff --git a/test/test_suite/compile_time/concat_const.c3 b/test/test_suite/compile_time/concat_const.c3 index 88766eeb0..2db4f6e1f 100644 --- a/test/test_suite/compile_time/concat_const.c3 +++ b/test/test_suite/compile_time/concat_const.c3 @@ -6,7 +6,7 @@ macro String to_string(uint $num) @const { char[] $res; int $i = 0; - $for (;$num != 0;) + $for ;$num != 0;: $res = $res +++ (char) ('0' + $num % 10); $num = $num / 10; $i++; diff --git a/test/test_suite/compile_time/concat_slice_array.c3 b/test/test_suite/compile_time/concat_slice_array.c3 index 07037864e..39ab8c933 100644 --- a/test/test_suite/compile_time/concat_slice_array.c3 +++ b/test/test_suite/compile_time/concat_slice_array.c3 @@ -6,7 +6,7 @@ fn int main() String $chars = "Abcd"; char $from = 2; char[10] $bitmap = {}; -$foreach ( $c : $chars) +$foreach $c : $chars: int $offset = ($c - $from) / BITS; int $rem = ($c - $from) % BITS; uint128 $value = $bitmap[$offset]; // #error: is out of range diff --git a/test/test_suite/compile_time/ct_assert_bug.c3 b/test/test_suite/compile_time/ct_assert_bug.c3 index 5b6582bbc..d987bd4dd 100644 --- a/test/test_suite/compile_time/ct_assert_bug.c3 +++ b/test/test_suite/compile_time/ct_assert_bug.c3 @@ -11,7 +11,7 @@ fn void main() macro bool deep_equal(a, b) { - $switch ($typeof(a).kindof) + $switch $typeof(a).kindof: $case SLICE: if (a.len != b.len) return false; foreach (i, x : a) diff --git a/test/test_suite/compile_time/ct_enum_values.c3t b/test/test_suite/compile_time/ct_enum_values.c3t index c17c69701..37f14ace4 100644 --- a/test/test_suite/compile_time/ct_enum_values.c3t +++ b/test/test_suite/compile_time/ct_enum_values.c3t @@ -9,7 +9,7 @@ enum Vehicles macro elements($Type) { int x; - $foreach ($x : $Type.values) + $foreach $x : $Type.values: x = $x.ordinal; $endforeach; } diff --git a/test/test_suite/compile_time/ct_for.c3t b/test/test_suite/compile_time/ct_for.c3t index 8d58ca058..92a369dc5 100644 --- a/test/test_suite/compile_time/ct_for.c3t +++ b/test/test_suite/compile_time/ct_for.c3t @@ -7,11 +7,11 @@ extern fn void printf(char*, ...); fn void main() { - $for (var $i = 0; $i < 3; $i++) + $for var $i = 0; $i < 3; $i++: printf("Foo %d\n", $i); $endfor; - $for ($i = 0, var $j = 100; $i < 4;) + $for $i = 0, var $j = 100; $i < 4;: printf("Foo %d %d\n", $i++, $j--); $endfor; diff --git a/test/test_suite/compile_time/ct_forach_with_defer.c3t b/test/test_suite/compile_time/ct_forach_with_defer.c3t index a1176febe..7b63a3211 100644 --- a/test/test_suite/compile_time/ct_forach_with_defer.c3t +++ b/test/test_suite/compile_time/ct_forach_with_defer.c3t @@ -6,7 +6,7 @@ fn void test() { defer io::printn("World!"); const HELLO = "Hello"; - $for (var $i = 0; $i < 5; $i++) + $for var $i = 0; $i < 5; $i++: io::printf("%c", HELLO[$i]); $endfor } @@ -15,7 +15,7 @@ fn void main() { defer io::printn("World!"); - $foreach ($c : "Hello") + $foreach $c : "Hello": io::printf("%c", $c); $endforeach io::printn(); diff --git a/test/test_suite/compile_time/ct_foreach.c3t b/test/test_suite/compile_time/ct_foreach.c3t index 7298b737a..0a060cd70 100644 --- a/test/test_suite/compile_time/ct_foreach.c3t +++ b/test/test_suite/compile_time/ct_foreach.c3t @@ -7,18 +7,18 @@ fn void main() { var $foo = { 1, 10, 34 }; - $foreach ($i : $foo) + $foreach $i : $foo: printf("Foo %d\n", $i); $endforeach; - $foreach ($i, $j : $foo) + $foreach $i, $j : $foo: printf("Bar %d %d\n", $i, $j); $endforeach; - $foreach ($x : { 123, "abc", 1177, "hello" }) + $foreach $x : { 123, "abc", 1177, "hello" }: { $typeof($x) z = $x; - $switch ($typeof($x)) + $switch $typeof($x): $case int: printf("Bar %d\n", $x); $default: diff --git a/test/test_suite/compile_time/ct_memberof.c3t b/test/test_suite/compile_time/ct_memberof.c3t index d60e6e732..afe68060a 100644 --- a/test/test_suite/compile_time/ct_memberof.c3t +++ b/test/test_suite/compile_time/ct_memberof.c3t @@ -7,7 +7,7 @@ fn int hell() { return 1; } macro print_args($Type) { var $params = $Type.params; - $foreach ($param : $params) + $foreach $param : $params: io::printn($param.nameof); $endforeach; } @@ -35,7 +35,7 @@ macro print_fields($Type) { io::printfn("Type: %s", $Type.nameof); var $params = $Type.membersof; - $foreach ($param : $params) + $foreach $param : $params: io::printfn("%s: %s", $param.nameof, $param.typeid.nameof); $endforeach; } diff --git a/test/test_suite/compile_time/ct_switch.c3t b/test/test_suite/compile_time/ct_switch.c3t index 7a625ffa5..b5c714c51 100644 --- a/test/test_suite/compile_time/ct_switch.c3t +++ b/test/test_suite/compile_time/ct_switch.c3t @@ -4,7 +4,7 @@ module test; macro getisprime($x) { - $switch ($x) + $switch $x: $case 1: $case 2: $case 3: diff --git a/test/test_suite/compile_time/ct_switch_errors.c3 b/test/test_suite/compile_time/ct_switch_errors.c3 index bbb85a1a7..41fbf338a 100644 --- a/test/test_suite/compile_time/ct_switch_errors.c3 +++ b/test/test_suite/compile_time/ct_switch_errors.c3 @@ -1,7 +1,7 @@ fn void test() { - $switch (3) + $switch 3: $case 2: return; $default: // #error: $default must be last in a $switch @@ -12,7 +12,7 @@ fn void test() fn void test1() { - $switch (1) + $switch 1: $case -1: return; $case -1: // #error: '-1' appears more than once @@ -25,7 +25,7 @@ fn void test1() fn void test3() { - $switch (3) + $switch 3: $case 3: return; $case 123.0: // #error: 'int' diff --git a/test/test_suite/compile_time/ct_switch_more_checks.c3 b/test/test_suite/compile_time/ct_switch_more_checks.c3 index 34eb21b95..fac4ebf17 100644 --- a/test/test_suite/compile_time/ct_switch_more_checks.c3 +++ b/test/test_suite/compile_time/ct_switch_more_checks.c3 @@ -4,7 +4,7 @@ import std::io; fn void foo() { int a; - $switch ($typeof(a)) + $switch $typeof(a): $case int..float: // #error: $case ranges are only allowed for integers io::printn("Hello"); $default: @@ -15,7 +15,7 @@ fn void foo() fn void foo2() { int a; - $switch ($typeof(a)) + $switch $typeof(a): $case true..false: // #error: $case ranges are only allowed io::printn("Hello"); $default: @@ -26,7 +26,7 @@ fn void foo2() fn void foo3() { int a; - $switch ({ 1, 3 }) // #error: Only types, strings, enums, integers, floats and booleans + $switch { 1, 3 }: // #error: Only types, strings, enums, integers, floats and booleans $case 1: io::printn("Hello"); $default: @@ -37,7 +37,7 @@ fn void foo3() fn void main() { int a; - $switch ("abc") + $switch "abc": $case "cde": io::printn("!!!"); $case "abc": diff --git a/test/test_suite/compile_time/ct_switch_top_level.c3t b/test/test_suite/compile_time/ct_switch_top_level.c3t index 922d83d5d..3692b9416 100644 --- a/test/test_suite/compile_time/ct_switch_top_level.c3t +++ b/test/test_suite/compile_time/ct_switch_top_level.c3t @@ -6,7 +6,7 @@ extern fn void printf(char*, ...); macro tester() { var $Type = int; - $switch ($Type) + $switch $Type: $case int: printf("Hello\n"); int z = 0; diff --git a/test/test_suite/compile_time/ct_switch_type_check.c3t b/test/test_suite/compile_time/ct_switch_type_check.c3t index 4fe4bf14c..921bb783d 100644 --- a/test/test_suite/compile_time/ct_switch_type_check.c3t +++ b/test/test_suite/compile_time/ct_switch_type_check.c3t @@ -4,7 +4,7 @@ module test; macro get_type($Type) { - $switch ($Type.typeid) + $switch $Type.typeid: $case int: return "int"; $case double: diff --git a/test/test_suite/compile_time/ct_switch_type_errors.c3 b/test/test_suite/compile_time/ct_switch_type_errors.c3 index 27a3df32d..33c2ddc1f 100644 --- a/test/test_suite/compile_time/ct_switch_type_errors.c3 +++ b/test/test_suite/compile_time/ct_switch_type_errors.c3 @@ -1,7 +1,7 @@ fn void test() { - $switch (int.typeid) + $switch int.typeid: $case int: return; $default: // #error: must be last in a $switch @@ -12,7 +12,7 @@ fn void test() fn void test1() { - $switch (int.typeid) + $switch int.typeid: $case int: return; $case int: // #error: 'int' appears more than once @@ -26,7 +26,7 @@ def Foo = int; def Bar = double; fn void test2() { - $switch (int.typeid) + $switch int.typeid: $case Foo: return; $case Bar: @@ -40,7 +40,7 @@ fn void test2() fn void test3() { - $switch (int.typeid) + $switch int.typeid: $case int: return; $case 123: // #error: A type was expected here not 'int' diff --git a/test/test_suite/compile_time_introspection/paramsof.c3t b/test/test_suite/compile_time_introspection/paramsof.c3t index 59c737e30..f45018999 100644 --- a/test/test_suite/compile_time_introspection/paramsof.c3t +++ b/test/test_suite/compile_time_introspection/paramsof.c3t @@ -11,7 +11,7 @@ fn void main() { io::printn(r); } - $foreach ($r : $typeof(testme).paramsof) + $foreach $r : $typeof(testme).paramsof: io::printn($r.name); io::printn($r.type.nameof); $endforeach diff --git a/test/test_suite/compile_time_introspection/tag_1343.c3t b/test/test_suite/compile_time_introspection/tag_1343.c3t index 91e480f83..97d892a5f 100644 --- a/test/test_suite/compile_time_introspection/tag_1343.c3t +++ b/test/test_suite/compile_time_introspection/tag_1343.c3t @@ -6,7 +6,7 @@ macro void Foo.tags(&self, other) // inner to remove pointer var $Type = $typefrom($typeof(other).inner); var $methodcount = $Type.methodsof.len; - $for (var $i = 0; $i < $methodcount; $i++) + $for var $i = 0; $i < $methodcount; $i++: var $MethodType1 = $typeof($Type.$eval($Type.methodsof[$i])); var $MethodType = $typeof(&$Type.$eval($Type.methodsof[$i])); $MethodType a; diff --git a/test/test_suite/debug_symbols/ct_foreach.c3t b/test/test_suite/debug_symbols/ct_foreach.c3t index 6e099306b..7c43baf93 100644 --- a/test/test_suite/debug_symbols/ct_foreach.c3t +++ b/test/test_suite/debug_symbols/ct_foreach.c3t @@ -5,7 +5,7 @@ struct Flags { bool flag1; } fn void foo() { int[1] values; - $foreach ($i, $member : Flags.membersof) + $foreach $i, $member : Flags.membersof: values[$i] = $i; $endforeach } diff --git a/test/test_suite/enumerations/enum_reflect_associated.c3t b/test/test_suite/enumerations/enum_reflect_associated.c3t index f39258d7f..2f7759b14 100644 --- a/test/test_suite/enumerations/enum_reflect_associated.c3t +++ b/test/test_suite/enumerations/enum_reflect_associated.c3t @@ -9,7 +9,7 @@ enum Abc : int (int x, double y, String z) fn int main() { - $foreach ($type : Abc.associated) + $foreach $type : Abc.associated: io::printfn("%s", $type.qnameof); $endforeach return 0; diff --git a/test/test_suite/expressions/type_support.c3t b/test/test_suite/expressions/type_support.c3t index 3c7e130c4..608e1ae9a 100644 --- a/test/test_suite/expressions/type_support.c3t +++ b/test/test_suite/expressions/type_support.c3t @@ -5,7 +5,7 @@ import std::io; macro print_type_info(...) { - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: io::printfn("type: %s", $vatype[$i].nameof); io::printfn("%s.sizeof = %d", $vatype[$i].nameof, $vatype[$i].sizeof); io::printfn("%s.min = %s", $vatype[$i].nameof, $vatype[$i].min); diff --git a/test/test_suite/functions/raw_splat.c3t b/test/test_suite/functions/raw_splat.c3t index ccd1b8959..b5fe0c793 100644 --- a/test/test_suite/functions/raw_splat.c3t +++ b/test/test_suite/functions/raw_splat.c3t @@ -4,7 +4,7 @@ module rawsplat; int x; macro void foo(...) { - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: x += $vaarg[$i] * $i; $endfor } diff --git a/test/test_suite/generic/generic_lambda_complex.c3t b/test/test_suite/generic/generic_lambda_complex.c3t index 6728e8b7d..76a726278 100644 --- a/test/test_suite/generic/generic_lambda_complex.c3t +++ b/test/test_suite/generic/generic_lambda_complex.c3t @@ -64,10 +64,10 @@ fn void! TextTemplate.init(&self, String template, String tag_start = "{{", Stri TextTag tag @noinit; do OUTER: { - $foreach ($m : Type.membersof) + $foreach $m : Type.membersof: if (name == $m.nameof) { - $switch ($m.typeid) + $switch $m.typeid: $case String.typeid: tag = { .kind = STRING, diff --git a/test/test_suite/lambda/ct_lambda2.c3t b/test/test_suite/lambda/ct_lambda2.c3t index 57b5df2d6..bd909f9a1 100644 --- a/test/test_suite/lambda/ct_lambda2.c3t +++ b/test/test_suite/lambda/ct_lambda2.c3t @@ -7,7 +7,7 @@ def Call = fn void(); fn int main() { var $x = 0; - $for (var $i = 0; $i < 10; $i++) + $for var $i = 0; $i < 10; $i++: { var $Type = int; $if $i % 2 == 0: diff --git a/test/test_suite/macros/macro_untyped_varargs_2.c3t b/test/test_suite/macros/macro_untyped_varargs_2.c3t index 8621fb3ef..1bddfde96 100644 --- a/test/test_suite/macros/macro_untyped_varargs_2.c3t +++ b/test/test_suite/macros/macro_untyped_varargs_2.c3t @@ -8,14 +8,14 @@ macro @foo(...) { int i = $vaarg[1] + $vaarg[1]; int j = $vaexpr[2] + $vaexpr[2]; - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: io::printfn("%d", $vaarg[$i]); $endfor; } macro foo2(...) { - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: { $vatype[$i] x; } @@ -26,7 +26,7 @@ macro foo2(...) macro foo3(...) { var $x = 0; - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: $x += $vaconst[$i]; $endfor; return $x; diff --git a/test/test_suite/macros/userland_bitcast.c3t b/test/test_suite/macros/userland_bitcast.c3t index b919b3d45..6f425e337 100644 --- a/test/test_suite/macros/userland_bitcast.c3t +++ b/test/test_suite/macros/userland_bitcast.c3t @@ -6,7 +6,7 @@ macro testbitcast(expr, $Type) $Type x @noinit; var $size = (usz)($sizeof(expr)); - $switch + $switch: $case $alignof(expr) >= 8 && $Type.alignof >= 8: ulong *b = (ulong*)(&expr); ulong *to = (ulong*)(&x); diff --git a/test/unit/regression/subtype.c3 b/test/unit/regression/subtype.c3 index 75d403a65..02e93a366 100644 --- a/test/unit/regression/subtype.c3 +++ b/test/unit/regression/subtype.c3 @@ -69,7 +69,7 @@ fn void switch_subtyping() default: assert(false); } - $switch (Bar.typeid) + $switch Bar.typeid: $case Foo: assert(true); $case Bar: diff --git a/test/unit/stdlib/math/math_is_even_odd.c3 b/test/unit/stdlib/math/math_is_even_odd.c3 index 7acef285c..cbddfcbe8 100644 --- a/test/unit/stdlib/math/math_is_even_odd.c3 +++ b/test/unit/stdlib/math/math_is_even_odd.c3 @@ -4,7 +4,7 @@ import std::io; macro test(start, ...) { - $for (var $i = 0; $i < $vacount; $i++) + $for var $i = 0; $i < $vacount; $i++: for ($vatype[$i] i = ($vatype[$i])start; i < 5; i+=2) { assert(math::is_even(i));