mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add .hash to integer types. Fixup of make and tmake. Updated map.c3 to become a working example. Fix bug in subarray -> pointer conversion. Search extension methods in std::core. Fix slice <-> slice copy.
This commit is contained in:
committed by
Christoffer Lerno
parent
4d5821408d
commit
ad18d9ba48
@@ -147,3 +147,13 @@ macro bool @convertible(#expr, $To) @builtin
|
||||
{
|
||||
return $checks($To x = #expr);
|
||||
}
|
||||
|
||||
macro uint int.hash(int i) = i;
|
||||
macro uint uint.hash(uint i) = i;
|
||||
macro uint short.hash(short s) = s;
|
||||
macro uint ushort.hash(ushort s) = s;
|
||||
macro uint char.hash(char c) = c;
|
||||
macro uint ichar.hash(ichar c) = c;
|
||||
macro uint long.hash(long i) = (uint)((i >> 32) ^ i);
|
||||
macro uint ulong.hash(ulong i) = (uint)((i >> 32) ^ i);
|
||||
macro uint bool.hash(bool b) = (uint)b;
|
||||
|
||||
@@ -26,7 +26,7 @@ macro talloc($Type, usize elements)
|
||||
**/
|
||||
macro make($Type, usize elements)
|
||||
{
|
||||
$Type* ptr = calloc($sizeof($Type) * elements);
|
||||
$Type* ptr = calloc($Type.sizeof * elements);
|
||||
return ptr[:elements];
|
||||
}
|
||||
|
||||
@@ -35,6 +35,6 @@ macro make($Type, usize elements)
|
||||
**/
|
||||
macro tmake($Type, usize elements)
|
||||
{
|
||||
$Type* ptr = tcalloc($sizeof($Type) * elements, $alignof($Type[1]));
|
||||
$Type* ptr = tcalloc($Type.sizeof * elements, $alignof($Type[1]));
|
||||
return ptr[:elements];
|
||||
}
|
||||
|
||||
@@ -138,5 +138,11 @@ macro bool is_power_of_2(x)
|
||||
return x != 0 && (x & (x - 1)) == 0;
|
||||
}
|
||||
|
||||
macro next_power_of_2(x)
|
||||
{
|
||||
$typeof(x) y = 1;
|
||||
while (y < x) y += y;
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user