mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Add bitsizeof to Builtins (#2376)
* Add `bitsizeof` to Builtins --------- Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
@@ -89,6 +89,10 @@ macro void @swap(#a, #b) @builtin
|
||||
#b = temp;
|
||||
}
|
||||
|
||||
macro usz bitsizeof($Type) @builtin @const => $Type.sizeof * 8u;
|
||||
|
||||
macro usz @bitsizeof(#expr) @builtin @const => $sizeof(#expr) * 8u;
|
||||
|
||||
<*
|
||||
Convert an `any` type to a type, returning an failure if there is a type mismatch.
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
- Support `alias foo = module std::io` module aliasing.
|
||||
- Add compile-time `@intlog2` macro to math.
|
||||
- Add compile-time `@clz` builtin. #2367
|
||||
- Add `bitsizeof` macro builtins. #2376
|
||||
|
||||
### Fixes
|
||||
- List.remove_at would incorrectly trigger ASAN.
|
||||
|
||||
@@ -184,3 +184,22 @@ fn void test_ct_clz()
|
||||
assert(@clz((uint128)0x87) == 120);
|
||||
assert(@clz((char)(0x44 - 0x40)) == 5);
|
||||
}
|
||||
|
||||
fn void test_bitsizeof()
|
||||
{
|
||||
assert(bitsizeof(uint128) == 128);
|
||||
assert(bitsizeof(ulong) == 64);
|
||||
assert(bitsizeof(int) == 32);
|
||||
assert(bitsizeof(short) == 16);
|
||||
assert(bitsizeof(char) == 8);
|
||||
assert(bitsizeof(char[200]) == 1600);
|
||||
|
||||
// Checks that they may be converted
|
||||
int x = bitsizeof(char);
|
||||
int y = @bitsizeof(1);
|
||||
|
||||
assert(@bitsizeof((char)0x07) == 8);
|
||||
assert(@bitsizeof(0x1000ul) == 64);
|
||||
assert(@bitsizeof(0) == 32);
|
||||
assert(@bitsizeof((char[*])"abcdefghi") == 72);
|
||||
}
|
||||
Reference in New Issue
Block a user