mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Extend "var" to allow type inference on variables.
This commit is contained in:
committed by
Christoffer Lerno
parent
5e184f04e7
commit
5d9a7ab0a6
@@ -28,16 +28,16 @@ fault VarCastResult
|
||||
**/
|
||||
macro void @scope(&variable; @body) @builtin
|
||||
{
|
||||
$typeof(variable) temp = variable;
|
||||
var temp = variable;
|
||||
defer variable = temp;
|
||||
@body();
|
||||
}
|
||||
|
||||
macro void @swap(&a, &b) @builtin
|
||||
{
|
||||
$typeof(a) temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
var temp = a;
|
||||
a = b;
|
||||
b = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,11 +95,11 @@ macro void unreachable($string = "Unreachable statement reached.") @builtin @nor
|
||||
|
||||
macro bitcast(expr, $Type) @builtin
|
||||
{
|
||||
var $size = (usz)($sizeof(expr));
|
||||
$assert($size == $Type.sizeof, "Cannot bitcast between types of different size.");
|
||||
$Type x = void;
|
||||
mem::copy(&x, &expr, $size, $Type.alignof, $alignof(expr));
|
||||
return x;
|
||||
var $size = (usz)($sizeof(expr));
|
||||
$assert($size == $Type.sizeof, "Cannot bitcast between types of different size.");
|
||||
$Type x = void;
|
||||
mem::copy(&x, &expr, $size, $Type.alignof, $alignof(expr));
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,7 +80,7 @@ macro min(x, ...) @builtin
|
||||
$if ($vacount == 1):
|
||||
return less(x, $vaarg(0)) ? x : $vaarg(0);
|
||||
$else:
|
||||
$typeof(x) result = x;
|
||||
var result = x;
|
||||
$for (var $i = 0; $i < $vacount; $i++):
|
||||
if (less($vaarg($i), result))
|
||||
{
|
||||
@@ -96,7 +96,7 @@ macro max(x, ...) @builtin
|
||||
$if ($vacount == 1):
|
||||
return greater(x, $vaarg(0)) ? x : $vaarg(0);
|
||||
$else:
|
||||
$typeof(x) result = x;
|
||||
var result = x;
|
||||
$for (var $i = 0; $i < $vacount; $i++):
|
||||
if (greater($vaarg($i), result))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user