mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Introduce $vaarg[...] syntax and deprecate the old $vaarg(...).
- Similar change to `$vasplat`: `$vasplat` and `$vasplat[1..]`.
This commit is contained in:
@@ -135,7 +135,7 @@ fn void panicf(String fmt, String file, String function, uint line, args...)
|
||||
macro void unreachable(String string = "Unreachable statement reached.", ...) @builtin @noreturn
|
||||
{
|
||||
$if env::COMPILER_SAFE_MODE:
|
||||
panicf(string, $$FILE, $$FUNC, $$LINE, $vasplat());
|
||||
panicf(string, $$FILE, $$FUNC, $$LINE, $vasplat);
|
||||
$endif;
|
||||
$$unreachable();
|
||||
}
|
||||
@@ -146,7 +146,7 @@ macro void unreachable(String string = "Unreachable statement reached.", ...) @b
|
||||
**/
|
||||
macro void unsupported(String string = "Unsupported function invoked") @builtin @noreturn
|
||||
{
|
||||
panicf(string, $$FILE, $$FUNC, $$LINE, $vasplat());
|
||||
panicf(string, $$FILE, $$FUNC, $$LINE, $vasplat);
|
||||
$$unreachable();
|
||||
}
|
||||
|
||||
@@ -291,12 +291,12 @@ macro @prefetch(void* ptr, PrefetchLocality $locality = VERY_NEAR, bool $write =
|
||||
|
||||
macro swizzle(v, ...) @builtin
|
||||
{
|
||||
return $$swizzle(v, $vasplat());
|
||||
return $$swizzle(v, $vasplat);
|
||||
}
|
||||
|
||||
macro swizzle2(v, v2, ...) @builtin
|
||||
{
|
||||
return $$swizzle2(v, v2, $vasplat());
|
||||
return $$swizzle2(v, v2, $vasplat);
|
||||
}
|
||||
|
||||
macro anyfault @catch(#expr) @builtin
|
||||
|
||||
@@ -97,13 +97,13 @@ macro bool equals(a, b) @builtin
|
||||
macro min(x, ...) @builtin
|
||||
{
|
||||
$if $vacount == 1:
|
||||
return less(x, $vaarg(0)) ? x : $vaarg(0);
|
||||
return less(x, $vaarg[0]) ? x : $vaarg[0];
|
||||
$else
|
||||
var result = x;
|
||||
$for (var $i = 0; $i < $vacount; $i++)
|
||||
if (less($vaarg($i), result))
|
||||
if (less($vaarg[$i], result))
|
||||
{
|
||||
result = $vaarg($i);
|
||||
result = $vaarg[$i];
|
||||
}
|
||||
$endfor
|
||||
return result;
|
||||
@@ -113,13 +113,13 @@ macro min(x, ...) @builtin
|
||||
macro max(x, ...) @builtin
|
||||
{
|
||||
$if $vacount == 1:
|
||||
return greater(x, $vaarg(0)) ? x : $vaarg(0);
|
||||
return greater(x, $vaarg[0]) ? x : $vaarg[0];
|
||||
$else
|
||||
var result = x;
|
||||
$for (var $i = 0; $i < $vacount; $i++)
|
||||
if (greater($vaarg($i), result))
|
||||
if (greater($vaarg[$i], result))
|
||||
{
|
||||
result = $vaarg($i);
|
||||
result = $vaarg[$i];
|
||||
}
|
||||
$endfor
|
||||
return result;
|
||||
|
||||
@@ -591,7 +591,7 @@ fn void* tmalloc(usz size, usz alignment = 0) @builtin @inline @nodiscard
|
||||
|
||||
/**
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $Type.alignof <= DEFAULT_MEM_ALIGNMENT : "Types with alignment exceeding the default must use 'alloc_aligned' instead"
|
||||
**/
|
||||
macro new($Type, ...) @nodiscard
|
||||
@@ -600,7 +600,7 @@ macro new($Type, ...) @nodiscard
|
||||
return ($Type*)calloc($Type.sizeof);
|
||||
$else
|
||||
$Type* val = malloc($Type.sizeof);
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
@@ -609,7 +609,7 @@ macro new($Type, ...) @nodiscard
|
||||
* Allocate using an aligned allocation. This is necessary for types with a default memory alignment
|
||||
* exceeding DEFAULT_MEM_ALIGNMENT. IMPORTANT! It must be freed using free_aligned.
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
**/
|
||||
macro new_aligned($Type, ...) @nodiscard
|
||||
{
|
||||
@@ -617,7 +617,7 @@ macro new_aligned($Type, ...) @nodiscard
|
||||
return ($Type*)calloc_aligned($Type.sizeof, $Type.alignof);
|
||||
$else
|
||||
$Type* val = malloc_aligned($Type.sizeof, $Type.alignof);
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
@@ -641,7 +641,7 @@ macro alloc_aligned($Type) @nodiscard
|
||||
|
||||
/**
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
**/
|
||||
macro temp_new($Type, ...) @nodiscard
|
||||
{
|
||||
@@ -649,7 +649,7 @@ macro temp_new($Type, ...) @nodiscard
|
||||
return ($Type*)tcalloc($Type.sizeof) @inline;
|
||||
$else
|
||||
$Type* val = tmalloc($Type.sizeof) @inline;
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ macro void free_aligned(Allocator allocator, void* ptr)
|
||||
/**
|
||||
* @require $Type.alignof <= mem::DEFAULT_MEM_ALIGNMENT : "Types with alignment exceeding the default must use 'new_aligned' instead"
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
**/
|
||||
macro new(Allocator allocator, $Type, ...) @nodiscard
|
||||
{
|
||||
@@ -157,7 +157,7 @@ macro new(Allocator allocator, $Type, ...) @nodiscard
|
||||
return ($Type*)calloc(allocator, $Type.sizeof);
|
||||
$else
|
||||
$Type* val = malloc(allocator, $Type.sizeof);
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
@@ -165,7 +165,7 @@ macro new(Allocator allocator, $Type, ...) @nodiscard
|
||||
/**
|
||||
* @require $Type.alignof <= mem::DEFAULT_MEM_ALIGNMENT : "Types with alignment exceeding the default must use 'new_aligned' instead"
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
**/
|
||||
macro new_try(Allocator allocator, $Type, ...) @nodiscard
|
||||
{
|
||||
@@ -173,7 +173,7 @@ macro new_try(Allocator allocator, $Type, ...) @nodiscard
|
||||
return ($Type*)calloc_try(allocator, $Type.sizeof);
|
||||
$else
|
||||
$Type* val = malloc_try(allocator, $Type.sizeof)!;
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
@@ -182,7 +182,7 @@ macro new_try(Allocator allocator, $Type, ...) @nodiscard
|
||||
* Allocate using an aligned allocation. This is necessary for types with a default memory alignment
|
||||
* exceeding DEFAULT_MEM_ALIGNMENT. IMPORTANT! It must be freed using free_aligned.
|
||||
* @require $vacount < 2 : "Too many arguments."
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr(0), $Type) : "The second argument must be an initializer for the type"
|
||||
* @require $vacount == 0 ||| $assignable($vaexpr[0], $Type) : "The second argument must be an initializer for the type"
|
||||
**/
|
||||
macro new_aligned($Type, ...) @nodiscard
|
||||
{
|
||||
@@ -190,7 +190,7 @@ macro new_aligned($Type, ...) @nodiscard
|
||||
return ($Type*)calloc_aligned(allocator, $Type.sizeof, $Type.alignof);
|
||||
$else
|
||||
$Type* val = malloc_aligned(allocator, $Type.sizeof, $Type.alignof);
|
||||
*val = $vaexpr(0);
|
||||
*val = $vaexpr[0];
|
||||
return val;
|
||||
$endif
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fault NumberConversion
|
||||
macro String tformat(String fmt, ...)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + $vacount * 8);
|
||||
str.appendf(fmt, $vasplat());
|
||||
str.appendf(fmt, $vasplat);
|
||||
return str.str_view();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ macro String tformat(String fmt, ...)
|
||||
macro ZString tformat_zstr(String fmt, ...)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + $vacount * 8);
|
||||
str.appendf(fmt, $vasplat());
|
||||
str.appendf(fmt, $vasplat);
|
||||
return str.zstr_view();
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ macro String new_format(String fmt, ..., Allocator allocator = allocator::heap()
|
||||
@pool(allocator)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + $vacount * 8);
|
||||
str.appendf(fmt, $vasplat());
|
||||
str.appendf(fmt, $vasplat);
|
||||
return str.copy_str(allocator);
|
||||
};
|
||||
}
|
||||
@@ -83,7 +83,7 @@ macro ZString new_format_zstr(String fmt, ..., Allocator allocator = allocator::
|
||||
@pool(allocator)
|
||||
{
|
||||
DString str = dstring::temp_with_capacity(fmt.len + $vacount * 8);
|
||||
str.appendf(fmt, $vasplat());
|
||||
str.appendf(fmt, $vasplat);
|
||||
return str.copy_zstr(allocator);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ macro bool @has_same(#a, #b, ...) @const
|
||||
return false;
|
||||
$endif
|
||||
$for (var $i = 0; $i < $vacount; $i++)
|
||||
$if @typeid($vaexpr($i)) != $type_a:
|
||||
$if @typeid($vaexpr[$i]) != $type_a:
|
||||
return false;
|
||||
$endif
|
||||
$endfor
|
||||
|
||||
@@ -365,7 +365,7 @@ macro max(x, y, ...)
|
||||
$else
|
||||
var m = $$max(x, y);
|
||||
$for (var $i = 0; $i < $vacount; $i++)
|
||||
m = $$max(m, $vaarg($i));
|
||||
m = $$max(m, $vaarg[$i]);
|
||||
$endfor
|
||||
return m;
|
||||
$endif
|
||||
@@ -382,7 +382,7 @@ macro min(x, y, ...)
|
||||
$else
|
||||
var m = $$min(x, y);
|
||||
$for (var $i = 0; $i < $vacount; $i++)
|
||||
m = $$min(m, $vaarg($i));
|
||||
m = $$min(m, $vaarg[$i]);
|
||||
$endfor
|
||||
return m;
|
||||
$endif
|
||||
|
||||
Reference in New Issue
Block a user