mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- $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:`
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()))
|
||||
{
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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])):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 🌎");
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -9,7 +9,7 @@ enum Vehicles
|
||||
macro elements($Type)
|
||||
{
|
||||
int x;
|
||||
$foreach ($x : $Type.values)
|
||||
$foreach $x : $Type.values:
|
||||
x = $x.ordinal;
|
||||
$endforeach;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ module test;
|
||||
|
||||
macro getisprime($x)
|
||||
{
|
||||
$switch ($x)
|
||||
$switch $x:
|
||||
$case 1:
|
||||
$case 2:
|
||||
$case 3:
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,7 +4,7 @@ module test;
|
||||
|
||||
macro get_type($Type)
|
||||
{
|
||||
$switch ($Type.typeid)
|
||||
$switch $Type.typeid:
|
||||
$case int:
|
||||
return "int";
|
||||
$case double:
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -69,7 +69,7 @@ fn void switch_subtyping()
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
$switch (Bar.typeid)
|
||||
$switch Bar.typeid:
|
||||
$case Foo:
|
||||
assert(true);
|
||||
$case Bar:
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user