Moved bitcast to builtin module.

This commit is contained in:
Christoffer Lerno
2022-07-26 23:42:03 +02:00
parent c02ce5ce2a
commit 1adc8b8264
2 changed files with 8 additions and 108 deletions

View File

@@ -47,8 +47,6 @@ macro varcast(variant v, $Type) @builtin
return ($Type*)v.ptr;
}
extern fn void printf(char*, ...);
struct CallstackElement
{
CallstackElement* prev;
@@ -56,6 +54,7 @@ struct CallstackElement
char* file;
uint line;
}
fn void panic(char* message, char *file, char *function, uint line) @builtin
{
CallstackElement* stack = $$stacktrace();
@@ -88,104 +87,12 @@ macro unreachable($string = "Unreachable statement reached.") @builtin @noreturn
$$unreachable();
}
/*
enum TypeKind
macro bitcast(expr, $Type) @builtin
{
VOID,
BOOL,
FLOAT,
INTEGER,
STRUCT,
UNION,
ERROR,
ENUM,
ARRAY,
POINTER,
VAR_ARRAY,
SUBARRAY,
OPAQUE
// ALIAS,
var $size = (usize)($sizeof(expr));
$assert($size == $Type.sizeof, "Cannot bitcast between types of different size.");
$Type x = void;
memcpy(&x, &expr, $size, false, $alignof($Type), $alignof(expr));
return x;
}
struct TypeData
{
typeid typeId;
TypeKind kind;
int size;
int alignment;
char* name;
char* fullName;
}
struct TypeAlias
{
TypeData data;
typeid aliasType;
}
struct TypeError
{
TypeData data;
TypeErrorValue[] errors;
}
struct TypeArray
{
TypeData data;
typeid elementType;
ulong elements;
}
struct TypeVarArray
{
TypeData data;
typeid elementType;
}
struct TypeSubarray
{
TypeData data;
typeid elementType;
}
struct TypePointer
{
TypeData data;
typeid baseType;
}
struct TypeStruct
{
TypeData data;
TypeData*[] fields;
}
struct TypeUnion
{
TypeData data;
TypeData*[] variants;
}
struct TypeEnum
{
TypeData data;
typeid valueType;
TypeData*[] associated_value_types;
}
struct TypeEnumValue
{
char* name;
ulong value;
void*[] associated_values;
}
struct TypeErrorValue
{
char* name;
ulong value;
}
*/

View File

@@ -50,14 +50,7 @@ macro void memset(void* dst, char val, usize bytes, bool $is_volatile = false, u
$$memset(dst, val, bytes, $is_volatile, $dst_align);
}
macro bitcast(expr, $Type)
{
var $size = (usize)($sizeof(expr));
$assert($size == $Type.sizeof, "Cannot bitcast between types of different size.");
$Type x = void;
@memcpy(&x, &expr, $size, false, $alignof($Type), $alignof(expr));
return x;
}
enum AllocationKind