Updated cast code.

This commit is contained in:
Christoffer Lerno
2023-09-10 23:12:35 +02:00
committed by Christoffer Lerno
parent ca1885fe09
commit 37bb16cca1
33 changed files with 1845 additions and 1852 deletions

View File

@@ -161,10 +161,13 @@ macro void unsupported(String string = "Unsupported function invoked") @builtin
**/
macro bitcast(expr, $Type) @builtin
{
usz $size = $sizeof(expr);
$Type x @noinit;
mem::copy(&x, &expr, $size, $Type.alignof, $alignof(expr));
return x;
$if $Type.alignof <= $alignof(expr):
return *($Type*)&expr;
$else
$Type x @noinit;
$$memcpy(&x, &expr, $sizeof(expr), false, $Type.alignof, $alignof(expr));
return x;
$endif
}
/**