diff --git a/lib/std/collections/enumset.c3 b/lib/std/collections/enumset.c3 index d8c27a0a6..d5128c50e 100644 --- a/lib/std/collections/enumset.c3 +++ b/lib/std/collections/enumset.c3 @@ -36,7 +36,7 @@ def EnumSet = distinct EnumSetType; fn void EnumSet.add(EnumSet* this, Enum v) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: (*this)[v / 8] |= (char)(1u << (v % 8)); $else *this = (EnumSet)((EnumSetType)*this | 1u << (EnumSetType)v); @@ -45,7 +45,7 @@ $endif fn void EnumSet.clear(EnumSet* this) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: *this = {}; $else *this = 0; @@ -54,7 +54,7 @@ $endif fn bool EnumSet.remove(EnumSet* this, Enum v) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: if (!this.has(v) @inline) return false; (*this)[v / 8] &= (char)~(1 << (v % 8)); return true; @@ -68,7 +68,7 @@ $endif fn bool EnumSet.has(EnumSet* this, Enum v) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: return (bool)(((*this)[v / 8] << (v % 8)) & 0x01); $else return ((EnumSetType)*this & (1u << (EnumSetType)v)) != 0; @@ -77,7 +77,7 @@ $endif fn void EnumSet.add_all(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: foreach (i, c : s) (*this)[i] |= c; $else *this = (EnumSet)((EnumSetType)*this | (EnumSetType)s); @@ -86,7 +86,7 @@ $endif fn void EnumSet.retain_all(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: foreach (i, c : s) (*this)[i] &= c; $else *this = (EnumSet)((EnumSetType)*this & (EnumSetType)s); @@ -95,7 +95,7 @@ $endif fn void EnumSet.remove_all(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: foreach (i, c : s) (*this)[i] &= ~c; $else *this = (EnumSet)((EnumSetType)*this & ~(EnumSetType)s); @@ -104,7 +104,7 @@ $endif fn EnumSet EnumSet.and_of(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: EnumSet copy = *this; copy.retain_all(s); return copy; @@ -115,7 +115,7 @@ $endif fn EnumSet EnumSet.or_of(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: EnumSet copy = *this; copy.add_all(s); return copy; @@ -127,7 +127,7 @@ $endif fn EnumSet EnumSet.diff_of(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: EnumSet copy = *this; copy.remove_all(s); return copy; @@ -138,7 +138,7 @@ $endif fn EnumSet EnumSet.xor_of(EnumSet* this, EnumSet s) { -$if (IS_CHAR_ARRAY) +$if IS_CHAR_ARRAY: EnumSet copy = *this; foreach (i, c : s) copy[i] ^= c; return copy; diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 45eb5d2b1..0b7f7c9bb 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -281,7 +281,7 @@ fn void List.ensure_capacity(List* list, usz added = 1) @inline @private // Functions for equatable types -$if (types::is_equatable_type(Type)) +$if types::is_equatable_type(Type): fn usz! List.index_of(List* list, Type type) { @@ -357,7 +357,7 @@ fn void List.remove_all(List* list, List* other_list) $endif -$if (Type.kindof == POINTER) +$if Type.kindof == POINTER: /** * @param [&in] list diff --git a/lib/std/collections/map.c3 b/lib/std/collections/map.c3 index cf136e8aa..b61728389 100644 --- a/lib/std/collections/map.c3 +++ b/lib/std/collections/map.c3 @@ -205,7 +205,7 @@ fn Value[] HashMap.value_list(HashMap* map, Allocator* using = mem::heap()) return list; } -$if (types::is_equatable(Value)) +$if types::is_equatable(Value): fn bool HashMap.has_value(HashMap* map, Value v) { if (!map.count) return false; diff --git a/lib/std/collections/object.c3 b/lib/std/collections/object.c3 index 1f8279e2e..8a5990201 100644 --- a/lib/std/collections/object.c3 +++ b/lib/std/collections/object.c3 @@ -230,7 +230,7 @@ $switch $case $checks(String s = value): return new_string(value); $default: - $assert(false, "Unsupported object type."); + $error "Unsupported object type."; $endswitch } @@ -315,7 +315,7 @@ macro get_integer_value(Object* value, $Type) } if (value.is_string()) { - $if ($Type.kindof == TypeKind.SIGNED_INT) + $if $Type.kindof == TypeKind.SIGNED_INT: return ($Type)value.s.to_int128(); $else return ($Type)value.s.to_uint128(); diff --git a/lib/std/core/allocators/mem_allocator_fn.c3 b/lib/std/core/allocators/mem_allocator_fn.c3 index 2190580c6..a66d3102a 100644 --- a/lib/std/core/allocators/mem_allocator_fn.c3 +++ b/lib/std/core/allocators/mem_allocator_fn.c3 @@ -37,7 +37,7 @@ struct AlignedBlock macro void*! @aligned_alloc(#alloc_fn, usz bytes, usz alignment, usz offset) { usz header = mem::aligned_offset(AlignedBlock.sizeof + offset, alignment) - offset; - $if ($checks(#alloc_fn(bytes)!)) + $if $checks(#alloc_fn(bytes)!): void* data = #alloc_fn(header + bytes)!; $else void* data = #alloc_fn(header + bytes); @@ -56,7 +56,7 @@ macro void*! @aligned_alloc(#alloc_fn, usz bytes, usz alignment, usz offset) macro void*! @aligned_calloc(#calloc_fn, usz bytes, usz alignment, usz offset) { usz header = mem::aligned_offset(AlignedBlock.sizeof + offset, alignment) - offset; - $if ($checks(#calloc_fn(bytes)!)) + $if $checks(#calloc_fn(bytes)!): void* data = #calloc_fn(header + bytes)!; $else void* data = #calloc_fn(header + bytes); @@ -78,7 +78,7 @@ macro void*! @aligned_realloc(#calloc_fn, #free_fn, void* old_pointer, usz bytes void* data_start = desc.start; void* new_data = @aligned_calloc(#calloc_fn, bytes, alignment, offset)!; mem::copy(new_data, old_pointer, desc.len > bytes ? desc.len : bytes, mem::DEFAULT_MEM_ALIGNMENT, mem::DEFAULT_MEM_ALIGNMENT); - $if ($checks(#free_fn(data_start)!)) + $if $checks(#free_fn(data_start)!): #free_fn(data_start)!; $else #free_fn(data_start); @@ -89,7 +89,7 @@ macro void*! @aligned_realloc(#calloc_fn, #free_fn, void* old_pointer, usz bytes macro void! @aligned_free(#free_fn, void* old_pointer) { AlignedBlock* desc = (AlignedBlock*)old_pointer - 1; - $if ($checks(#free_fn(desc.start)!)) + $if $checks(#free_fn(desc.start)!): #free_fn(desc.start)!; $else #free_fn(desc.start); diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index a020e78da..170887580 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -78,7 +78,7 @@ struct CallstackElement fn void default_panic(String message, String file, String function, uint line) { CallstackElement* stack = $$stacktrace(); - $if ($defined(io::stderr) && $defined(File.printf)) + $if $defined(io::stderr) && $defined(File.printf): if (stack) stack = stack.prev; if (stack) @@ -181,7 +181,7 @@ macro enum_by_name($Type, String enum_name) @builtin **/ macro bool @likely(bool #value, $probability = 1.0) @builtin { -$if ($probability == 1.0) +$if $probability == 1.0: return $$expect(#value, true); $else return $$expect_with_probability(#value, true, $probability); @@ -197,7 +197,7 @@ $endif **/ macro bool @unlikely(bool #value, $probability = 1.0) @builtin { -$if ($probability == 1.0) +$if $probability == 1.0: return $$expect(#value, false); $else return $$expect_with_probability(#value, false, $probability); @@ -211,7 +211,7 @@ $endif **/ macro @expect(#value, expected, $probability = 1.0) @builtin { - $if ($probability == 1.0) + $if $probability == 1.0: return $$expect(#value, ($typeof(#value))expected); $else return $$expect_with_probability(#value, expected, $probability); diff --git a/lib/std/core/builtin_comparison.c3 b/lib/std/core/builtin_comparison.c3 index b9f7f05ba..6bbd53235 100644 --- a/lib/std/core/builtin_comparison.c3 +++ b/lib/std/core/builtin_comparison.c3 @@ -82,7 +82,7 @@ $endswitch macro min(x, ...) @builtin { - $if ($vacount == 1) + $if $vacount == 1: return less(x, $vaarg(0)) ? x : $vaarg(0); $else var result = x; @@ -98,7 +98,7 @@ macro min(x, ...) @builtin macro max(x, ...) @builtin { - $if ($vacount == 1) + $if $vacount == 1: return greater(x, $vaarg(0)) ? x : $vaarg(0); $else var result = x; diff --git a/lib/std/core/cinterop.c3 b/lib/std/core/cinterop.c3 index 2fd58809d..56d9e5d32 100644 --- a/lib/std/core/cinterop.c3 +++ b/lib/std/core/cinterop.c3 @@ -8,13 +8,13 @@ const C_LONG_SIZE = $$C_LONG_SIZE; const C_SHORT_SIZE = $$C_SHORT_SIZE; const C_LONG_LONG_SIZE = $$C_LONG_LONG_SIZE; -$assert (C_SHORT_SIZE < 32); -$assert (C_INT_SIZE < 128); -$assert (C_LONG_SIZE < 128); -$assert (C_LONG_LONG_SIZE <= 128); -$assert (C_SHORT_SIZE <= C_INT_SIZE); -$assert (C_INT_SIZE <= C_LONG_SIZE); -$assert (C_LONG_SIZE <= C_LONG_LONG_SIZE); +$assert C_SHORT_SIZE < 32; +$assert C_INT_SIZE < 128; +$assert C_LONG_SIZE < 128; +$assert C_LONG_LONG_SIZE <= 128; +$assert C_SHORT_SIZE <= C_INT_SIZE; +$assert C_INT_SIZE <= C_LONG_SIZE; +$assert C_LONG_SIZE <= C_LONG_LONG_SIZE; $switch ($$C_INT_SIZE) $case 64: @@ -27,7 +27,7 @@ $case 16: typedef CInt = short; typedef CUInt = ushort; $default: - $assert(false, "Invalid C int size"); + $error "Invalid C int size"; $endswitch $switch ($$C_LONG_SIZE) @@ -41,7 +41,7 @@ $case 16: typedef CLong = short; typedef CULong = ushort; $default: - $assert(false, "Invalid C long size"); + $error "Invalid C long size"; $endswitch $switch ($$C_SHORT_SIZE) @@ -55,7 +55,7 @@ $case 8: typedef CShort = ichar; typedef CUShort = char; $default: - $assert(false, "Invalid C short size"); + $error "Invalid C short size"; $endswitch $switch ($$C_LONG_LONG_SIZE) @@ -72,7 +72,7 @@ $case 16: typedef CLongLong = short; typedef CULongLong = ushort; $default: - $assert(false, "Invalid C long long size"); + $error "Invalid C long long size"; $endswitch @@ -80,7 +80,7 @@ $endswitch typedef CSChar = ichar; typedef CUChar = char; -$if ($$C_CHAR_IS_SIGNED) +$if $$C_CHAR_IS_SIGNED: typedef CChar = ichar; $else typedef CChar = char; diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index 6d7bc39b6..cc54d3dd6 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -308,7 +308,7 @@ macro void DString.append(DString* str, value) $case @convertible(value, String): str.append_chars(value); $default: - $assert(false, "Unsupported type for append – use printf instead."); + $error "Unsupported type for append – use printf instead."; $endswitch $endswitch } diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 3b43b947c..cc2e50ebd 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -177,7 +177,7 @@ macro bool os_is_posix() **/ fn String! get_var(String name) { -$if (COMPILER_LIBC_AVAILABLE && !os_is_win32()) +$if COMPILER_LIBC_AVAILABLE && !os_is_win32(): @pool() { ZString val = libc::getenv(name.zstr_tcopy()); @@ -196,7 +196,7 @@ $endif **/ fn void set_var(String name, String value, bool overwrite = true) { -$if (COMPILER_LIBC_AVAILABLE && !os_is_win32()) +$if COMPILER_LIBC_AVAILABLE && !os_is_win32(): @pool() { if (libc::setenv(name.zstr_tcopy(), value.zstr_copy(), (int)overwrite)) @@ -213,7 +213,7 @@ $endif **/ fn void clear_var(String name) { -$if (COMPILER_LIBC_AVAILABLE && !os_is_win32()) +$if COMPILER_LIBC_AVAILABLE && !os_is_win32(): @pool() { if (libc::unsetenv(name.zstr_tcopy())) diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index fe8c75689..3fa2fd010 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -91,7 +91,7 @@ fn bool ptr_is_aligned(void* ptr, usz alignment) @inline macro void clear(void* dst, usz len, usz $dst_align = 0, bool $is_volatile = false, bool $inlined = false) { - $if ($inlined) + $if $inlined: $$memset_inline(dst, (char)0, len, $is_volatile, $dst_align); $else $$memset(dst, (char)0, len, $is_volatile, $dst_align); @@ -100,7 +100,7 @@ macro void clear(void* dst, usz len, usz $dst_align = 0, bool $is_volatile = fal macro void copy(void* dst, void* src, usz len, usz $dst_align = 0, usz $src_align = 0, bool $is_volatile = false, bool $inlined = false) { - $if ($inlined) + $if $inlined: $$memcpy_inline(dst, src, len, $is_volatile, $dst_align, $src_align); $else $$memcpy(dst, src, len, $is_volatile, $dst_align, $src_align); @@ -114,7 +114,7 @@ macro void move(void* dst, void* src, usz len, usz $dst_align = 0, usz $src_alig macro void set(void* dst, char val, usz len, usz $dst_align = 0, bool $is_volatile = false, bool $inlined = false) { - $if ($inlined) + $if $inlined: $$memset_inline(dst, val, len, $is_volatile, $dst_align); $else $$memset(dst, val, len, $is_volatile, $dst_align); @@ -130,12 +130,12 @@ macro void set(void* dst, char val, usz len, usz $dst_align = 0, bool $is_volati **/ macro bool equals(a, b, isz len = -1, usz $align = 0) { - $if (!$align) + $if !$align: $align = $typeof(a[0]).alignof; $endif void* x @noinit; void* y @noinit; - $if (values::@inner_kind(a) == TypeKind.SUBARRAY) + $if values::@inner_kind(a) == TypeKind.SUBARRAY: len = a.len; if (len != b.len) return false; x = a.ptr; @@ -206,10 +206,10 @@ macro malloc(..., Allocator* using = mem::heap(), usz end_padding = 0) @builtin **/ macro malloc_checked(..., Allocator* using = mem::heap(), usz end_padding = 0) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $assert(!type_alloc_must_be_aligned($vatype(0)), "Type must be allocated with malloc_aligned"); - $if ($vacount == 2) + $assert !type_alloc_must_be_aligned($vatype(0)) : "Type must be allocated with malloc_aligned"; + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)using.alloc($Type.sizeof * size + end_padding))[:size]; $else @@ -228,9 +228,9 @@ macro malloc_checked(..., Allocator* using = mem::heap(), usz end_padding = 0) @ **/ macro malloc_aligned(..., usz alignment = 0, usz end_padding = 0, Allocator* using = mem::heap()) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $if ($vacount == 2) + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)using.alloc_aligned($Type.sizeof * size + end_padding, alignment))[:size]; $else @@ -256,10 +256,10 @@ macro calloc(..., Allocator* using = mem::heap(), usz end_padding = 0) @builtin **/ macro calloc_checked(..., Allocator* using = mem::heap(), usz end_padding = 0) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $assert(!type_alloc_must_be_aligned($vatype(0)), "Type must be allocated with calloc_aligned"); - $if ($vacount == 2) + $assert !type_alloc_must_be_aligned($vatype(0)) : "Type must be allocated with calloc_aligned"; + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)using.calloc($Type.sizeof * size + end_padding))[:size]; $else @@ -278,9 +278,9 @@ macro calloc_checked(..., Allocator* using = mem::heap(), usz end_padding = 0) @ **/ macro calloc_aligned(..., usz alignment = 0, Allocator* using = mem::heap(), usz end_padding = 0) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $if ($vacount == 2) + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)using.calloc_aligned($Type.sizeof * size + end_padding, alignment))[:size]; $else @@ -331,9 +331,9 @@ macro void @scoped(Allocator* using; @body()) **/ macro tmalloc(..., usz end_padding = 0, usz alignment = DEFAULT_MEM_ALIGNMENT) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $if ($vacount == 2) + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)temp().alloc_aligned($Type.sizeof * size + end_padding, alignment))[:size]!!; $else @@ -350,9 +350,9 @@ macro tmalloc(..., usz end_padding = 0, usz alignment = DEFAULT_MEM_ALIGNMENT) @ **/ macro tcalloc(..., usz end_padding = 0, usz alignment = mem::DEFAULT_MEM_ALIGNMENT) @builtin { - $if ($checks($vatype(0).sizeof)) + $if $checks($vatype(0).sizeof): var $Type = $vatype(0); - $if ($vacount == 2) + $if $vacount == 2: usz size = $vaarg(1); return (($Type*)temp().calloc_aligned($Type.sizeof * size + end_padding, alignment))[:size]!!; $else @@ -411,7 +411,7 @@ macro TempAllocator* temp() macro Allocator* current_allocator() => thread_allocator; macro Allocator* heap() => thread_allocator; -$if (!env::COMPILER_LIBC_AVAILABLE && env::ARCH_TYPE == ArchType.WASM32 || env::ARCH_TYPE == ArchType.WASM64) +$if !env::COMPILER_LIBC_AVAILABLE && env::ARCH_TYPE == ArchType.WASM32 || env::ARCH_TYPE == ArchType.WASM64: SimpleHeapAllocator wasm_allocator @private; diff --git a/lib/std/core/private/main_stub.c3 b/lib/std/core/private/main_stub.c3 index b8066f7b3..f374b3e15 100644 --- a/lib/std/core/private/main_stub.c3 +++ b/lib/std/core/private/main_stub.c3 @@ -55,7 +55,7 @@ macro int @main_to_void_main_args(#m, int argc, char** argv) return 0; } -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn Char16** _win_command_line_to_argv_w(ushort* cmd_line, int* argc_ptr) @extern("CommandLineToArgvW"); diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index 672e80252..824280315 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -88,7 +88,7 @@ fn bool __run_default_test_runner() return test_runner_create().run(); } -$if (!env::COMPILER_LIBC_AVAILABLE && env::ARCH_TYPE == ArchType.WASM32 || env::ARCH_TYPE == ArchType.WASM64) +$if !env::COMPILER_LIBC_AVAILABLE && env::ARCH_TYPE == ArchType.WASM32 || env::ARCH_TYPE == ArchType.WASM64: extern fn void __wasm_call_ctors(); fn void wasm_initialize() @extern("_initialize") @wasm diff --git a/lib/std/core/string_to_real.c3 b/lib/std/core/string_to_real.c3 index aa8362685..cf405e62c 100644 --- a/lib/std/core/string_to_real.c3 +++ b/lib/std/core/string_to_real.c3 @@ -460,9 +460,9 @@ macro String.to_real(String chars, $Type) @private const int BITS = math::DOUBLE_MANT_DIG; const int EMIN = math::DOUBLE_MIN_EXP - BITS; $case float128: - $assert(false, "Not yet supported"); + $error "Not yet supported"; $default: - $assert(false, "Unexpected type"); + $error "Unexpected type"; $endswitch while (chars.len && chars[0] == ' ') chars = chars[1..]; diff --git a/lib/std/core/types.c3 b/lib/std/core/types.c3 index 089f5105e..dc2f29be7 100644 --- a/lib/std/core/types.c3 +++ b/lib/std/core/types.c3 @@ -77,7 +77,7 @@ macro any_to_int(any v, $Type) macro bool is_numerical($Type) { var $kind = $Type.kindof; - $if ($kind == TypeKind.DISTINCT) + $if $kind == TypeKind.DISTINCT: return is_numerical($Type.inner); $else return $kind == TypeKind.SIGNED_INT || $kind == TypeKind.UNSIGNED_INT || $kind == TypeKind.FLOAT @@ -98,7 +98,7 @@ macro bool is_indexable($Type) macro bool is_comparable($Type) { var $kind = $Type.kindof; - $if ($kind == TypeKind.DISTINCT) + $if $kind == TypeKind.DISTINCT: return is_comparable($Type.inner); $else return $kind == TypeKind.SIGNED_INT || $kind == TypeKind.UNSIGNED_INT || $kind == TypeKind.FLOAT @@ -162,7 +162,7 @@ macro bool is_vector($Type) macro TypeKind inner_kind($Type) { - $if ($Type.kindof == TypeKind.DISTINCT) + $if $Type.kindof == TypeKind.DISTINCT: return inner_kind($typefrom($Type.inner)); $else return $Type.kindof; @@ -182,11 +182,11 @@ macro bool is_same($TypeA, $TypeB) macro bool @has_same(#a, #b, ...) { var $type_a = $typeof(#a).typeid; - $if ($type_a != $typeof(#b).typeid) + $if $type_a != $typeof(#b).typeid: return false; $endif $for (var $i = 0; $i < $vacount; $i++) - $if ($typeof($vaexpr($i)).typeid != $type_a) + $if $typeof($vaexpr($i)).typeid != $type_a: return false; $endif $endfor @@ -213,7 +213,7 @@ macro bool is_promotable_to_float($Type) => types::is_float($Type) || types::is_ macro bool is_same_vector_type($Type1, $Type2) { - $if ($Type1.kindof != TypeKind.VECTOR) + $if $Type1.kindof != TypeKind.VECTOR: return $Type2.kindof != TypeKind.VECTOR; $else return $Type1.inner == $Type2.inner && $Type1.len == $Type2.len; @@ -222,7 +222,7 @@ macro bool is_same_vector_type($Type1, $Type2) macro bool is_equatable_type($Type) { - $if ($defined($Type.less) || $defined($Type.compare_to) || $defined($Type.equals)) + $if $defined($Type.less) || $defined($Type.compare_to) || $defined($Type.equals): return true; $else return is_equatable($Type); @@ -236,7 +236,7 @@ macro bool is_equatable_value(value) macro bool is_comparable_value(value) { - $if ($defined(value.less) || $defined(value.compare_to)) + $if $defined(value.less) || $defined(value.compare_to): return true; $else return is_comparable($typeof(value)); diff --git a/lib/std/core/values.c3 b/lib/std/core/values.c3 index efce6c743..f65ec893e 100644 --- a/lib/std/core/values.c3 +++ b/lib/std/core/values.c3 @@ -12,7 +12,7 @@ macro bool @is_promotable_to_float(#value) => types::is_promotable_to_float($typ macro bool @is_same_vector_type(#value1, #value2) => types::is_same_vector_type($typeof(#value1), $typeof(#value2)); macro promote_int(x) { - $if (@is_int(x)) + $if @is_int(x): return (double)x; $else return x; diff --git a/lib/std/hash/sha1.c3 b/lib/std/hash/sha1.c3 index 2eccac421..941e8d0bc 100644 --- a/lib/std/hash/sha1.c3 +++ b/lib/std/hash/sha1.c3 @@ -96,7 +96,7 @@ macro @blk(&block, i) @local macro @blk0(&block, i) @local { -$if (env::BIG_ENDIAN) +$if env::BIG_ENDIAN: return block.l[i]; $else return block.l[i] = (block.l[i].rotl(24) & 0xFF00FF00) diff --git a/lib/std/io/io.c3 b/lib/std/io/io.c3 index ffd220cbc..144edf7b2 100644 --- a/lib/std/io/io.c3 +++ b/lib/std/io/io.c3 @@ -63,7 +63,7 @@ macro void print(x) $case DString: (void)stdout().print(x.str()); $default: - $if (@convertible(x, String)) + $if @convertible(x, String): (void)stdout().print((String)x); $else (void)stdout().printf("%s", x); @@ -82,7 +82,7 @@ macro void printn(x = "") $case DString: (void)stdout().printn(x.str()); $default: - $if (@convertible(x, String)) + $if @convertible(x, String): (void)stdout().printn((String)x); $else (void)stdout().printfn("%s", x); diff --git a/lib/std/io/io_formatter_private.c3 b/lib/std/io/io_formatter_private.c3 index 8b925b089..52c103e05 100644 --- a/lib/std/io/io_formatter_private.c3 +++ b/lib/std/io/io_formatter_private.c3 @@ -69,10 +69,10 @@ fn uint128! int_from_any(any arg, bool *is_neg) @private fn FloatType! float_from_any(any arg) @private { - $if (env::F128_SUPPORT) + $if env::F128_SUPPORT: if (arg.type == float128.typeid) return (FloatType)*((float128*)arg.ptr); $endif - $if (env::F16_SUPPORT) + $if env::F16_SUPPORT: if (arg.type == float16.typeid) return *((float16*)arg.ptr); $endif if (arg.type.kindof == TypeKind.DISTINCT) diff --git a/lib/std/io/io_printf.c3 b/lib/std/io/io_printf.c3 index 32bc43196..221334aad 100644 --- a/lib/std/io/io_printf.c3 +++ b/lib/std/io/io_printf.c3 @@ -109,7 +109,7 @@ fn void Formatter.init(Formatter* this, OutputFn out_fn, void* data = null) */ macro void formatter_register_type($Type) { - $if ($checks($Type a, a.to_format(&&Formatter {}))) + $if $checks($Type a, a.to_format(&&Formatter {})): if (!toformat_functions.table.len) { toformat_functions.init(64); diff --git a/lib/std/io/os/file.c3 b/lib/std/io/os/file.c3 index d3df2ca7b..63c60599b 100644 --- a/lib/std/io/os/file.c3 +++ b/lib/std/io/os/file.c3 @@ -9,25 +9,25 @@ typedef FtellFn = fn usz!(void*); typedef FwriteFn = fn usz!(void*, char[] buffer); typedef FreadFn = fn usz!(void*, char[] buffer); -$if (!$defined(native_fopen_fn)) +$if !$defined(native_fopen_fn): FopenFn native_fopen_fn @weak; $endif -$if (!$defined(native_fclose_fn)) +$if !$defined(native_fclose_fn): FcloseFn native_fclose_fn @weak; $endif -$if (!$defined(native_freopen_fn)) +$if !$defined(native_freopen_fn): FreopenFn native_freopen_fn @weak; $endif -$if (!$defined(native_fseek_fn)) +$if !$defined(native_fseek_fn): FseekFn native_fseek_fn @weak; $endif -$if (!$defined(native_ftell_fn)) +$if !$defined(native_ftell_fn): FtellFn native_ftell_fn @weak; $endif -$if (!$defined(native_fwrite_fn)) +$if !$defined(native_fwrite_fn): FwriteFn native_fwrite_fn @weak; $endif -$if (!$defined(native_fread_fn)) +$if !$defined(native_fread_fn): FreadFn native_fread_fn @weak; $endif @@ -38,13 +38,13 @@ $endif **/ fn void*! native_fopen(String filename, String mode) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_fopen_fn) return native_fopen_fn(filename, mode); unreachable("Tried to call fopen without support."); $else @pool() { - $if (env::os_is_win32()) + $if env::os_is_win32(): void* file = (CFile)_wfopen(filename.to_temp_utf16(), filename.to_temp_utf16())!; $else void* file = libc::fopen(filename.zstr_tcopy(), mode.zstr_tcopy()); @@ -60,13 +60,13 @@ $endif **/ fn void*! native_freopen(void* file, String filename, String mode) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_freopen_fn) return native_freopen_fn(file, filename, mode); unreachable("Tried to call freopen without support."); $else @pool() { - $if (env::os_is_win32()) + $if env::os_is_win32(): file = _wfreopen(filename.to_temp_utf16(), mode.to_temp_utf16(), file)!; $else file = libc::freopen(filename.zstr_tcopy(), mode.zstr_tcopy(), file); @@ -78,11 +78,11 @@ $endif fn void! native_fseek(void* file, isz offset, Seek seek_mode) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_fseek_fn) return native_fseek_fn(file, offset, seek_mode); unreachable("Tried to call fseek without support."); $else - $if (env::os_is_win32()) + $if env::os_is_win32(): bool success = _fseeki64(file, (long)offset, (int)seek_mode) == 0; $else bool success = libc::fseek(file, (SeekIndex)offset, (CInt)seek_mode) == 0; @@ -93,11 +93,11 @@ $endif fn usz! native_ftell(CFile file) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_ftell_fn) return native_ftell_fn(file); unreachable("Tried to call ftell without support."); $else - $if (env::os_is_win32()) + $if env::os_is_win32(): long index = _ftelli64(file); return index >= 0 ? index : file_seek_errno()?; $else @@ -109,7 +109,7 @@ $endif fn usz! native_fwrite(CFile file, char[] buffer) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_fwrite_fn) return native_fwrite_fn(file, buffer); unreachable("Tried to call fwrite without support."); $else @@ -119,7 +119,7 @@ $endif fn usz! native_fread(CFile file, char[] buffer) @inline { -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: if (native_fread_fn) return native_fread_fn(file, buffer); unreachable("Tried to call fread without support."); $else @@ -175,13 +175,13 @@ macro anyfault file_seek_errno() @local } // Win functions -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn void* _wfopen(Char16*, Char16*) @local; extern fn void* _wfreopen(Char16*, Char16*, CFile) @local; extern fn int _fseeki64(CFile, long, int) @local; extern fn long _ftelli64(CFile) @local; $endif -$if (env::os_is_posix()) +$if env::os_is_posix(): extern fn CInt access(ZString path, CInt mode); $endif diff --git a/lib/std/io/os/fileinfo_darwin.c3 b/lib/std/io/os/fileinfo_darwin.c3 index 701151118..9b344ce2b 100644 --- a/lib/std/io/os/fileinfo_darwin.c3 +++ b/lib/std/io/os/fileinfo_darwin.c3 @@ -1,8 +1,7 @@ module std::io::file::os; import libc; -$if (env::os_is_darwin()) - +$if env::os_is_darwin(): struct DarwinTimespec @private { diff --git a/lib/std/io/os/fileinfo_other.c3 b/lib/std/io/os/fileinfo_other.c3 index b87803902..7ff9392ff 100644 --- a/lib/std/io/os/fileinfo_other.c3 +++ b/lib/std/io/os/fileinfo_other.c3 @@ -1,7 +1,7 @@ module std::io::file::os; // native_temp_directory, for non Win32 -$if (!env::os_is_win32()) +$if !env::os_is_win32(): fn Path! native_temp_directory(Allocator* using = mem::heap()) { @@ -13,7 +13,7 @@ fn Path! native_temp_directory(Allocator* using = mem::heap()) return path::new("/tmp", using); } -$if (env::COMPILER_LIBC_AVAILABLE) +$if env::COMPILER_LIBC_AVAILABLE: extern fn void* opendir(ZString); extern fn void closedir(void*); @@ -84,7 +84,7 @@ $endif $endif -$if (!env::os_is_darwin() && !env::os_is_win32()) +$if !env::os_is_darwin() && !env::os_is_win32(): fn usz! native_file_size(String path) { @@ -93,7 +93,7 @@ fn usz! native_file_size(String path) return f.seek(0, Seek.END)!; } -$if (env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE) +$if env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE: fn bool native_file_or_dir_exists(String path) { @@ -142,7 +142,7 @@ $case MACOS: $case TVOS: $case WATCHOS: -$if (env::ARCH_TYPE == X86_64) +$if env::ARCH_TYPE == X86_64: extern fn NativeDirentry* readdir(void*) @extern("readdir$INODE64"); $else extern fn NativeDirentry* readdir(void*) @extern("readdir"); diff --git a/lib/std/io/os/fileinfo_win32.c3 b/lib/std/io/os/fileinfo_win32.c3 index 001dba7d3..6e334982b 100644 --- a/lib/std/io/os/fileinfo_win32.c3 +++ b/lib/std/io/os/fileinfo_win32.c3 @@ -1,7 +1,7 @@ module std::io::file::os; import std::os::win32; -$if (env::os_is_win32()) +$if env::os_is_win32(): const Win32_DWORD FILE_ATTRIBUTE_READONLY = 0x01; const Win32_DWORD FILE_ATTRIBUTE_HIDDEN = 0x02; diff --git a/lib/std/io/path.c3 b/lib/std/io/path.c3 index 099d0d066..c73cc54bb 100644 --- a/lib/std/io/path.c3 +++ b/lib/std/io/path.c3 @@ -96,7 +96,7 @@ fn bool! rmdir(Path path) fn void! rmtree(Path path) { if (!path.path_string.len) return PathResult.INVALID_PATH?; -$if ($defined(os::native_rmtree)) +$if $defined(os::native_rmtree): return os::native_rmtree(path); $else assert(false, "rmtree is not available"); diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index 1ffb7c656..bc4c50eb7 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -35,7 +35,7 @@ typedef TerminateFunction = fn void(); typedef CompareFunction = fn int(void*, void*); typedef JmpBuf = uptr[$$JMP_BUF_SIZE]; -$if (env::COMPILER_LIBC_AVAILABLE) +$if env::COMPILER_LIBC_AVAILABLE: extern fn double atof(char* str); extern fn int atoi(char* str); @@ -59,7 +59,7 @@ extern fn int rand(); extern fn void srand(uint seed); extern fn void longjmp(JmpBuf* buffer, CInt value); -$if (env::os_is_win32()) +$if env::os_is_win32(): // TODO win32 aarch64 extern fn CInt _setjmp(void* frameptr, JmpBuf* buffer); macro CInt setjmp(JmpBuf* buffer) => _setjmp($$frameaddress(), buffer); @@ -205,7 +205,7 @@ const int FILENAME_MAX = 1024; typedef Errno = distinct CInt; typedef SeekIndex = CLong; -$if (env::COMPILER_LIBC_AVAILABLE) +$if env::COMPILER_LIBC_AVAILABLE: extern fn int fclose(CFile stream); extern fn void clearerr(CFile stream); @@ -370,7 +370,7 @@ struct Tm $endswitch -$if (env::os_is_win32()) +$if env::os_is_win32(): struct TimeSpec { @@ -411,7 +411,7 @@ extern fn Tm* gmtime(Time_t *timer); extern fn Tm* localtime(Time_t *timer); -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn Tm* _gmtime64_s(Tm* buf, Time_t *timer); extern fn Tm* _localtime64_s(Tm* buf, Time_t *timer); extern fn void _get_timezone(CLong *timezone); @@ -451,7 +451,7 @@ const Errno ENOEXEC = 8; // Exec format error const Errno EBADF = 9; // Bad file number const Errno ECHILD = 10; // No child processes -$if (env::OS_TYPE == MACOS) +$if env::os_is_darwin(): const Errno EAGAIN = 35; // Try again Macos $else const Errno EAGAIN = 11; // Try again diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index 935b127ce..fab48e14f 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -120,7 +120,7 @@ macro abs(x) => $$abs(x); macro sign(x) { var $Type = $typeof(x); - $if ($Type.kindof == TypeKind.UNSIGNED_INT) + $if $Type.kindof == TypeKind.UNSIGNED_INT: return ($Type)(x > 0); $else return ($Type)(x > 0) - ($Type)(x < 0); @@ -134,7 +134,7 @@ macro sign(x) **/ macro atan2(x, y) { - $if (@typeis(x, float) && @typeis(y, float)) + $if @typeis(x, float) && @typeis(y, float): return _atan2f(x, y); $else return _atan2(x, y); @@ -148,7 +148,7 @@ macro atan2(x, y) **/ macro @sincos(x, y) { - $if ($typeof(y[0]).typeid == float.typeid) + $if $typeof(y[0]).typeid == float.typeid: return _sincosf(x, y); $else return _sincos(x, y); @@ -161,7 +161,7 @@ macro @sincos(x, y) **/ macro atan(x) { - $if ($typeof(x).typeid == float.typeid) + $if $typeof(x).typeid == float.typeid: return _atanf(x); $else return _atan(x); @@ -276,7 +276,7 @@ macro log10(x) => $$log10(values::promote_int(x)); **/ macro max(x, y, ...) { - $if ($vacount == 0) + $if $vacount == 0: return $$max(x, y); $else var m = $$max(x, y); @@ -293,7 +293,7 @@ macro max(x, y, ...) **/ macro min(x, y, ...) { - $if ($vacount == 0) + $if $vacount == 0: return $$min(x, y); $else var m = $$min(x, y); @@ -321,7 +321,7 @@ macro nearbyint(x) => $$nearbyint(x); **/ macro pow(x, exp) { - $if (types::is_floatlike($typeof(exp))) + $if types::is_floatlike($typeof(exp)): return $$pow(x, ($typeof(x))exp); $else return $$pow_int(x, exp); @@ -333,7 +333,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); @@ -347,7 +347,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; @@ -422,7 +422,7 @@ $endswitch **/ macro bool is_finite(x) { - $switch($typeof(x)) + $switch ($typeof(x)) $case float: $case float16: return bitcast((float)x, uint) & 0x7fffffff < 0x7f800000; diff --git a/lib/std/math/math_nolibc/__cos.c3 b/lib/std/math/math_nolibc/__cos.c3 index aa8a11812..564a89dc8 100644 --- a/lib/std/math/math_nolibc/__cos.c3 +++ b/lib/std/math/math_nolibc/__cos.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_cos.c */ /* diff --git a/lib/std/math/math_nolibc/__cosdf.c3 b/lib/std/math/math_nolibc/__cosdf.c3 index 4b599a5be..9b039d59b 100644 --- a/lib/std/math/math_nolibc/__cosdf.c3 +++ b/lib/std/math/math_nolibc/__cosdf.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.c */ /* diff --git a/lib/std/math/math_nolibc/__sin.c3 b/lib/std/math/math_nolibc/__sin.c3 index d77e29e3d..e6b841c03 100644 --- a/lib/std/math/math_nolibc/__sin.c3 +++ b/lib/std/math/math_nolibc/__sin.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_sin.c */ /* diff --git a/lib/std/math/math_nolibc/__sindf.c3 b/lib/std/math/math_nolibc/__sindf.c3 index 390c37fca..19242723b 100644 --- a/lib/std/math/math_nolibc/__sindf.c3 +++ b/lib/std/math/math_nolibc/__sindf.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/__tan.c3 b/lib/std/math/math_nolibc/__tan.c3 index d6de73dca..28f8cd93a 100644 --- a/lib/std/math/math_nolibc/__tan.c3 +++ b/lib/std/math/math_nolibc/__tan.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */ /* diff --git a/lib/std/math/math_nolibc/__tandf.c3 b/lib/std/math/math_nolibc/__tandf.c3 index 038b0dd4b..34bad3a86 100644 --- a/lib/std/math/math_nolibc/__tandf.c3 +++ b/lib/std/math/math_nolibc/__tandf.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */ /* diff --git a/lib/std/math/math_nolibc/atan.c3 b/lib/std/math/math_nolibc/atan.c3 index 92def4237..113749e5c 100644 --- a/lib/std/math/math_nolibc/atan.c3 +++ b/lib/std/math/math_nolibc/atan.c3 @@ -1,6 +1,6 @@ module std::math::nolibc::atan; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: const double[*] ATANHI @private = { 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ diff --git a/lib/std/math/math_nolibc/ceil.c3 b/lib/std/math/math_nolibc/ceil.c3 index 39479414f..f71d6c33e 100644 --- a/lib/std/math/math_nolibc/ceil.c3 +++ b/lib/std/math/math_nolibc/ceil.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double _ceil(double x) @weak @extern("ceil") @nostrip { diff --git a/lib/std/math/math_nolibc/cos.c3 b/lib/std/math/math_nolibc/cos.c3 index 132981c10..fc1ef7231 100644 --- a/lib/std/math/math_nolibc/cos.c3 +++ b/lib/std/math/math_nolibc/cos.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn float _cosf(float x) @extern("cosf") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/exp2.c3 b/lib/std/math/math_nolibc/exp2.c3 index 7f5fa42c6..0598bfd7b 100644 --- a/lib/std/math/math_nolibc/exp2.c3 +++ b/lib/std/math/math_nolibc/exp2.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: macro uint _top12f(float x) @private => bitcast(x, uint) >> 20; diff --git a/lib/std/math/math_nolibc/floor.c3 b/lib/std/math/math_nolibc/floor.c3 index be95c0743..f95391cfb 100644 --- a/lib/std/math/math_nolibc/floor.c3 +++ b/lib/std/math/math_nolibc/floor.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double _floor(double x) @weak @extern("floor") @nostrip { diff --git a/lib/std/math/math_nolibc/pow.c3 b/lib/std/math/math_nolibc/pow.c3 index 8a30b3f48..8eaf309ad 100644 --- a/lib/std/math/math_nolibc/pow.c3 +++ b/lib/std/math/math_nolibc/pow.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn float powf_broken(float x, float f) @extern("powf") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/rempi.c3 b/lib/std/math/math_nolibc/rempi.c3 index d12333a5b..4914500c1 100644 --- a/lib/std/math/math_nolibc/rempi.c3 +++ b/lib/std/math/math_nolibc/rempi.c3 @@ -1,7 +1,7 @@ module std::math::nolibc; import std::math; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */ /* diff --git a/lib/std/math/math_nolibc/round.c3 b/lib/std/math/math_nolibc/round.c3 index 372495a70..53856b870 100644 --- a/lib/std/math/math_nolibc/round.c3 +++ b/lib/std/math/math_nolibc/round.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double _round(double x) @extern("round") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/scalbn.c3 b/lib/std/math/math_nolibc/scalbn.c3 index ac48dfa94..69c416ac2 100644 --- a/lib/std/math/math_nolibc/scalbn.c3 +++ b/lib/std/math/math_nolibc/scalbn.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double _scalbn(double x, int n) @weak @extern("scalbn") @nostrip { diff --git a/lib/std/math/math_nolibc/sin.c3 b/lib/std/math/math_nolibc/sin.c3 index 80b221888..e5cdad2f9 100644 --- a/lib/std/math/math_nolibc/sin.c3 +++ b/lib/std/math/math_nolibc/sin.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/sincos.c3 b/lib/std/math/math_nolibc/sincos.c3 index ea6d5fcf3..b5a851bd5 100644 --- a/lib/std/math/math_nolibc/sincos.c3 +++ b/lib/std/math/math_nolibc/sincos.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/tan.c3 b/lib/std/math/math_nolibc/tan.c3 index 0888224d0..ab1530263 100644 --- a/lib/std/math/math_nolibc/tan.c3 +++ b/lib/std/math/math_nolibc/tan.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: /* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ /* diff --git a/lib/std/math/math_nolibc/trig.c3 b/lib/std/math/math_nolibc/trig.c3 index b55cb51fe..09b5eed4c 100644 --- a/lib/std/math/math_nolibc/trig.c3 +++ b/lib/std/math/math_nolibc/trig.c3 @@ -1,6 +1,6 @@ module std::math::nolibc::trig; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double sincos_broken(double x) @extern("sincos") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/trunc.c3 b/lib/std/math/math_nolibc/trunc.c3 index c61a4f693..6ab8dee04 100644 --- a/lib/std/math/math_nolibc/trunc.c3 +++ b/lib/std/math/math_nolibc/trunc.c3 @@ -1,6 +1,6 @@ module std::math::nolibc; -$if (!env::COMPILER_LIBC_AVAILABLE) +$if !env::COMPILER_LIBC_AVAILABLE: fn double _trunc(double x) @weak @extern("trunc") @nostrip { diff --git a/lib/std/math/math_vector.c3 b/lib/std/math/math_vector.c3 index f0c3e610b..24b6830b8 100644 --- a/lib/std/math/math_vector.c3 +++ b/lib/std/math/math_vector.c3 @@ -217,7 +217,7 @@ return v; var view_proj = m1.mul(m2); var invert = view_proj.invert(); // Create quaternion from source point - $if ($typeof(v[0]).typeid == float.typeid) + $if $typeof(v[0]).typeid == float.typeid: Quaternionf quat = { v.x, v.y, v.z, 1 }; $else Quaternion quat = { v.x, v.y, v.z, 1 }; diff --git a/lib/std/net/os/common.c3 b/lib/std/net/os/common.c3 index 4704496cc..5c10ede95 100644 --- a/lib/std/net/os/common.c3 +++ b/lib/std/net/os/common.c3 @@ -1,8 +1,8 @@ module std::net::os; -$if ($defined(PLATFORM_AF_INET)) +$if $defined(PLATFORM_AF_INET): -$if (!$defined(PLATFORM_O_NONBLOCK)) +$if !$defined(PLATFORM_O_NONBLOCK): const PLATFORM_O_NONBLOCK = 0; $endif diff --git a/lib/std/net/os/darwin.c3 b/lib/std/net/os/darwin.c3 index d057b3153..d609ce26f 100644 --- a/lib/std/net/os/darwin.c3 +++ b/lib/std/net/os/darwin.c3 @@ -1,7 +1,7 @@ module std::net::os; import libc; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): const AI_NUMERICSERV = 0x1000; const AI_ALL = 0x100; diff --git a/lib/std/net/os/linux.c3 b/lib/std/net/os/linux.c3 index a8d5a60cb..803370314 100644 --- a/lib/std/net/os/linux.c3 +++ b/lib/std/net/os/linux.c3 @@ -1,7 +1,7 @@ module std::net::os; import libc; -$if (env::OS_TYPE == LINUX) +$if env::OS_TYPE == LINUX: struct AddrInfo { diff --git a/lib/std/net/os/posix.c3 b/lib/std/net/os/posix.c3 index 9677e03f9..f9b52eaff 100644 --- a/lib/std/net/os/posix.c3 +++ b/lib/std/net/os/posix.c3 @@ -1,7 +1,7 @@ module std::net::os; import libc; -$if (env::os_is_win32() && $defined(AddrInfo)) +$if env::os_is_win32() && $defined(AddrInfo): const int F_GETFL = 3; const int F_SETFL = 4; diff --git a/lib/std/net/os/win32.c3 b/lib/std/net/os/win32.c3 index fa09acc38..53afc1de7 100644 --- a/lib/std/net/os/win32.c3 +++ b/lib/std/net/os/win32.c3 @@ -1,6 +1,6 @@ module std::net::os; -$if (env::os_is_win32()) +$if env::os_is_win32(): const int PLATFORM_AF_INET = 1; const int PLATFORM_AF_IPX = 6; diff --git a/lib/std/os/macos/cf_allocator.c3 b/lib/std/os/macos/cf_allocator.c3 index ac61a201e..ab8a0b9a2 100644 --- a/lib/std/os/macos/cf_allocator.c3 +++ b/lib/std/os/macos/cf_allocator.c3 @@ -1,6 +1,6 @@ module std::os::macos::cf; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): typedef CFAllocatorRef = distinct void*; typedef CFAllocatorContextRef = distinct void*; diff --git a/lib/std/os/macos/cf_array.c3 b/lib/std/os/macos/cf_array.c3 index 18ea90883..1a777572c 100644 --- a/lib/std/os/macos/cf_array.c3 +++ b/lib/std/os/macos/cf_array.c3 @@ -1,6 +1,6 @@ module std::os::macos::cf; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): typedef CFArrayRef = distinct void*; typedef CFArrayCallBacksRef = distinct void*; diff --git a/lib/std/os/macos/core_foundation.c3 b/lib/std/os/macos/core_foundation.c3 index 86a806c59..35b38e0ef 100644 --- a/lib/std/os/macos/core_foundation.c3 +++ b/lib/std/os/macos/core_foundation.c3 @@ -1,6 +1,6 @@ module std::os::macos::cf; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): typedef CFTypeRef = distinct void*; typedef CFIndex = isz; diff --git a/lib/std/os/macos/objc.c3 b/lib/std/os/macos/objc.c3 index c2d63a8dd..259470684 100644 --- a/lib/std/os/macos/objc.c3 +++ b/lib/std/os/macos/objc.c3 @@ -1,6 +1,6 @@ module std::os::macos::objc; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): typedef Class = distinct void*; typedef Method = distinct void*; diff --git a/lib/std/os/posix/files.c3 b/lib/std/os/posix/files.c3 index fb2e045fc..862b8d69f 100644 --- a/lib/std/os/posix/files.c3 +++ b/lib/std/os/posix/files.c3 @@ -1,6 +1,6 @@ module std::os::posix; -$if (env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE) +$if env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE: extern fn int rmdir(ZString); extern fn int mkdir(ZString, ushort mode_t); diff --git a/lib/std/os/win32/files.c3 b/lib/std/os/win32/files.c3 index cba7ecacb..aee32b974 100644 --- a/lib/std/os/win32/files.c3 +++ b/lib/std/os/win32/files.c3 @@ -1,6 +1,6 @@ module std::os::win32; -$if (env::os_is_win32()) +$if env::os_is_win32(): enum Win32_GET_FILEEX_INFO_LEVELS { diff --git a/lib/std/os/win32/general.c3 b/lib/std/os/win32/general.c3 index a2ad96ed1..59d80d91e 100644 --- a/lib/std/os/win32/general.c3 +++ b/lib/std/os/win32/general.c3 @@ -1,6 +1,6 @@ module std::os::win32; -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn Win32_DWORD win32_GetLastError() @extern("GetLastError"); diff --git a/lib/std/os/win32/process.c3 b/lib/std/os/win32/process.c3 index b6c10f70c..e4708f8a1 100644 --- a/lib/std/os/win32/process.c3 +++ b/lib/std/os/win32/process.c3 @@ -1,6 +1,6 @@ module std::os::win32; -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn bool win32_CreateProcessW( Win32_LPCWSTR lpApplicationName, diff --git a/lib/std/os/win32/wsa.c3 b/lib/std/os/win32/wsa.c3 index cade24ad7..96cd3330a 100644 --- a/lib/std/os/win32/wsa.c3 +++ b/lib/std/os/win32/wsa.c3 @@ -2,7 +2,7 @@ module std::os::win32; typedef WSAError = distinct int; -$if (env::os_is_win32()) +$if env::os_is_win32(): extern fn WSAError win32_WSAGetLastError() @extern("WSAGetLastError"); extern fn void win32_WSASetLastError(WSAError error) @extern("WSASetLastError"); @@ -10,7 +10,7 @@ $endif module std::os::win32::wsa; -$if (env::os_is_win32()) +$if env::os_is_win32(): const WSAError INVALID_HANDLE = 6; const WSAError NOT_ENOUGHT_MEMORY = 8; const WSAError INVALID_PARAMETER = 87; diff --git a/lib/std/threads/os/thread_posix.c3 b/lib/std/threads/os/thread_posix.c3 index 394286499..77b2c84a5 100644 --- a/lib/std/threads/os/thread_posix.c3 +++ b/lib/std/threads/os/thread_posix.c3 @@ -1,7 +1,7 @@ module std::thread::os; import libc; -$if (thread::THREAD_MODEL == ThreadModel.POSIX) +$if thread::THREAD_MODEL == ThreadModel.POSIX: const PTHREAD_MUTEX_NORMAL = 0; const PTHREAD_MUTEX_ERRORCHECK = 1; @@ -14,7 +14,7 @@ typedef NativeOnceFlag = PthreadOnce; typedef Pthread = distinct void*; -$if (env::OS_TYPE == LINUX) +$if env::OS_TYPE == LINUX: typedef PthreadMutex = distinct ulong[5]; typedef PthreadAttribute = distinct ulong[7]; typedef PthreadMutexAttribute = distinct uint; diff --git a/lib/std/threads/os/thread_win32.c3 b/lib/std/threads/os/thread_win32.c3 index 1bd27c680..60e8f45c7 100644 --- a/lib/std/threads/os/thread_win32.c3 +++ b/lib/std/threads/os/thread_win32.c3 @@ -1,6 +1,6 @@ module std::thread::os; -$if (thread::THREAD_MODEL == ThreadModel.WIN32) +$if thread::THREAD_MODEL == ThreadModel.WIN32: typedef NativeThread = Win32_HANDLE; diff --git a/lib/std/time/clock.c3 b/lib/std/time/clock.c3 index 00901be8f..331d1e270 100644 --- a/lib/std/time/clock.c3 +++ b/lib/std/time/clock.c3 @@ -2,7 +2,7 @@ module std::time::clock; fn Clock now() { -$if ($defined(native_clock)) +$if $defined(native_clock): return os::native_clock(); $else return 0; diff --git a/lib/std/time/datetime.c3 b/lib/std/time/datetime.c3 index 0daa2f78b..318536b1a 100644 --- a/lib/std/time/datetime.c3 +++ b/lib/std/time/datetime.c3 @@ -36,10 +36,10 @@ fn TzDateTime DateTime.to_local(DateTime* this) dt.weekday = !tm.tm_wday ? Weekday.SUNDAY : (Weekday)tm.tm_wday + 1; dt.year_day = (ushort)tm.tm_yday; dt.time = this.time; -$if ($defined(tm.tm_gmtoff)) +$if $defined(tm.tm_gmtoff): dt.gmt_offset = (int)tm.tm_gmtoff; $else - $assert($defined(libc::_get_timezone)); + $assert $defined(libc::_get_timezone); CLong timezone; libc::_get_timezone(&timezone); dt.gmt_offset = (int)-timezone; diff --git a/lib/std/time/os/time_darwin.c3 b/lib/std/time/os/time_darwin.c3 index a9f5174d7..5ce08731a 100644 --- a/lib/std/time/os/time_darwin.c3 +++ b/lib/std/time/os/time_darwin.c3 @@ -1,6 +1,6 @@ module std::time::os; -$if (env::os_is_darwin()) +$if env::os_is_darwin(): struct Darwin_mach_timebase_info { diff --git a/lib/std/time/os/time_posix.c3 b/lib/std/time/os/time_posix.c3 index 407ec9c59..80192c8a6 100644 --- a/lib/std/time/os/time_posix.c3 +++ b/lib/std/time/os/time_posix.c3 @@ -1,7 +1,7 @@ module std::time::os; import libc; -$if (env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE) +$if env::os_is_posix() && env::COMPILER_LIBC_AVAILABLE: $switch (env::OS_TYPE) $case OPENBSD: @@ -76,7 +76,7 @@ fn Time native_timestamp() return (Time)(ts.s * 1_000_000i64 + ts.ns / 1_000i64); } -$if (!env::os_is_darwin()) +$if !env::os_is_darwin(): fn Clock native_clock() { TimeSpec ts; diff --git a/lib/std/time/os/time_win32.c3 b/lib/std/time/os/time_win32.c3 index 5cb1a4776..5505f9b60 100644 --- a/lib/std/time/os/time_win32.c3 +++ b/lib/std/time/os/time_win32.c3 @@ -1,7 +1,7 @@ module std::time::os; import std::os::win32; -$if (env::os_is_win32() && env::COMPILER_LIBC_AVAILABLE) +$if env::os_is_win32() && env::COMPILER_LIBC_AVAILABLE: extern fn void win32_GetSystemTimeAsFileTime(Win32_FILETIME* time) @extern("GetSystemTimeAsFileTime"); extern fn Win32_BOOL win32_QueryPerformanceFrequency(Win32_LARGE_INTEGER* lpFrequency) @extern("QueryPerformanceFrequency"); diff --git a/lib/std/time/time.c3 b/lib/std/time/time.c3 index 2f1144853..bb8683181 100644 --- a/lib/std/time/time.c3 +++ b/lib/std/time/time.c3 @@ -61,7 +61,7 @@ enum Month : char fn Time now() { -$if ($defined(native_timestamp)) +$if $defined(native_timestamp): return os::native_timestamp(); $else return 0; diff --git a/releasenotes.md b/releasenotes.md index d89b569ae..bc11311d2 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -3,6 +3,10 @@ ## 0.5.0 Change List ### Changes / improvements +- `$if` now uses `$if :` syntax. +- `$assert` now uses `$assert : ` +- `$error` is syntax sugar for `$assert false : "Some message"` +- `$include`, `$echo` no longer has mandatory `()` around the arguments. - Dropped support for LLVM 13-14. - Updated grammar and lexer definition. - Removal of `$elif`. diff --git a/resources/examples/factorial_macro.c3 b/resources/examples/factorial_macro.c3 index 2bed8cf11..e486c485f 100644 --- a/resources/examples/factorial_macro.c3 +++ b/resources/examples/factorial_macro.c3 @@ -1,6 +1,6 @@ macro int factorial($n) { - $if ($n == 0) + $if $n == 0: return 1; $else return $n * factorial($n - 1); diff --git a/resources/examples/notworking/toml_parser_c2.c3 b/resources/examples/notworking/toml_parser_c2.c3 index 70a25fa07..f3ef93216 100644 --- a/resources/examples/notworking/toml_parser_c2.c3 +++ b/resources/examples/notworking/toml_parser_c2.c3 @@ -16,7 +16,7 @@ const uint MaxDepth = 8; //#define DEBUG_NODES -$if (DEBUG_NODES) +$if DEBUG_NODES: fn void Blocks.dump(Blocks* b) { @@ -418,7 +418,7 @@ public fn void! TomlReader.parse(TomlReader* r, string filename) Parser parser; parser.parse(file.data(), r.message, r.blocks); -$if (DEBUG_NODES) +$if DEBUG_NODES: r.blocks.dump(); $endif return status; diff --git a/resources/grammar/c3.l b/resources/grammar/c3.l index 19157a4c9..bb7c0dddd 100644 --- a/resources/grammar/c3.l +++ b/resources/grammar/c3.l @@ -50,6 +50,7 @@ int comment_level = 0; "$endforeach" { count(); return(CT_ENDFOREACH); } "$endif" { count(); return(CT_ENDIF); } "$endswitch" { count(); return(CT_ENDSWITCH); } +"$error" { count(); return(CT_ERROR); } "$eval" { count(); return(CT_EVAL); } "$evaltype" { count(); return(CT_EVALTYPE); } "$extnameof" { count(); return(CT_EXTNAMEOF); } diff --git a/resources/grammar/grammar.y b/resources/grammar/grammar.y index 2704f733f..dd711d440 100644 --- a/resources/grammar/grammar.y +++ b/resources/grammar/grammar.y @@ -23,6 +23,7 @@ void yyerror(char *s); %token TYPEID BITSTRUCT STATIC BANGBANG AT_CONST_IDENT HASH_TYPE_IDENT %token STRUCT UNION ENUM ELLIPSIS DOTDOT BYTES +%token CT_ERROR %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR CONTINUE BREAK RETURN FOREACH_R FOREACH %token FN FAULT MACRO CT_IF CT_ENDIF CT_ELSE CT_SWITCH CT_CASE CT_DEFAULT CT_FOR CT_FOREACH CT_ENDFOREACH %token CT_ENDFOR CT_ENDSWITCH BUILTIN IMPLIES INITIALIZE FINALIZE CT_ECHO CT_ASSERT CT_EVALTYPE CT_VATYPE @@ -410,10 +411,6 @@ constant_expr : ternary_expr ; -const_paren_expr - : '(' constant_expr ')' - ; - param_path_element : '[' expr ']' | '[' expr DOTDOT expr ']' @@ -750,8 +747,8 @@ defer_stmt ; ct_if_stmt - : CT_IF const_paren_expr opt_stmt_list CT_ENDIF - | CT_IF const_paren_expr opt_stmt_list CT_ELSE opt_stmt_list CT_ENDIF + : CT_IF constant_expr ':' opt_stmt_list CT_ENDIF + | CT_IF constant_expr ':' opt_stmt_list CT_ELSE opt_stmt_list CT_ENDIF ; assert_expr @@ -873,16 +870,17 @@ optional_label ; ct_assert_stmt - : CT_ASSERT '(' constant_expr ',' constant_expr ')' ';' - | CT_ASSERT '(' constant_expr ')' ';' + : CT_ASSERT constant_expr ':' constant_expr ';' + | CT_ASSERT constant_expr ';' + | CT_ERROR constant_expr ';' ; ct_include_stmt - : CT_INCLUDE '(' string_expr ')' ';' + : CT_INCLUDE string_expr ';' ; ct_echo_stmt - : CT_ECHO '(' constant_expr ')' ';' + : CT_ECHO constant_expr ';' bitstruct_declaration : BITSTRUCT TYPE_IDENT ':' type opt_attributes bitstruct_body @@ -1173,8 +1171,8 @@ define_declaration ; tl_ct_if - : CT_IF const_paren_expr opt_tl_stmts CT_ENDIF - | CT_IF const_paren_expr opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF + : CT_IF constant_expr ':' opt_tl_stmts CT_ENDIF + | CT_IF constant_expr ':' opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF ; tl_ct_switch diff --git a/resources/testfragments/parsertest.c3 b/resources/testfragments/parsertest.c3 index eeeb0c585..09051872f 100644 --- a/resources/testfragments/parsertest.c3 +++ b/resources/testfragments/parsertest.c3 @@ -15,7 +15,7 @@ macro @goo(i, $e) struct Foo { - $if ($use_bar > 0) + $if $use_bar > 0: { int bar; } @@ -125,12 +125,12 @@ $default: } $endswitch -$if ($e > 0) +$if $e > 0: { fn void foo() {} } -$if ($b > 0) +$if $b > 0: { } $else diff --git a/resources/testproject/hello_world.c3 b/resources/testproject/hello_world.c3 index bf26977b0..bb698702f 100644 --- a/resources/testproject/hello_world.c3 +++ b/resources/testproject/hello_world.c3 @@ -1,7 +1,7 @@ module hello_world; import std; import bar; -$if (env::os_is_win32()) +$if env::os_is_win32(): fn int test_doubler(int x) { return x * x; diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 57218f24a..0b385247d 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -565,6 +565,7 @@ typedef enum TOKEN_CT_ENDSWITCH, // $endswitch TOKEN_CT_EVAL, // $eval TOKEN_CT_EVALTYPE, // $evaltype + TOKEN_CT_ERROR, // $error TOKEN_CT_EXTNAMEOF, // $extnameof TOKEN_CT_FOR, // $for TOKEN_CT_FOREACH, // $foreach diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 5ebb89efe..5fc576e0b 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -54,6 +54,7 @@ void recover_top_level(ParseContext *c) case TOKEN_CONST: case TOKEN_ASM: case TOKEN_CT_ASSERT: + case TOKEN_CT_ERROR: case TOKEN_DOCS_START: case TOKEN_CT_IDENT: case TOKEN_CT_IF: @@ -113,8 +114,8 @@ static inline Decl *parse_ct_if_top_level(ParseContext *c) { Decl *ct = decl_new_ct(DECL_CT_IF, c->span); advance_and_verify(c, TOKEN_CT_IF); - ASSIGN_EXPR_OR_RET(ct->ct_if_decl.expr, parse_const_paren_expr(c), poisoned_decl); - + ASSIGN_EXPR_OR_RET(ct->ct_if_decl.expr, parse_expr(c), poisoned_decl); + CONSUME_OR_RET(TOKEN_COLON, poisoned_decl); if (!parse_top_level_block(c, &ct->ct_if_decl.then, TOKEN_CT_ENDIF, TOKEN_CT_ENDIF, TOKEN_CT_ELSE)) return poisoned_decl; CtIfDecl *ct_if_decl = &ct->ct_if_decl; @@ -2815,6 +2816,14 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) decl->ct_assert_decl = ast; return decl; } + case TOKEN_CT_ERROR: + { + if (contracts) goto CONTRACT_NOT_ALLOWED; + ASSIGN_AST_OR_RET(Ast *ast, parse_ct_error_stmt(c), poisoned_decl); + decl = decl_new_ct(DECL_CT_ASSERT, ast->span); + decl->ct_assert_decl = ast; + return decl; + } case TOKEN_CT_ECHO: { if (contracts) goto CONTRACT_NOT_ALLOWED; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 8c25ebfc5..9958870f5 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -900,7 +900,7 @@ static inline bool parse_ct_compound_stmt(ParseContext *c, AstId *start) /** * ct_if_stmt - * : CT_IF '(' expression ')' ct_compound_stmt (ct_elif_stmt | ct_else_stmt) CT_ENDIF EOS + * : CT_IF expression ':' ct_compound_stmt (ct_elif_stmt | ct_else_stmt) CT_ENDIF EOS * ; */ static inline Ast *parse_ct_if_stmt(ParseContext *c) @@ -908,7 +908,8 @@ static inline Ast *parse_ct_if_stmt(ParseContext *c) Ast *ast = ast_new_curr(c, AST_CT_IF_STMT); advance_and_verify(c, TOKEN_CT_IF); - ASSIGN_EXPR_OR_RET(ast->ct_if_stmt.expr, parse_const_paren_expr(c), poisoned_ast); + ASSIGN_EXPR_OR_RET(ast->ct_if_stmt.expr, parse_expr(c), poisoned_ast); + CONSUME_OR_RET(TOKEN_COLON, poisoned_ast); if (!parse_ct_compound_stmt(c, &ast->ct_if_stmt.then)) return poisoned_ast; if (tok_is(c, TOKEN_CT_ELSE)) @@ -944,11 +945,6 @@ static inline Ast *parse_return_stmt(ParseContext *c) } - - - - - /** * ct_foreach_stmt ::= CT_FOREACH '(' CT_IDENT (',' CT_IDENT)? ':' expr ')' statement* CT_ENDFOREACH */ @@ -1062,6 +1058,16 @@ static inline Ast* parse_ct_switch_stmt(ParseContext *c) return ast; } +static inline Ast *consume_eos(ParseContext *c, Ast *ast) +{ + if (!try_consume(c, TOKEN_EOS)) + { + sema_error_at_after(c->prev_span, "Expected ';'"); + advance(c); + return poisoned_ast; + } + return ast; +} /** * assert_stmt ::= ASSERT '(' assert_expr (',' expr)? ')' ';' */ @@ -1077,23 +1083,13 @@ static inline Ast *parse_assert_stmt(ParseContext *c) ASSIGN_EXPRID_OR_RET(ast->assert_stmt.message, parse_expr(c), poisoned_ast); } TRY_CONSUME_OR_RET(TOKEN_RPAREN, "The ending ')' was expected here.", poisoned_ast); - do - { - if (!tok_is(c, TOKEN_EOS)) - { - sema_error_at_after(c->prev_span, "Expected ';'"); - return poisoned_ast; - } - advance(c); - } - while (0); - return ast; + return consume_eos(c, ast); } // --- External functions /** - * ct_assert_stmt ::= CT_ASSERT '(' constant_expression (',' constant_expression) ')' ';' + * ct_assert_stmt ::= CT_ASSERT constant_expression (':' constant_expression) ';' * @param c * @return */ @@ -1101,46 +1097,34 @@ Ast *parse_ct_assert_stmt(ParseContext *c) { Ast *ast = ast_new_curr(c, AST_CT_ASSERT); advance_and_verify(c, TOKEN_CT_ASSERT); - TRY_CONSUME_OR_RET(TOKEN_LPAREN, "'$assert' needs a '(' here, did you forget it?", poisoned_ast); ASSIGN_EXPRID_OR_RET(ast->assert_stmt.expr, parse_constant_expr(c), poisoned_ast); - - if (try_consume(c, TOKEN_COMMA)) + if (try_consume(c, TOKEN_COLON)) { ASSIGN_EXPRID_OR_RET(ast->assert_stmt.message, parse_constant_expr(c), poisoned_ast); } - TRY_CONSUME_OR_RET(TOKEN_RPAREN, "The ending ')' was expected here.", poisoned_ast); - do - { - if (!tok_is(c, TOKEN_EOS)) - { - sema_error_at_after(c->prev_span, "Expected ';'"); - return poisoned_ast; - } - advance(c); - } - while (0); - return ast; + return consume_eos(c, ast); +} + +/** + * ct_error_stmt ::= CT_ERROR constant_expression) ';' + * @param c + * @return + */ +Ast *parse_ct_error_stmt(ParseContext *c) +{ + Ast *ast = ast_new_curr(c, AST_CT_ASSERT); + advance_and_verify(c, TOKEN_CT_ERROR); + ast->assert_stmt.expr = 0; + ASSIGN_EXPRID_OR_RET(ast->assert_stmt.message, parse_constant_expr(c), poisoned_ast); + return consume_eos(c, ast); } Ast *parse_ct_echo_stmt(ParseContext *c) { Ast *ast = ast_new_curr(c, AST_CT_ECHO_STMT); advance_and_verify(c, TOKEN_CT_ECHO); - TRY_CONSUME_OR_RET(TOKEN_LPAREN, "'$echo' needs a '(' here, did you forget it?", poisoned_ast); ASSIGN_EXPR_OR_RET(ast->expr_stmt, parse_constant_expr(c), poisoned_ast); - - TRY_CONSUME_OR_RET(TOKEN_RPAREN, "The ending ')' was expected here.", poisoned_ast); - do - { - if (!tok_is(c, TOKEN_EOS)) - { - sema_error_at_after(c->prev_span, "Expected ';'"); - return poisoned_ast; - } - advance(c); - } - while (0); - return ast; + return consume_eos(c, ast); } Ast *parse_stmt(ParseContext *c) @@ -1199,6 +1183,8 @@ Ast *parse_stmt(ParseContext *c) return parse_ct_echo_stmt(c); case TOKEN_CT_ASSERT: return parse_ct_assert_stmt(c); + case TOKEN_CT_ERROR: + return parse_ct_error_stmt(c); case TOKEN_CT_IF: return parse_ct_if_stmt(c); case TOKEN_CT_SWITCH: diff --git a/src/compiler/parser_internal.h b/src/compiler/parser_internal.h index 6ee33d4ac..ac3a35561 100644 --- a/src/compiler/parser_internal.h +++ b/src/compiler/parser_internal.h @@ -27,6 +27,7 @@ typedef enum Decl *parse_top_level_statement(ParseContext *c, ParseContext **new_context); Ast *parse_ct_assert_stmt(ParseContext *c); +Ast *parse_ct_error_stmt(ParseContext *c); Ast *parse_ct_echo_stmt(ParseContext *c); Ast *parse_stmt(ParseContext *c); bool parse_path_prefix(ParseContext *c, Path** path_ref); diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index fbd93a864..69be74b38 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -2523,7 +2523,7 @@ static inline bool sema_analyse_switch_stmt(SemaContext *context, Ast *statement bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement) { - Expr *expr = exprptr(statement->assert_stmt.expr); + Expr *expr = exprptrzero(statement->assert_stmt.expr); ExprId message = statement->assert_stmt.message; const char *msg = NULL; Expr *message_expr = message ? exprptr(message) : NULL; @@ -2535,9 +2535,10 @@ bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement) SEMA_ERROR(message_expr, "Expected a string as the error message."); } } - int res = sema_check_comp_time_bool(context, expr); + int res = expr ? sema_check_comp_time_bool(context, expr) : 0; if (res == -1) return false; + SourceSpan span = expr ? expr->span : statement->span; if (!res) { if (context->current_macro) @@ -2550,16 +2551,16 @@ bool sema_analyse_ct_assert_stmt(SemaContext *context, Ast *statement) { sema_error_at(context->inlining_span, "Compile time assert", EXPAND_EXPR_STRING(message_expr)); } - sema_error_prev_at(expr->span, "$assert was defined here."); + sema_error_prev_at(span, expr ? "$error was defined here" : "$assert was defined here."); return false; } if (message_expr) { - SEMA_ERROR(expr, "%.*s", EXPAND_EXPR_STRING(message_expr)); + sema_error_at(span, "%.*s", EXPAND_EXPR_STRING(message_expr)); } else { - SEMA_ERROR(expr, "Compile time assert failed."); + sema_error_at(span, "Compile time assert failed."); } return false; } diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index f09d3417e..f3e7ca97c 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -338,6 +338,8 @@ const char *token_type_to_string(TokenType type) return "$eval"; case TOKEN_CT_EVALTYPE: return "$evaltype"; + case TOKEN_CT_ERROR: + return "$error"; case TOKEN_CT_FOR: return "$for"; case TOKEN_CT_FOREACH: diff --git a/src/version.h b/src/version.h index fd5133a13..94cbd866e 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.504" \ No newline at end of file +#define COMPILER_VERSION "0.4.505" \ No newline at end of file diff --git a/test/test_suite/assert/global_static_assert_not_constant.c3 b/test/test_suite/assert/global_static_assert_not_constant.c3 index 9d1c3496d..a26c52b89 100644 --- a/test/test_suite/assert/global_static_assert_not_constant.c3 +++ b/test/test_suite/assert/global_static_assert_not_constant.c3 @@ -1,3 +1,3 @@ int x = 3; -$assert(x == 3); // #error: Compile time evaluation requires a compile time constant value. \ No newline at end of file +$assert x == 3; // #error: Compile time evaluation requires a compile time constant value. \ No newline at end of file diff --git a/test/test_suite/assert/local_static_assert_not_constant.c3 b/test/test_suite/assert/local_static_assert_not_constant.c3 index c75ffc30a..c40f7826d 100644 --- a/test/test_suite/assert/local_static_assert_not_constant.c3 +++ b/test/test_suite/assert/local_static_assert_not_constant.c3 @@ -2,19 +2,19 @@ int x = 3; fn void test() { - $assert(x == 3); // #error: Compile time evaluation requires a compile time constant value. + $assert x == 3; // #error: Compile time evaluation requires a compile time constant value. } fn void test2() { int i = 0; - $assert(1); - $assert(i == 0); // #error: Compile time evaluation requires a compile time constant value. + $assert 1; + $assert i == 0; // #error: Compile time evaluation requires a compile time constant value. } extern fn int foo(); fn void test3() { int i = 0; - $assert(foo() == 0); // #error: Compile time evaluation requires a compile time constant value. + $assert foo() == 0; // #error: Compile time evaluation requires a compile time constant value. } diff --git a/test/test_suite/assert/static_assert.c3 b/test/test_suite/assert/static_assert.c3 index a60e79eaa..75a060f06 100644 --- a/test/test_suite/assert/static_assert.c3 +++ b/test/test_suite/assert/static_assert.c3 @@ -3,6 +3,6 @@ const int FOO = 2; fn void test() { - $assert(FOO == 2, "Bad"); - $assert(FOO == 0, "Good"); // #error: Good + $assert FOO == 2 : "Bad"; + $assert FOO == 0 : "Good"; // #error: Good } \ No newline at end of file diff --git a/test/test_suite/compile_time/compile_time_pointers.c3t b/test/test_suite/compile_time/compile_time_pointers.c3t index 5429eae28..59a9d5082 100644 --- a/test/test_suite/compile_time/compile_time_pointers.c3t +++ b/test/test_suite/compile_time/compile_time_pointers.c3t @@ -11,7 +11,7 @@ const int* BOB = (int*)16 - 1; const int* BAB = (int*)16 + 1; const isz AO = BAB - BOB; -$if (ZAB > 100) +$if ZAB > 100: int abc = 123; $endif diff --git a/test/test_suite/compile_time/ct_if.c3t b/test/test_suite/compile_time/ct_if.c3t index 38fd34b19..91af81769 100644 --- a/test/test_suite/compile_time/ct_if.c3t +++ b/test/test_suite/compile_time/ct_if.c3t @@ -1,4 +1,4 @@ -$if (0) +$if 0: $else $switch $case false: @@ -11,52 +11,52 @@ $endif $switch $case false: -$assert(false); +$assert false; $case false: -$assert(false); +$assert false; $default: -$assert(true); +$assert true; $endswitch -$if (1) -$assert(true); +$if 1: +$assert true; int d = 5; $else -$assert(false); +$assert false; $endif $switch $case false: -$assert(true); +$assert true; $case true: -$assert(true); +$assert true; int c = 5; $default: -$assert(false); +$assert false; $endswitch $switch $case false: -$assert(true); +$assert true; $case true: -$assert(true); +$assert true; int b = 4; $case false: -$assert(false); +$assert false; $default: -$assert(false); +$assert false; $endswitch $switch $case false: -$assert(true); +$assert true; $case false: -$assert(false); +$assert false; $case true: -$assert(true); +$assert true; int a = 3; $default: -$assert(false); +$assert false; $endswitch /* #expect: ct_if.ll diff --git a/test/test_suite/compile_time/ct_if_fails.c3 b/test/test_suite/compile_time/ct_if_fails.c3 index 660df3b05..c9a640429 100644 --- a/test/test_suite/compile_time/ct_if_fails.c3 +++ b/test/test_suite/compile_time/ct_if_fails.c3 @@ -1,16 +1,16 @@ int x; -$if (x > 0) +$if x > 0: $endif -$if (0) - $assert(false); +$if 0: + $assert false; $endif -$if (1) +$if 1: $else $endif -$if (1) +$if 1: $else $else // #error: Expected the start of a global declaration here $endif diff --git a/test/test_suite/compile_time/stringify.c3t b/test/test_suite/compile_time/stringify.c3t index 932d7e12f..546a5882b 100644 --- a/test/test_suite/compile_time/stringify.c3t +++ b/test/test_suite/compile_time/stringify.c3t @@ -8,14 +8,14 @@ macro @timeit(#call) long t = (long)libc::clock(); var $Type = $typeof(#call); var $is_void = $Type.typeid == void.typeid; -$if ($is_void) +$if $is_void: #call; $else $Type result = #call; $endif long diff = (long)libc::clock() - t; libc::printf("'%s' took %lld us\n", $stringify(#call), diff); -$if (!$is_void) +$if !$is_void: return result; $endif } diff --git a/test/test_suite/compile_time_introspection/defined.c3t b/test/test_suite/compile_time_introspection/defined.c3t index d84dfbe0d..79dbb0c6b 100644 --- a/test/test_suite/compile_time_introspection/defined.c3t +++ b/test/test_suite/compile_time_introspection/defined.c3t @@ -17,41 +17,41 @@ fn void main() { int x = 0; var $counter = 0; - $if ($defined(x)) + $if $defined(x): x++; $counter++; $endif - $if ($defined(Foo.ab)) + $if $defined(Foo.ab): int y = 10; $counter++; x++; $endif - $if ($defined(Foo.ab.x)) + $if $defined(Foo.ab.x): x = 0; $counter = 0; $endif - $if ($defined(Foo.bob)) + $if $defined(Foo.bob): x++; $counter++; $endif - $if ($defined($eval("x"))) + $if $defined($eval("x")): x++; $counter++; $endif - $if ($defined($evaltype("Foo").$eval("ab"))) + $if $defined($evaltype("Foo").$eval("ab")): x++; $counter++; $endif - $if ($defined($evaltype("mymodule::Foo").$eval("bob"))) + $if $defined($evaltype("mymodule::Foo").$eval("bob")): x++; $counter++; $endif - $if ($defined(y)) + $if $defined(y): x++; $counter++; y = 1; $endif - $if ($defined(z)) + $if $defined(z): $counter = 0; x = 0; $endif diff --git a/test/test_suite/compile_time_introspection/defined_err.c3 b/test/test_suite/compile_time_introspection/defined_err.c3 index ae06b4be9..d8d198ece 100644 --- a/test/test_suite/compile_time_introspection/defined_err.c3 +++ b/test/test_suite/compile_time_introspection/defined_err.c3 @@ -10,16 +10,16 @@ struct Foo fn void test2() { - $assert($defined(int[1])); + $assert $defined(int[1]); bool x = $defined(int[y]); // #error: 'y' could not be found, did you spell it right? } fn void test3() { - $assert($defined(Foo[1])); - $assert($defined(Foo*)); - $assert($defined(Foo[])); - $assert($defined(Foo[*])); + $assert $defined(Foo[1]); + $assert $defined(Foo*); + $assert $defined(Foo[]); + $assert $defined(Foo[*]); bool x = $defined(Foo[y]); // #error: 'y' could not be found, did you spell it right? } diff --git a/test/test_suite/constants/init_order.c3t b/test/test_suite/constants/init_order.c3t index e342474f2..96d1e0355 100644 --- a/test/test_suite/constants/init_order.c3t +++ b/test/test_suite/constants/init_order.c3t @@ -3,7 +3,7 @@ module test; macro foo() { - $if ($defined(A)) + $if $defined(A): return A + 1; $else return 1; @@ -12,7 +12,7 @@ macro foo() const Z = foo(); -$if (!$defined(A) && Z == 1) +$if !$defined(A) && Z == 1: const A = 222; $endif diff --git a/test/test_suite/enumerations/enum_add_sub.c3t b/test/test_suite/enumerations/enum_add_sub.c3t index dce01c5ce..9496709bc 100644 --- a/test/test_suite/enumerations/enum_add_sub.c3t +++ b/test/test_suite/enumerations/enum_add_sub.c3t @@ -14,17 +14,17 @@ fn int main() { Foo a; a += 1; - $assert($typeof(a++).typeid == Foo.typeid); - $assert($typeof(a += 1).typeid == Foo.typeid); + $assert $typeof(a++).typeid == Foo.typeid; + $assert $typeof(a += 1).typeid == Foo.typeid; Abc b; b += 1; - $assert($typeof(b++).typeid == Abc.typeid); - $assert($typeof(b += 1).typeid == Abc.typeid); - $assert(!$checks(a += Foo.ABC)); + $assert $typeof(b++).typeid == Abc.typeid; + $assert $typeof(b += 1).typeid == Abc.typeid; + $assert !$checks(a += Foo.ABC); Bar c; c += 1; - $assert($typeof(c++).typeid == Bar.typeid); - $assert($typeof(c += 1).typeid == Bar.typeid); + $assert $typeof(c++).typeid == Bar.typeid; + $assert $typeof(c += 1).typeid == Bar.typeid; return 0; } diff --git a/test/test_suite/expressions/enum_ct_sub.c3t b/test/test_suite/expressions/enum_ct_sub.c3t index 608c90b8a..5fb1993ce 100644 --- a/test/test_suite/expressions/enum_ct_sub.c3t +++ b/test/test_suite/expressions/enum_ct_sub.c3t @@ -6,18 +6,18 @@ enum Foo : char typedef Abc = distinct int; fn void main() { - $assert((Foo.ABC - Foo.BCD) == 255); - $assert((Foo.ABC + Foo.BCD) == 1); + $assert (Foo.ABC - Foo.BCD) == 255; + $assert (Foo.ABC + Foo.BCD) == 1; char c = Foo.ABC - Foo.BCD; char d = Foo.ABC + Foo.BCD; - $assert($typeof(Foo.ABC - Foo.BCD).typeid == char.typeid); - $assert($typeof(Foo.ABC + Foo.BCD).typeid == char.typeid); - $assert(Foo.BCD - 1 == Foo.ABC); - $assert(Foo.ABC + 1 == Foo.BCD); - $assert($typeof(Foo.BCD - 1).typeid == Foo.typeid); - $assert($typeof(Foo.ABC + 1).typeid == Foo.typeid); + $assert $typeof(Foo.ABC - Foo.BCD).typeid == char.typeid; + $assert $typeof(Foo.ABC + Foo.BCD).typeid == char.typeid; + $assert Foo.BCD - 1 == Foo.ABC; + $assert Foo.ABC + 1 == Foo.BCD; + $assert $typeof(Foo.BCD - 1).typeid == Foo.typeid; + $assert $typeof(Foo.ABC + 1).typeid == Foo.typeid; Foo x = Foo.BCD; - $assert($typeof(x - 1).typeid == Foo.typeid); + $assert $typeof(x - 1).typeid == Foo.typeid; x = x - 1; - $assert($typeof(x + 1).typeid == Foo.typeid); + $assert $typeof(x + 1).typeid == Foo.typeid; } diff --git a/test/test_suite/import/import_error_out_of_order.c3 b/test/test_suite/import/import_error_out_of_order.c3 index 9d38e67cb..8ce736166 100644 --- a/test/test_suite/import/import_error_out_of_order.c3 +++ b/test/test_suite/import/import_error_out_of_order.c3 @@ -2,7 +2,7 @@ module foo; fn void hello() {} -$if (true) +$if true: import bar; // #error: 'import' may not appear inside a compile diff --git a/test/test_suite/macros/hash_ident.c3 b/test/test_suite/macros/hash_ident.c3 index 1244c7918..c2d3e449f 100644 --- a/test/test_suite/macros/hash_ident.c3 +++ b/test/test_suite/macros/hash_ident.c3 @@ -19,7 +19,7 @@ fn void main() @cofefe(x += 1); @cofefe(xx()); @cofefe($x += 1); - $assert($x == 2); + $assert $x == 2; @cofefe(y += 1); // #error: 'y' could not be found } diff --git a/test/test_suite/macros/macro_nested_labels.c3t b/test/test_suite/macros/macro_nested_labels.c3t index cfa795043..0a1416bee 100644 --- a/test/test_suite/macros/macro_nested_labels.c3t +++ b/test/test_suite/macros/macro_nested_labels.c3t @@ -11,7 +11,7 @@ macro checker(int x, $i) { for (int i = 0; i < $indent; i++) printf(" "); printf("Helo %d\n", x); - $if ($i > 0) + $if $i > 0: checker(x, $i - 1); $endif if (x % 2 == 0) break FOO; diff --git a/test/test_suite/macros/userland_bitcast.c3t b/test/test_suite/macros/userland_bitcast.c3t index 2fb7f7e61..cbd4075c3 100644 --- a/test/test_suite/macros/userland_bitcast.c3t +++ b/test/test_suite/macros/userland_bitcast.c3t @@ -2,7 +2,7 @@ macro testbitcast(expr, $Type) { - $assert($sizeof(expr) == $Type.sizeof, "Cannot bitcast between types of different size."); + $assert $sizeof(expr) == $Type.sizeof : "Cannot bitcast between types of different size."; $Type x @noinit; var $size = (usz)($sizeof(expr)); diff --git a/test/test_suite/struct/struct_pack_and_align.c3t b/test/test_suite/struct/struct_pack_and_align.c3t index 469f4e618..c73fdd1e3 100644 --- a/test/test_suite/struct/struct_pack_and_align.c3t +++ b/test/test_suite/struct/struct_pack_and_align.c3t @@ -9,7 +9,7 @@ struct Foo1 @packed @align(4) char foo; } -$assert(Foo1.sizeof == 12); +$assert Foo1.sizeof == 12; Foo1 foo1 = { 1, 2 }; // <{ i8, i64, [3 x i8] }> @@ -19,7 +19,7 @@ struct Foo2 @packed @align(4) long bar; } -$assert(Foo2.sizeof == 12); +$assert Foo2.sizeof == 12; Foo2 foo2 = { 1, 2 }; // <{ i8, i64, [7 x i8] }> @@ -30,7 +30,7 @@ struct Foo3 @packed @align(8) } Foo3 foo3 = { 1, 2 }; -$assert(Foo3.sizeof == 16); +$assert Foo3.sizeof == 16; // <{ i8, i64 }> struct Foo4 @packed @@ -39,7 +39,7 @@ struct Foo4 @packed long bar; } -$assert(Foo4.sizeof == 9); +$assert Foo4.sizeof == 9; Foo4 foo4 = { 1, 2 }; // { i32, [12 x i8], i8, [15 x i8] } @@ -49,7 +49,7 @@ struct Foo5 ichar foo @align(16); } -$assert(Foo5.sizeof == 32); +$assert Foo5.sizeof == 32; Foo5 foo5 = { 1, 2 }; fn int test5(ichar x) @@ -66,7 +66,7 @@ struct Foo6 @packed short c; } -$assert(Foo6.sizeof == 8); +$assert Foo6.sizeof == 8; Foo6 foo6 = { 1, 2, 3 }; /* #expect: struct2.ll diff --git a/test/unit/regression/faults.c3 b/test/unit/regression/faults.c3 index 29f93e780..58bf33f3a 100644 --- a/test/unit/regression/faults.c3 +++ b/test/unit/regression/faults.c3 @@ -10,9 +10,9 @@ fn void ordinals() { Foo z = {}; assert(z.ordinal == 0); - $assert(Foo.ABC.ordinal == 1); - $assert(Foo.CDE.ordinal == 2); - $assert((Foo{}).ordinal == 0); + $assert Foo.ABC.ordinal == 1; + $assert Foo.CDE.ordinal == 2; + $assert (Foo{}).ordinal == 0; Foo x = Foo.CDE; assert(x.ordinal == 2); x = Foo.ABC; diff --git a/test/unit/regression/vector_ops.c3 b/test/unit/regression/vector_ops.c3 index 299dc0b40..38c1cd567 100644 --- a/test/unit/regression/vector_ops.c3 +++ b/test/unit/regression/vector_ops.c3 @@ -18,9 +18,9 @@ fn void! test_conv() @test assert(gh == { -1, 0 }); var $k = bool[<2>] { true, false }; var $gh = (int[<2>])$k; - $assert($gh[0] == -1); + $assert $gh[0] == -1; var $gh2 = (char[<2>])$gh; - $assert($gh2[0] == 255); + $assert $gh2[0] == 255; b = (bool[<2>])gh; assert(b == { true, false }); } diff --git a/test/unit/stdlib/math/math.c3 b/test/unit/stdlib/math/math.c3 index 720a68dec..2bcdc1d8c 100644 --- a/test/unit/stdlib/math/math.c3 +++ b/test/unit/stdlib/math/math.c3 @@ -9,7 +9,7 @@ fn void! test_abs() @test assert(math::abs(y) == 123.0); float z = -21.0f; assert(math::abs(z) == 21.0f); - $assert(@typeis(math::abs(z), float)); + $assert @typeis(math::abs(z), float); int[<3>] xx = { -1, -1000, 1000 }; assert(math::abs(xx) == int[<3>] { 1, 1000, 1000 }); double[<3>] yy = { -1, -0.5, 1000 }; @@ -71,7 +71,7 @@ fn void! test_ceil() @test assert(math::ceil(d) == 1); d = -0.9; assert(math::ceil(d) == 0); - $assert(@typeis(math::ceil(d), double)); + $assert @typeis(math::ceil(d), double); float f = -123.1f; assert(math::ceil(f) == -123.0f); f = 123.1f; @@ -80,7 +80,7 @@ fn void! test_ceil() @test assert(math::ceil(f) == 1.0f); f = -0.9f; assert(math::ceil(f) == 0.0f); - $assert(@typeis(math::ceil(f), float)); + $assert @typeis(math::ceil(f), float); double[<5>] vec = { -123.1, 123.1, 0.1, -0.9, 0 }; assert(math::ceil(vec) == double[<5>] { -123, 124, 1, 0, 0 }); } @@ -95,7 +95,7 @@ fn void! test_floor() @test assert(math::floor(d) == 0); d = -0.1; assert(math::floor(d) == -1); - $assert(@typeis(math::floor(d), double)); + $assert @typeis(math::floor(d), double); float f = -123.1f; assert(math::floor(f) == -124.0f); f = 123.1f; @@ -104,7 +104,7 @@ fn void! test_floor() @test assert(math::floor(f) == 0.0f); f = -0.1f; assert(math::floor(f) == -1.0f); - $assert(@typeis(math::floor(f), float)); + $assert @typeis(math::floor(f), float); double[<5>] vec = { -123.1, 123.1, 0.9, -0.1, 0 }; assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 }); } @@ -119,7 +119,7 @@ fn void! test_trunc() @test assert(math::trunc(d) == 0); d = -0.9; assert(math::trunc(d) == 0); - $assert(@typeis(math::trunc(d), double)); + $assert @typeis(math::trunc(d), double); float f = -123.9f; assert(math::trunc(f) == -123.0f); f = 123.9f; @@ -128,7 +128,7 @@ fn void! test_trunc() @test assert(math::trunc(f) == 0.0f); f = -0.9f; assert(math::trunc(f) == -0.0f); - $assert(@typeis(math::trunc(f), float)); + $assert @typeis(math::trunc(f), float); double[<5>] vec = { -123.9, 123.9, 0.9, -0.9, 0 }; assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 }); } \ No newline at end of file